|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "markdown", |
| 5 | + "id": "c268f287-98f5-4a34-9df4-e6e7dfd92143", |
| 6 | + "metadata": {}, |
| 7 | + "source": [ |
| 8 | + "## Sharing Artist Asset with Record Labels" |
| 9 | + ] |
| 10 | + }, |
| 11 | + { |
| 12 | + "cell_type": "code", |
| 13 | + "execution_count": 1, |
| 14 | + "id": "1b1ee270-8c52-4045-a7ae-98dc75c9eb64", |
| 15 | + "metadata": {}, |
| 16 | + "outputs": [], |
| 17 | + "source": [ |
| 18 | + "# Creates an Access Policy that shares \"read-only\" permission across RKVST tenancies.\n", |
| 19 | + "#\n", |
| 20 | + "# Main function, establishes a connection to RKVST using an App Registration then uses that\n", |
| 21 | + "# to create an Access Policy.\n", |
| 22 | + "#\n", |
| 23 | + "# Note: The purpose of RKVST Jupyter Notebooks is to provide simplified examples that one can easily execute and digest.\n", |
| 24 | + "# The RKVST Python SDK is authored to work cleanly with more advanced coding techniques.\n", |
| 25 | + "#\n", |
| 26 | + "# RKVST Python SDK: https://github.com/rkvst/rkvst-python\n", |
| 27 | + "#" |
| 28 | + ] |
| 29 | + }, |
| 30 | + { |
| 31 | + "cell_type": "code", |
| 32 | + "execution_count": 2, |
| 33 | + "id": "9b313d8f-6b6e-4980-a2d3-09c15006ae14", |
| 34 | + "metadata": {}, |
| 35 | + "outputs": [], |
| 36 | + "source": [ |
| 37 | + "import random\n", |
| 38 | + "import string\n", |
| 39 | + "\n", |
| 40 | + "from json import dumps as json_dumps\n", |
| 41 | + "from os import getenv\n", |
| 42 | + "from warnings import filterwarnings\n", |
| 43 | + "\n", |
| 44 | + "from dotenv import load_dotenv\n", |
| 45 | + "\n", |
| 46 | + "from archivist.archivist import Archivist\n", |
| 47 | + "from archivist.proof_mechanism import ProofMechanism\n", |
| 48 | + "from archivist.logger import set_logger\n", |
| 49 | + "from archivist.constants import ASSET_BEHAVIOURS" |
| 50 | + ] |
| 51 | + }, |
| 52 | + { |
| 53 | + "cell_type": "code", |
| 54 | + "execution_count": 3, |
| 55 | + "id": "c39219a9-d910-4e23-865e-9e549c331e3c", |
| 56 | + "metadata": {}, |
| 57 | + "outputs": [], |
| 58 | + "source": [ |
| 59 | + "%reload_ext dotenv\n", |
| 60 | + "%dotenv -o notebooks.env" |
| 61 | + ] |
| 62 | + }, |
| 63 | + { |
| 64 | + "cell_type": "code", |
| 65 | + "execution_count": 4, |
| 66 | + "id": "b95f35f9-7452-4e19-9e79-c48686729141", |
| 67 | + "metadata": {}, |
| 68 | + "outputs": [], |
| 69 | + "source": [ |
| 70 | + "# RKVST_URL, RKVST_APPREG_CLIENT, RKVST_APPREG_SECRET are environment variables that represent connection parameters.\n", |
| 71 | + "#\n", |
| 72 | + "# RKVST_URL = represents the url to the RKVST application\n", |
| 73 | + "# RKVST_APPREG_CLIENT = represents the client ID from an Application Registration\n", |
| 74 | + "# RKVST_APPREG_SECRET = represents the client secret from an Application Registration\n", |
| 75 | + "RKVST_URL = getenv(\"RKVST_URL\")\n", |
| 76 | + "RKVST_APPREG_CLIENT = getenv(\"RKVST_APPREG_CLIENT\")\n", |
| 77 | + "RKVST_APPREG_SECRET = getenv(\"RKVST_APPREG_SECRET\")" |
| 78 | + ] |
| 79 | + }, |
| 80 | + { |
| 81 | + "cell_type": "code", |
| 82 | + "execution_count": 5, |
| 83 | + "id": "7ab24ec2-b772-404a-b60c-37efcf32a9a6", |
| 84 | + "metadata": {}, |
| 85 | + "outputs": [ |
| 86 | + { |
| 87 | + "name": "stdout", |
| 88 | + "output_type": "stream", |
| 89 | + "text": [ |
| 90 | + "Connecting to RKVST\n", |
| 91 | + "RKVST_URL https://app.rkvst.io\n" |
| 92 | + ] |
| 93 | + } |
| 94 | + ], |
| 95 | + "source": [ |
| 96 | + "\"\"\"\n", |
| 97 | + "Main function of Access Policy creation.\n", |
| 98 | + "\n", |
| 99 | + "* Connect to RKVST with client ID and client secret\n", |
| 100 | + "* Creates an Access Policy\n", |
| 101 | + "* Prints response of Access Policy creation\n", |
| 102 | + "\"\"\"\n", |
| 103 | + "\n", |
| 104 | + "# Optional call to set the logger level. The argument can be either\n", |
| 105 | + "# \"INFO\" or \"DEBUG\". For more sophisticated logging control see our\n", |
| 106 | + "# documentation.\n", |
| 107 | + "set_logger(\"INFO\")\n", |
| 108 | + "\n", |
| 109 | + "# Initialize connection to RKVST\n", |
| 110 | + "print(\"Connecting to RKVST\")\n", |
| 111 | + "print(\"RKVST_URL\", RKVST_URL)\n", |
| 112 | + "arch = Archivist(RKVST_URL, (RKVST_APPREG_CLIENT, RKVST_APPREG_SECRET), max_time=300)" |
| 113 | + ] |
| 114 | + }, |
| 115 | + { |
| 116 | + "cell_type": "code", |
| 117 | + "execution_count": 6, |
| 118 | + "id": "9cb20418-bd3d-4bf9-8aaf-afb45b50a1bd", |
| 119 | + "metadata": {}, |
| 120 | + "outputs": [], |
| 121 | + "source": [ |
| 122 | + "def create_access(arch):\n", |
| 123 | + " \"\"\"\n", |
| 124 | + " Creates an Access Policy that shares read only data for Artists with other RKVST tenancies\n", |
| 125 | + " \"\"\"\n", |
| 126 | + " props = {\n", |
| 127 | + " \"display_name\": \"Sharing Artist Asset with Record Labels\",\n", |
| 128 | + " \"description\": \"Sharing Artist Asset with Record Labels\",\n", |
| 129 | + " }\n", |
| 130 | + " filters = [{\"or\": [\"attributes.arc_display_type=Artists\"]}]\n", |
| 131 | + " access_permissions = [\n", |
| 132 | + " {\n", |
| 133 | + " \"asset_attributes_read\": [\"*\"],\n", |
| 134 | + " \"asset_attributes_write\": [],\n", |
| 135 | + " \"behaviours\": ASSET_BEHAVIOURS,\n", |
| 136 | + " \"event_arc_display_type_read\": [\"*\"],\n", |
| 137 | + " \"event_arc_display_type_write\": [],\n", |
| 138 | + " \"include_attributes\": [],\n", |
| 139 | + " \"subjects\": [\"subjects/34b291c3-30f4-4d89-9ec7-85f57354f798\"],\n", |
| 140 | + " \"user_attributes\": [],\n", |
| 141 | + " }\n", |
| 142 | + " ]\n", |
| 143 | + "\n", |
| 144 | + " return arch.access_policies.create(props, filters, access_permissions)" |
| 145 | + ] |
| 146 | + }, |
| 147 | + { |
| 148 | + "cell_type": "code", |
| 149 | + "execution_count": 7, |
| 150 | + "id": "2992a91b-a5e3-43e6-bb76-7e96fdeb2a22", |
| 151 | + "metadata": {}, |
| 152 | + "outputs": [ |
| 153 | + { |
| 154 | + "name": "stderr", |
| 155 | + "output_type": "stream", |
| 156 | + "text": [ |
| 157 | + "Refresh token\n" |
| 158 | + ] |
| 159 | + }, |
| 160 | + { |
| 161 | + "name": "stdout", |
| 162 | + "output_type": "stream", |
| 163 | + "text": [ |
| 164 | + "ACCESS_POLICY {\n", |
| 165 | + " \"identity\": \"access_policies/df5f0048-ba9b-43b2-a7bf-82b8d2f603a3\",\n", |
| 166 | + " \"display_name\": \"Sharing Artist Asset with Record Labels\",\n", |
| 167 | + " \"filters\": [\n", |
| 168 | + " {\n", |
| 169 | + " \"or\": [\n", |
| 170 | + " \"attributes.arc_display_type=Artists\"\n", |
| 171 | + " ]\n", |
| 172 | + " }\n", |
| 173 | + " ],\n", |
| 174 | + " \"access_permissions\": [\n", |
| 175 | + " {\n", |
| 176 | + " \"subjects\": [\n", |
| 177 | + " \"subjects/34b291c3-30f4-4d89-9ec7-85f57354f798\"\n", |
| 178 | + " ],\n", |
| 179 | + " \"behaviours\": [\n", |
| 180 | + " \"Attachments\",\n", |
| 181 | + " \"RecordEvidence\"\n", |
| 182 | + " ],\n", |
| 183 | + " \"include_attributes\": [],\n", |
| 184 | + " \"user_attributes\": [],\n", |
| 185 | + " \"asset_attributes_read\": [\n", |
| 186 | + " \"*\"\n", |
| 187 | + " ],\n", |
| 188 | + " \"asset_attributes_write\": [],\n", |
| 189 | + " \"event_arc_display_type_read\": [\n", |
| 190 | + " \"*\"\n", |
| 191 | + " ],\n", |
| 192 | + " \"event_arc_display_type_write\": []\n", |
| 193 | + " }\n", |
| 194 | + " ],\n", |
| 195 | + " \"tenant\": \"tenant/0a62f7c9-fd7b-4791-8041-01218d839ec1\",\n", |
| 196 | + " \"description\": \"Sharing Artist Asset with Record Labels\"\n", |
| 197 | + "}\n" |
| 198 | + ] |
| 199 | + } |
| 200 | + ], |
| 201 | + "source": [ |
| 202 | + "# Creates an Access Policy and prints result\n", |
| 203 | + "access_policy = create_access(arch)\n", |
| 204 | + "print(\"ACCESS_POLICY\", json_dumps(access_policy, indent=4))" |
| 205 | + ] |
| 206 | + } |
| 207 | + ], |
| 208 | + "metadata": { |
| 209 | + "kernelspec": { |
| 210 | + "display_name": "Python 3 (ipykernel)", |
| 211 | + "language": "python", |
| 212 | + "name": "python3" |
| 213 | + }, |
| 214 | + "language_info": { |
| 215 | + "codemirror_mode": { |
| 216 | + "name": "ipython", |
| 217 | + "version": 3 |
| 218 | + }, |
| 219 | + "file_extension": ".py", |
| 220 | + "mimetype": "text/x-python", |
| 221 | + "name": "python", |
| 222 | + "nbconvert_exporter": "python", |
| 223 | + "pygments_lexer": "ipython3", |
| 224 | + "version": "3.8.15" |
| 225 | + } |
| 226 | + }, |
| 227 | + "nbformat": 4, |
| 228 | + "nbformat_minor": 5 |
| 229 | +} |
0 commit comments