Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,247 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "ae305cf3-4dc9-4f3d-bc48-6467101cbc47",
"metadata": {},
"source": [
"## Sharing Album Release Info with Record Labels"
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "2a4a0d3f-d774-411a-969b-7e7aad31cb0d",
"metadata": {},
"outputs": [],
"source": [
"# Pre-requisite: Ensure that RKVST Subject IDS have been exchanged with parties that one\n",
"# wants to share with BEFORE creating this Access Policy.\n",
"#\n",
"# How to exchange RKVST Subject IDs:\n",
"# https://docs.rkvst.com/docs/rkvst-basics/sharing-assets-with-obac/\n",
"#\n",
"# Creates an Access Policy that shares event-level \"read-only\" permission across RKVST tenancies.\n",
"#\n",
"# Main function, establishes a connection to RKVST using an App Registration then uses that\n",
"# to create an Access Policy.\n",
"#\n",
"# Note: The purpose of RKVST Jupyter Notebooks is to provide simplified examples that one can easily execute and digest.\n",
"# The RKVST Python SDK is authored to work cleanly with more advanced coding techniques.\n",
"#\n",
"# RKVST Python SDK: https://github.com/rkvst/rkvst-python\n",
"#"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "e3dc6e9d-e910-44af-b61e-5016b92b5da0",
"metadata": {},
"outputs": [],
"source": [
"import random\n",
"import string\n",
"\n",
"from json import dumps as json_dumps\n",
"from os import getenv\n",
"from warnings import filterwarnings\n",
"\n",
"from dotenv import load_dotenv\n",
"\n",
"from archivist.archivist import Archivist\n",
"from archivist.proof_mechanism import ProofMechanism\n",
"from archivist.logger import set_logger\n",
"from archivist.constants import ASSET_BEHAVIOURS"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "819162de-c4b1-4c6a-a078-fc327db97e80",
"metadata": {},
"outputs": [],
"source": [
"%reload_ext dotenv\n",
"%dotenv -o notebooks.env"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "cb56cd35-41a0-40e4-948f-c327557feb09",
"metadata": {},
"outputs": [],
"source": [
"# RKVST_URL, RKVST_APPREG_CLIENT, RKVST_APPREG_SECRET are environment variables that represent connection parameters.\n",
"#\n",
"# RKVST_URL = represents the url to the RKVST application\n",
"# RKVST_APPREG_CLIENT = represents the client ID from an Application Registration\n",
"# RKVST_APPREG_SECRET = represents the client secret from an Application Registration\n",
"RKVST_URL = getenv(\"RKVST_URL\")\n",
"RKVST_APPREG_CLIENT = getenv(\"RKVST_APPREG_CLIENT\")\n",
"RKVST_APPREG_SECRET = getenv(\"RKVST_APPREG_SECRET\")"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "ffa23b6d-5dd5-494e-8707-6af11ea1dbe6",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Connecting to RKVST\n",
"RKVST_URL https://app.rkvst.io\n"
]
}
],
"source": [
"\"\"\"\n",
"Main function of Access Policy creation.\n",
"\n",
"* Connect to RKVST with client ID and client secret\n",
"* Creates an Access Policy\n",
"* Prints response of Access Policy creation\n",
"\"\"\"\n",
"\n",
"# Optional call to set the logger level. The argument can be either\n",
"# \"INFO\" or \"DEBUG\". For more sophisticated logging control see our\n",
"# documentation.\n",
"set_logger(\"INFO\")\n",
"\n",
"# Initialize connection to RKVST\n",
"print(\"Connecting to RKVST\")\n",
"print(\"RKVST_URL\", RKVST_URL)\n",
"arch = Archivist(RKVST_URL, (RKVST_APPREG_CLIENT, RKVST_APPREG_SECRET), max_time=300)"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "bae05b9c-cafa-4e81-bcb5-3cfcf3e70de7",
"metadata": {},
"outputs": [],
"source": [
"def create_event_access(arch):\n",
" \"\"\"\n",
" Pre-requisite: Ensure that RKVST Subject IDS have been exchanged with parties that one\n",
" wants to share with BEFORE creating this Access Policy.\n",
"\n",
" How to exchange RKVST Subject IDs:\n",
" https://docs.rkvst.com/docs/rkvst-basics/sharing-assets-with-obac/\n",
"\n",
" Creates an Access Policy that shares Album Release data for Artists with other RKVST tenancies\n",
" \"\"\"\n",
" props = {\n",
" \"display_name\": \"Sharing Album Release Info with Record Labels\",\n",
" \"description\": \"Sharing Album Release Info with Record Labels\",\n",
" }\n",
" filters = [{\"or\": [\"attributes.arc_display_type=Artists\"]}]\n",
" access_permissions = [\n",
" {\n",
" \"asset_attributes_read\": [\n",
" \"arc_display_name\",\n",
" \"arc_display_type\",\n",
" \"arc_description\",\n",
" ],\n",
" \"asset_attributes_write\": [],\n",
" \"behaviours\": ASSET_BEHAVIOURS,\n",
" \"event_arc_display_type_read\": [\"Album Release\"],\n",
" \"event_arc_display_type_write\": [],\n",
" \"include_attributes\": [],\n",
" \"subjects\": [\"subjects/34b291c3-30f4-4d89-9ec7-85f57354f798\"],\n",
" \"user_attributes\": [],\n",
" }\n",
" ]\n",
"\n",
" return arch.access_policies.create(props, filters, access_permissions)"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "678dd908-413e-4ac8-8d96-2948de403238",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"Refresh token\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"ACCESS_POLICY {\n",
" \"identity\": \"access_policies/2f30120d-55ba-4aeb-80cf-059abe37f9d2\",\n",
" \"display_name\": \"Sharing Album Release Info with Record Labels\",\n",
" \"filters\": [\n",
" {\n",
" \"or\": [\n",
" \"attributes.arc_display_type=Artists\"\n",
" ]\n",
" }\n",
" ],\n",
" \"access_permissions\": [\n",
" {\n",
" \"subjects\": [\n",
" \"subjects/34b291c3-30f4-4d89-9ec7-85f57354f798\"\n",
" ],\n",
" \"behaviours\": [\n",
" \"Attachments\",\n",
" \"RecordEvidence\"\n",
" ],\n",
" \"include_attributes\": [],\n",
" \"user_attributes\": [],\n",
" \"asset_attributes_read\": [\n",
" \"arc_display_name\",\n",
" \"arc_display_type\",\n",
" \"arc_description\"\n",
" ],\n",
" \"asset_attributes_write\": [],\n",
" \"event_arc_display_type_read\": [\n",
" \"Album Release\"\n",
" ],\n",
" \"event_arc_display_type_write\": []\n",
" }\n",
" ],\n",
" \"tenant\": \"tenant/0a62f7c9-fd7b-4791-8041-01218d839ec1\",\n",
" \"description\": \"Sharing Album Release Info with Record Labels\"\n",
"}\n"
]
}
],
"source": [
"# Creates an Access Policy and prints result\n",
"access_policy = create_event_access(arch)\n",
"print(\"ACCESS_POLICY\", json_dumps(access_policy, indent=4))"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.15"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
1 change: 1 addition & 0 deletions docs/notebooks.rst
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ Download the notebooks into a suitable folder:
notebooks/Sharing Artist Asset with User
notebooks/Sharing Album Release Info with User
notebooks/Sharing Artist Asset with Record Labels
notebooks/Sharing Album Release Info with Record Labels

.. toctree::
:maxdepth: 2
Expand Down
14 changes: 14 additions & 0 deletions functests/execnotebooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,3 +290,17 @@ def test_share_artist_asset_recordlabel(self):
self.basic_notebook_test(notebook)
self.check_notebook_cell(notebook, 7)
LOGGER.debug("=================================")

@skip("Requires root access credentials -- see #7742")
def test_share_album_release_recordlabel(self):
"""
Test share_album_release_recordlabel
"""
with testbook(
"archivist/notebooks/Sharing Album Release Info with Record Labels.ipynb",
execute=True,
) as notebook:
LOGGER.debug("\nshare_album_release_recordlabel")
self.basic_notebook_test(notebook)
self.check_notebook_cell(notebook, 7)
LOGGER.debug("=================================")
10 changes: 10 additions & 0 deletions unittests/testnotebooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,3 +299,13 @@ def test_share_artist_asset_recordlabel(self):
execute=range(1, 6),
) as notebook:
self.basic_notebook_test(notebook)

def test_share_album_release_recordlabel(self):
"""
Test share_album_release_recordlabel
"""
with testbook(
"archivist/notebooks/Sharing Album Release Info with Record Labels.ipynb",
execute=range(1, 6),
) as notebook:
self.basic_notebook_test(notebook)