-
Notifications
You must be signed in to change notification settings - Fork 7
Access Policy that shares event level info with Record Companies #232
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
247 changes: 247 additions & 0 deletions
247
archivist/notebooks/Sharing Album Release Info with Record Labels.ipynb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.