Sharing Artist Asset with User
[1]:
# Creates an Access Policy that shares "read-only" permission with user (within a single tenancy).
#
# Main function, establishes a connection to DataTrails using an App Registration then uses that
# to create an Access Policy.
#
# Note: The purpose of DataTrails Jupyter Notebooks is to provide simplified examples that one can easily execute and digest.
# The DataTrails Python SDK is authored to work cleanly with more advanced coding techniques.
#
# DataTrails Python SDK: https://github.com/datatrails/datatrails-python
#
[2]:
from json import dumps as json_dumps
from os import getenv
from archivist.archivist import Archivist
from archivist.constants import ASSET_BEHAVIOURS
from archivist.logger import set_logger
[3]:
%reload_ext dotenv
%dotenv -o notebooks.env
[4]:
# DATATRAILS_URL, DATATRAILS_APPREG_CLIENT, DATATRAILS_APPREG_SECRET are environment variables that represent connection parameters.
#
# DATATRAILS_URL = represents the url to the DataTrails application
# DATATRAILS_APPREG_CLIENT = represents the client ID from an Application Registration
# DATATRAILS_APPREG_SECRET = represents the client secret from an Application Registration
DATATRAILS_URL = getenv("DATATRAILS_URL")
DATATRAILS_APPREG_CLIENT = getenv("DATATRAILS_APPREG_CLIENT")
DATATRAILS_APPREG_SECRET = getenv("DATATRAILS_APPREG_SECRET")
[5]:
"""
Main function of Access Policy creation.
* Connect to DataTrails with client ID and client secret
* Creates an Access Policy
* Prints response of Access Policy creation
"""
# Optional call to set the logger level. The argument can be either
# "INFO" or "DEBUG". For more sophisticated logging control see our
# documentation.
set_logger("INFO")
# Initialize connection to DATATRAILS
print("Connecting to DATATRAILS")
print("DATATRAILS_URL", DATATRAILS_URL)
arch = Archivist(
DATATRAILS_URL, (DATATRAILS_APPREG_CLIENT, DATATRAILS_APPREG_SECRET), max_time=300
)
Connecting to DATATRAILS
DATATRAILS_URL https://app.datatrails.ai
[6]:
def create_access(arch):
"""
Creates an Access Policy that shares read only data for Artists with another user within a single tenancy
"""
props = {
"display_name": "Sharing Artist Asset",
"description": "Sharing Artist Asset with User",
}
filters = [{"or": ["attributes.arc_display_type=Artists"]}]
access_permissions = [
{
"asset_attributes_read": ["*"],
"asset_attributes_write": [],
"behaviours": ASSET_BEHAVIOURS,
"event_arc_display_type_read": ["*"],
"event_arc_display_type_write": [],
"include_attributes": [],
"subjects": [],
"user_attributes": [{"or": ["email=datatrails.test@gmail.com"]}],
}
]
return arch.access_policies.create(props, filters, access_permissions)
[7]:
# Creates an Access Policy and prints result
access_policy = create_access(arch)
print("ACCESS_POLICY", json_dumps(access_policy, indent=4))
Refresh token
ACCESS_POLICY {
"identity": "access_policies/318599ad-272f-4c58-b0ac-5773f38c705a",
"display_name": "Sharing Artist Asset",
"filters": [
{
"or": [
"attributes.arc_display_type=Artists"
]
}
],
"access_permissions": [
{
"subjects": [],
"behaviours": [
"RecordEvidence"
],
"include_attributes": [],
"user_attributes": [
{
"or": [
"email=datatrails.test@gmail.com"
]
}
],
"asset_attributes_read": [
"*"
],
"asset_attributes_write": [],
"event_arc_display_type_read": [
"*"
],
"event_arc_display_type_write": []
}
],
"tenant": "tenant/0a62f7c9-fd7b-4791-8041-01218d839ec1",
"description": "Sharing Artist Asset with User"
}