Skip to content

Commit

Permalink
Merge pull request #964 from datatrails/dev/jag/10053-access-policy-e…
Browse files Browse the repository at this point in the history
…xamples

API example tidy-ups ahead of Event Centric move
  • Loading branch information
JAG-UK authored Jan 8, 2025
2 parents 2ce07e7 + d5e3336 commit 2341201
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 208 deletions.
81 changes: 2 additions & 79 deletions content/developers/api-reference/assets-api/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,81 +82,6 @@ The response:
}
```

#### Updating an Asset Attribute

To update an Asset attribute, record an Event and enter the new value. Here we will update the weight of the cat from the previous example.

See the [Events API reference](https://docs.datatrails.ai/developers/api-reference/events-api/) for more information about Events.

```json
{
"operation": "Record",
"behaviour": "RecordEvidence",
"event_attributes": {
"arc_display_type": "groom",
"additional_checks": "weigh the cat"
},
"asset_attributes": {
"weight": "3.5kg"
},
"public": false
}
```

POST the Event to update the Asset:

```bash
curl -X POST \
-H "@$HOME/.datatrails/bearer-token.txt" \
-H "Content-type: application/json" \
-d "@/path/to/jsonfile" \
https://app.datatrails.ai/archivist/v2/assets/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/events
```

The response is:

```json
{
"identity": "assets/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/events/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"asset_identity": "assets/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"event_attributes": {
"arc_display_type": "groom",
"additional_checks": "weigh the cat"
},
"asset_attributes": {
"weight": "3.5kg"
},
"operation": "Record",
"behaviour": "RecordEvidence",
"timestamp_declared": "2024-05-30T12:28:50Z",
"timestamp_accepted": "2024-05-30T12:28:50Z",
"timestamp_committed": "1970-01-01T00:00:00Z",
"principal_declared": {
"issuer": "https://app.datatrails.ai/appidpv1",
"subject": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"display_name": "Custom Integration",
"email": ""
},
"principal_accepted": {
"issuer": "https://app.datatrails.ai/appidpv1",
"subject": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"display_name": "Custom Integration",
"email": ""
},
"confirmation_status": "PENDING",
"transaction_id": "",
"block_number": 0,
"transaction_index": 0,
"from": "",
"tenant_identity": "",
"merklelog_entry": {
"commit": null,
"confirm": null,
"unequivocal": null
}
}
```

#### Creating a Public Asset

{{< warning >}}
Expand Down Expand Up @@ -198,7 +123,6 @@ Define the asset parameters and store in `/path/to/jsonfile`:
"document_status":"Published",
"some_custom_attribute":"anything you like"
},
"chain_id":"",
"behaviours": [
"Builtin",
"RecordEvidence"
Expand Down Expand Up @@ -240,11 +164,10 @@ The response is:
"arc_display_name": "Test Document Profile Asset",
"document_hash_alg": "sha256"
},
"confirmation_status": "PENDING",
"confirmation_status": "STORED",
"tracked": "TRACKED",
"owner": "",
"at_time": "2023-09-27T11:32:22Z",
"storage_integrity": "TENANT_STORAGE",
"chain_id": "8275868384",
"public": false,
"tenant_identity": ""
Expand Down Expand Up @@ -437,7 +360,7 @@ The response is:
"issuer": "job.idp.server/1234",
"subject": "bob@job"
},
"confirmation_status": "PENDING",
"confirmation_status": "STORED",
"transaction_id": "",
"block_number": 0,
"transaction_index": 0,
Expand Down
101 changes: 3 additions & 98 deletions content/developers/api-reference/events-api/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,81 +122,6 @@ ASSET_UUID=<ASSET_UUID>
- To query the events jump to [Fetch Specific Events by Identity](#fetch-events-for-a-specific-asset)
### Updating an Asset Attribute
To update an Asset attribute, record an Event and enter the new value. Here we will update the weight of the cat Asset created in the [Assets API reference](https://docs.datatrails.ai/developers/api-reference/assets-api/#asset-record-creation) example.
```json
cat > /tmp/event.json <<EOF
{
"operation": "Record",
"behaviour": "RecordEvidence",
"event_attributes": {
"arc_display_type": "groom",
"additional_checks": "weigh the cat"
},
"asset_attributes": {
"weight": "3.5kg"
},
"public": false
}
EOF
```
POST the Event to update the Asset:
```bash
curl -X POST \
-H "@$HOME/.datatrails/bearer-token.txt" \
-H "Content-type: application/json" \
-d "@/tmp/event.json" \
https://app.datatrails.ai/archivist/v2/assets/$ASSET_UUID/events
```
The response:
```json
{
"identity": "assets/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/events/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"asset_identity": "assets/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"event_attributes": {
"arc_display_type": "groom",
"additional_checks": "weigh the cat"
},
"asset_attributes": {
"weight": "3.5kg"
},
"operation": "Record",
"behaviour": "RecordEvidence",
"timestamp_declared": "2024-05-30T12:28:50Z",
"timestamp_accepted": "2024-05-30T12:28:50Z",
"timestamp_committed": "1970-01-01T00:00:00Z",
"principal_declared": {
"issuer": "https://app.datatrails.ai/appidpv1",
"subject": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"display_name": "Custom Integration",
"email": ""
},
"principal_accepted": {
"issuer": "https://app.datatrails.ai/appidpv1",
"subject": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"display_name": "Custom Integration",
"email": ""
},
"confirmation_status": "PENDING",
"transaction_id": "",
"block_number": 0,
"transaction_index": 0,
"from": "",
"tenant_identity": "",
"merklelog_entry": {
"commit": null,
"confirm": null,
"unequivocal": null
}
}
```
### Document Profile Event Creation
There are two [Document Profile Events](/developers/developer-patterns/document-profile/) that are available as part of the document lifecycle. These are to `publish` a new version and to `withdraw` the document from use.
Expand All @@ -220,7 +145,7 @@ cat > /tmp/event.json <<EOF
"arc_description":"Publish version 2 of Test Document",
"arc_display_type":"Publish",
"document_version_authors": [
{
{
"display_name": "George",
"email": "[email protected]"
},
Expand Down Expand Up @@ -385,9 +310,9 @@ blobs/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
Each attachment has an associated hash value and the name of the hash algorithm used that you can also get from the Blob API response.
Once you've uploaded your file, you can use the `"arc_attribute_type": "arc_attachment"` key-value pair within a dictionary of blob information to add the attachment to either your Asset or Event.
Once you've uploaded your file, you can use the `"arc_attribute_type": "arc_attachment"` key-value pair within a dictionary of blob information to add the attachment to your Event.
The following example shows you usage with both the `event_attributes` and the `asset_attributes`:
For example:
```json
cat > /tmp/event.json <<EOF
Expand Down Expand Up @@ -415,16 +340,6 @@ cat > /tmp/event.json <<EOF
"arc_display_name": "arc_primary_image",
},
},
"asset_attributes": {
"latest_conformance_report": {
"arc_attribute_type": "arc_attachment",
"arc_blob_hash_value": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"arc_blob_identity": "blobs/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"arc_blob_hash_alg": "SHA256",
"arc_file_name": "safety_conformance.pdf",
"arc_display_name": "Latest Conformance Report",
},
},
"timestamp_declared": "2019-11-27T14:44:19Z",
"principal_declared": {
"issuer": "idp.synsation.io/1234",
Expand Down Expand Up @@ -474,16 +389,6 @@ The response:
"arc_display_name": "Conformance Report",
},
},
"asset_attributes": {
"latest_conformance_report": {
"arc_attribute_type": "arc_attachment",
"arc_blob_hash_value": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"arc_blob_identity": "blobs/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"arc_blob_hash_alg": "SHA256",
"arc_file_name": "safety_conformance.pdf",
"arc_display_name": "Latest Conformance Report",
},
},
"timestamp_accepted": "2019-11-27T15:13:21Z",
"timestamp_declared": "2019-11-27T14:44:19Z",
"timestamp_committed": "2019-11-27T15:15:02Z",
Expand Down
12 changes: 4 additions & 8 deletions content/developers/api-reference/iam-policies-api/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,9 @@ Define the access_policies parameters and store in `/path/to/jsonfile`:

