Sharing Album Release Info with Record Labels

[1]:
# Pre-requisite: Ensure that DataTrails Subject IDS have been exchanged with parties that one
# wants to share with BEFORE creating this Access Policy.
#
# How to exchange DataTrails Subject IDs:
# https://docs.datatrails.ai/docs/datatrails-basics/sharing-assets-with-obac/
#
# Creates an Access Policy that shares event-level "read-only" permission across DataTrails tenancies.
#
# 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_event_access(arch):
    """
    Pre-requisite: Ensure that DataTrails Subject IDS have been exchanged with parties that one
    wants to share with BEFORE creating this Access Policy.

    How to exchange DataTrails Subject IDs:
    https://docs.datatrails.ai/docs/datatrails-basics/sharing-assets-with-obac/

    Creates an Access Policy that shares Album Release data for Artists with other DataTrails tenancies
    """
    props = {
        "display_name": "Sharing Album Release Info with Record Labels",
        "description": "Sharing Album Release Info with Record Labels",
    }
    filters = [{"or": ["attributes.arc_display_type=Artists"]}]
    access_permissions = [
        {
            "asset_attributes_read": [
                "arc_display_name",
                "arc_display_type",
                "arc_description",
            ],
            "asset_attributes_write": [],
            "behaviours": ASSET_BEHAVIOURS,
            "event_arc_display_type_read": ["Album Release"],
            "event_arc_display_type_write": [],
            "include_attributes": [],
            "subjects": ["subjects/34b291c3-30f4-4d89-9ec7-85f57354f798"],
            "user_attributes": [],
        }
    ]

    return arch.access_policies.create(props, filters, access_permissions)
[7]:
# Creates an Access Policy and prints result
access_policy = create_event_access(arch)
print("ACCESS_POLICY", json_dumps(access_policy, indent=4))
Refresh token
ACCESS_POLICY {
    "identity": "access_policies/2f30120d-55ba-4aeb-80cf-059abe37f9d2",
    "display_name": "Sharing Album Release Info with Record Labels",
    "filters": [
        {
            "or": [
                "attributes.arc_display_type=Artists"
            ]
        }
    ],
    "access_permissions": [
        {
            "subjects": [
                "subjects/34b291c3-30f4-4d89-9ec7-85f57354f798"
            ],
            "behaviours": [
                "RecordEvidence"
            ],
            "include_attributes": [],
            "user_attributes": [],
            "asset_attributes_read": [
                "arc_display_name",
                "arc_display_type",
                "arc_description"
            ],
            "asset_attributes_write": [],
            "event_arc_display_type_read": [
                "Album Release"
            ],
            "event_arc_display_type_write": []
        }
    ],
    "tenant": "tenant/0a62f7c9-fd7b-4791-8041-01218d839ec1",
    "description": "Sharing Album Release Info with Record Labels"
}