Skip to content

Commit f3a1970

Browse files
authored
Merge pull request #232 from rkvst/mmwilder26/jpn_share_album_recordlabels
Access Policy that shares event level info with Record Companies
2 parents e6e75b8 + 072f7a4 commit f3a1970

File tree

4 files changed

+272
-0
lines changed

4 files changed

+272
-0
lines changed
Lines changed: 247 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,247 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"id": "ae305cf3-4dc9-4f3d-bc48-6467101cbc47",
6+
"metadata": {},
7+
"source": [
8+
"## Sharing Album Release Info with Record Labels"
9+
]
10+
},
11+
{
12+
"cell_type": "code",
13+
"execution_count": 1,
14+
"id": "2a4a0d3f-d774-411a-969b-7e7aad31cb0d",
15+
"metadata": {},
16+
"outputs": [],
17+
"source": [
18+
"# Pre-requisite: Ensure that RKVST Subject IDS have been exchanged with parties that one\n",
19+
"# wants to share with BEFORE creating this Access Policy.\n",
20+
"#\n",
21+
"# How to exchange RKVST Subject IDs:\n",
22+
"# https://docs.rkvst.com/docs/rkvst-basics/sharing-assets-with-obac/\n",
23+
"#\n",
24+
"# Creates an Access Policy that shares event-level \"read-only\" permission across RKVST tenancies.\n",
25+
"#\n",
26+
"# Main function, establishes a connection to RKVST using an App Registration then uses that\n",
27+
"# to create an Access Policy.\n",
28+
"#\n",
29+
"# Note: The purpose of RKVST Jupyter Notebooks is to provide simplified examples that one can easily execute and digest.\n",
30+
"# The RKVST Python SDK is authored to work cleanly with more advanced coding techniques.\n",
31+
"#\n",
32+
"# RKVST Python SDK: https://github.com/rkvst/rkvst-python\n",
33+
"#"
34+
]
35+
},
36+
{
37+
"cell_type": "code",
38+
"execution_count": 2,
39+
"id": "e3dc6e9d-e910-44af-b61e-5016b92b5da0",
40+
"metadata": {},
41+
"outputs": [],
42+
"source": [
43+
"import random\n",
44+
"import string\n",
45+
"\n",
46+
"from json import dumps as json_dumps\n",
47+
"from os import getenv\n",
48+
"from warnings import filterwarnings\n",
49+
"\n",
50+
"from dotenv import load_dotenv\n",
51+
"\n",
52+
"from archivist.archivist import Archivist\n",
53+
"from archivist.proof_mechanism import ProofMechanism\n",
54+
"from archivist.logger import set_logger\n",
55+
"from archivist.constants import ASSET_BEHAVIOURS"
56+
]
57+
},
58+
{
59+
"cell_type": "code",
60+
"execution_count": 3,
61+
"id": "819162de-c4b1-4c6a-a078-fc327db97e80",
62+
"metadata": {},
63+
"outputs": [],
64+
"source": [
65+
"%reload_ext dotenv\n",
66+
"%dotenv -o notebooks.env"
67+
]
68+
},
69+
{
70+
"cell_type": "code",
71+
"execution_count": 4,
72+
"id": "cb56cd35-41a0-40e4-948f-c327557feb09",
73+
"metadata": {},
74+
"outputs": [],
75+
"source": [
76+
"# RKVST_URL, RKVST_APPREG_CLIENT, RKVST_APPREG_SECRET are environment variables that represent connection parameters.\n",
77+
"#\n",
78+
"# RKVST_URL = represents the url to the RKVST application\n",
79+
"# RKVST_APPREG_CLIENT = represents the client ID from an Application Registration\n",
80+
"# RKVST_APPREG_SECRET = represents the client secret from an Application Registration\n",
81+
"RKVST_URL = getenv(\"RKVST_URL\")\n",
82+
"RKVST_APPREG_CLIENT = getenv(\"RKVST_APPREG_CLIENT\")\n",
83+
"RKVST_APPREG_SECRET = getenv(\"RKVST_APPREG_SECRET\")"
84+
]
85+
},
86+
{
87+
"cell_type": "code",
88+
"execution_count": 5,
89+
"id": "ffa23b6d-5dd5-494e-8707-6af11ea1dbe6",
90+
"metadata": {},
91+
"outputs": [
92+
{
93+
"name": "stdout",
94+
"output_type": "stream",
95+
"text": [
96+
"Connecting to RKVST\n",
97+
"RKVST_URL https://app.rkvst.io\n"
98+
]
99+
}
100+
],
101+
"source": [
102+
"\"\"\"\n",
103+
"Main function of Access Policy creation.\n",
104+
"\n",
105+
"* Connect to RKVST with client ID and client secret\n",
106+
"* Creates an Access Policy\n",
107+
"* Prints response of Access Policy creation\n",
108+
"\"\"\"\n",
109+
"\n",
110+
"# Optional call to set the logger level. The argument can be either\n",
111+
"# \"INFO\" or \"DEBUG\". For more sophisticated logging control see our\n",
112+
"# documentation.\n",
113+
"set_logger(\"INFO\")\n",
114+
"\n",
115+
"# Initialize connection to RKVST\n",
116+
"print(\"Connecting to RKVST\")\n",
117+
"print(\"RKVST_URL\", RKVST_URL)\n",
118+
"arch = Archivist(RKVST_URL, (RKVST_APPREG_CLIENT, RKVST_APPREG_SECRET), max_time=300)"
119+
]
120+
},
121+
{
122+
"cell_type": "code",
123+
"execution_count": 6,
124+
"id": "bae05b9c-cafa-4e81-bcb5-3cfcf3e70de7",
125+
"metadata": {},
126+
"outputs": [],
127+
"source": [
128+
"def create_event_access(arch):\n",
129+
" \"\"\"\n",
130+
" Pre-requisite: Ensure that RKVST Subject IDS have been exchanged with parties that one\n",
131+
" wants to share with BEFORE creating this Access Policy.\n",
132+
"\n",
133+
" How to exchange RKVST Subject IDs:\n",
134+
" https://docs.rkvst.com/docs/rkvst-basics/sharing-assets-with-obac/\n",
135+
"\n",
136+
" Creates an Access Policy that shares Album Release data for Artists with other RKVST tenancies\n",
137+
" \"\"\"\n",
138+
" props = {\n",
139+
" \"display_name\": \"Sharing Album Release Info with Record Labels\",\n",
140+
" \"description\": \"Sharing Album Release Info with Record Labels\",\n",
141+
" }\n",
142+
" filters = [{\"or\": [\"attributes.arc_display_type=Artists\"]}]\n",
143+
" access_permissions = [\n",
144+
" {\n",
145+
" \"asset_attributes_read\": [\n",
146+
" \"arc_display_name\",\n",
147+
" \"arc_display_type\",\n",
148+
" \"arc_description\",\n",
149+
" ],\n",
150+
" \"asset_attributes_write\": [],\n",
151+
" \"behaviours\": ASSET_BEHAVIOURS,\n",
152+
" \"event_arc_display_type_read\": [\"Album Release\"],\n",
153+
" \"event_arc_display_type_write\": [],\n",
154+
" \"include_attributes\": [],\n",
155+
" \"subjects\": [\"subjects/34b291c3-30f4-4d89-9ec7-85f57354f798\"],\n",
156+
" \"user_attributes\": [],\n",
157+
" }\n",
158+
" ]\n",
159+
"\n",
160+
" return arch.access_policies.create(props, filters, access_permissions)"
161+
]
162+
},
163+
{
164+
"cell_type": "code",
165+
"execution_count": 7,
166+
"id": "678dd908-413e-4ac8-8d96-2948de403238",
167+
"metadata": {},
168+
"outputs": [
169+
{
170+
"name": "stderr",
171+
"output_type": "stream",
172+
"text": [
173+
"Refresh token\n"
174+
]
175+
},
176+
{
177+
"name": "stdout",
178+
"output_type": "stream",
179+
"text": [
180+
"ACCESS_POLICY {\n",
181+
" \"identity\": \"access_policies/2f30120d-55ba-4aeb-80cf-059abe37f9d2\",\n",
182+
" \"display_name\": \"Sharing Album Release Info with Record Labels\",\n",
183+
" \"filters\": [\n",
184+
" {\n",
185+
" \"or\": [\n",
186+
" \"attributes.arc_display_type=Artists\"\n",
187+
" ]\n",
188+
" }\n",
189+
" ],\n",
190+
" \"access_permissions\": [\n",
191+
" {\n",
192+
" \"subjects\": [\n",
193+
" \"subjects/34b291c3-30f4-4d89-9ec7-85f57354f798\"\n",
194+
" ],\n",
195+
" \"behaviours\": [\n",
196+
" \"Attachments\",\n",
197+
" \"RecordEvidence\"\n",
198+
" ],\n",
199+
" \"include_attributes\": [],\n",
200+
" \"user_attributes\": [],\n",
201+
" \"asset_attributes_read\": [\n",
202+
" \"arc_display_name\",\n",
203+
" \"arc_display_type\",\n",
204+
" \"arc_description\"\n",
205+
" ],\n",
206+
" \"asset_attributes_write\": [],\n",
207+
" \"event_arc_display_type_read\": [\n",
208+
" \"Album Release\"\n",
209+
" ],\n",
210+
" \"event_arc_display_type_write\": []\n",
211+
" }\n",
212+
" ],\n",
213+
" \"tenant\": \"tenant/0a62f7c9-fd7b-4791-8041-01218d839ec1\",\n",
214+
" \"description\": \"Sharing Album Release Info with Record Labels\"\n",
215+
"}\n"
216+
]
217+
}
218+
],
219+
"source": [
220+
"# Creates an Access Policy and prints result\n",
221+
"access_policy = create_event_access(arch)\n",
222+
"print(\"ACCESS_POLICY\", json_dumps(access_policy, indent=4))"
223+
]
224+
}
225+
],
226+
"metadata": {
227+
"kernelspec": {
228+
"display_name": "Python 3 (ipykernel)",
229+
"language": "python",
230+
"name": "python3"
231+
},
232+
"language_info": {
233+
"codemirror_mode": {
234+
"name": "ipython",
235+
"version": 3
236+
},
237+
"file_extension": ".py",
238+
"mimetype": "text/x-python",
239+
"name": "python",
240+
"nbconvert_exporter": "python",
241+
"pygments_lexer": "ipython3",
242+
"version": "3.8.15"
243+
}
244+
},
245+
"nbformat": 4,
246+
"nbformat_minor": 5
247+
}