```json
{
"display_name": "Friendly name of the policy",
"description": "Description of the policy",
"display_name": "Printer management policy",
"description": "Restrict who can register ",
"filters": [
{ "or": [
"attributes.arc_home_location_identity=locations/5ea815f0-4de1-4a84-9377-701e880fe8ae",
"attributes.arc_home_location_identity=locations/27eed70b-9e2b-4db1-b8c4-e36505350dcc"
]},
{ "or": [
"attributes.arc_display_type=Valve",
"attributes.arc_display_type=Pump"
Expand All @@ -72,7 +68,7 @@ Define the access_policies parameters and store in `/path/to/jsonfile`:
"access_permissions": [
{
"asset_attributes_read": [ "toner_colour", "toner_type" ],
"asset_attributes_write":["toner_colour"],
"asset_attributes_write":[],
"behaviours": [ "RecordEvidence" ],
"event_arc_display_type_read": ["toner_type", "toner_colour"],
"event_arc_display_type_write": ["toner_replacement"],
Expand Down Expand Up @@ -122,7 +118,7 @@ The response is:
"access_permissions": [
{
"asset_attributes_read": [ "toner_colour", "toner_type" ],
"asset_attributes_write":["toner_colour"],
"asset_attributes_write":[],
"behaviours": [ "RecordEvidence" ],
"event_arc_display_type_read": ["toner_type", "toner_colour"],
"event_arc_display_type_write": ["toner_replacement"],
Expand Down
38 changes: 17 additions & 21 deletions content/platform/overview/advanced-concepts/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -185,21 +185,21 @@ A simple Access Policy may look like this:
"display_name": "Sample Policy",
"description": "An Access Policy created for DataTrails user docs"

// Filters define which Assets this Policy applies to
// Filters define which Assets (sets of Events) this Policy applies to
"filters": [
{
// Any Crate, Box, or Bag ...
// Any image, video, or whitepaper...
"or": [
"attributes.arc_display_type=Crate",
"attributes.arc_display_type=Box",
"attributes.arc_display_type=Bag"
"attributes.arc_display_type=Image",
"attributes.arc_display_type=Video",
"attributes.arc_display_type=Whitepaper"
]
},
{
// ... whose registered handler is either Fred or Margaret
// ... which is marked either CONFIDENTIAL or SECRET
"or": [
"attributes.handler=Fred",
"attributes.handler=Margaret"
"attributes.classification=CONFIDENTIAL",
"attributes.classification=SECRET"
]
}
],
Expand All @@ -218,31 +218,27 @@ A simple Access Policy may look like this:
{ "or": [ "[email protected]" ] }
],

// Limit the APIs they can call
"behaviours": [ "RecordEvidence" ],

// Select which Asset attributes these users can see
"asset_attributes_read": [
"Height",
"arc_display_name",
"arc_display_type"
],

// Select which Asset attributes these users can modify
"asset_attributes_write": [
"Height"
],
// Note modifying Asset attributes in this way is deprecated
// and not recommended
"asset_attributes_write": [],

// Select which Events from the Asset history these users can see
// Select which types of Events these users can see
"event_arc_display_type_read": [
"Measure",
"Open",
"Seal"
"Pre-release",
"Watermark",
"Approve"
],

// Select which Events these users can contribute to the history
// Select which types of Events these users can contribute to the Trail
"event_arc_display_type_write": [
"Measure"
"Approve"
],

// Note the include_attributes field is deprecated
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Asset Creation is the first Event. The more Events recorded against an Asset, th
Events track key moments of an Asset's lifecycle; details of Who Did What When to an Asset.

{{< note >}}
**Note:** Before creating an Event, follow [this guide](/platform/overview/creating-an-asset/) to create your first Asset. You will need to wait for the Asset to reach COMMITTED state before attempting to record an Event.
**Note:** Before creating an Event, follow [this guide](/platform/overview/creating-an-asset/) to create your first Asset.
{{< /note >}}

## Creating Events
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ When the document version is no longer to be used there is a Withdraw Event.
These Events track key moments of an Document's lifecycle; details of Who Did What When to each version of the document.

{{< note >}}
**Note:** Before registering an Event, follow [this guide](/platform/overview/registering-a-document-profile-asset/) to register your first Document Asset. You will need to wait for the Asset to reach COMMITTED state before attempting to record an Event.
**Note:** Before registering an Event, follow [this guide](/platform/overview/registering-a-document-profile-asset/) to register your first Document.
{{< /note >}}

## Registering Events
Expand Down

0 comments on commit 2341201

Please sign in to comment.