docs/notebooks.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ Download the notebooks into a suitable folder:
6666
notebooks/Sharing Artist Asset with User
6767
notebooks/Sharing Album Release Info with User
6868
notebooks/Sharing Artist Asset with Record Labels
69+
notebooks/Sharing Album Release Info with Record Labels
6970

7071
.. toctree::
7172
:maxdepth: 2

functests/execnotebooks.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,3 +290,17 @@ def test_share_artist_asset_recordlabel(self):
290290
self.basic_notebook_test(notebook)
291291
self.check_notebook_cell(notebook, 7)
292292
LOGGER.debug("=================================")
293+
294+
@skip("Requires root access credentials -- see #7742")
295+
def test_share_album_release_recordlabel(self):
296+
"""
297+
Test share_album_release_recordlabel
298+
"""
299+
with testbook(
300+
"archivist/notebooks/Sharing Album Release Info with Record Labels.ipynb",
301+
execute=True,
302+
) as notebook:
303+
LOGGER.debug("\nshare_album_release_recordlabel")
304+
self.basic_notebook_test(notebook)
305+
self.check_notebook_cell(notebook, 7)
306+
LOGGER.debug("=================================")

unittests/testnotebooks.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,3 +299,13 @@ def test_share_artist_asset_recordlabel(self):
299299
execute=range(1, 6),
300300
) as notebook:
301301
self.basic_notebook_test(notebook)
302+
303+
def test_share_album_release_recordlabel(self):
304+
"""
305+
Test share_album_release_recordlabel
306+
"""
307+
with testbook(
308+
"archivist/notebooks/Sharing Album Release Info with Record Labels.ipynb",
309+
execute=range(1, 6),
310+
) as notebook:
311+
self.basic_notebook_test(notebook)

0 commit comments

Comments
 (0)