Skip to content

Commit

Permalink
Merge pull request #219 from rkvst/mmwilder26/jpn_compliance_pytoml
Browse files Browse the repository at this point in the history
Re-Adding Compliance Notebooks, Functests, Unittests, Notebooks.rst
  • Loading branch information
mmwilder26 authored Feb 14, 2023
2 parents 6b621b0 + 6692209 commit 1e18920
Show file tree
Hide file tree
Showing 9 changed files with 1,311 additions and 2 deletions.
236 changes: 236 additions & 0 deletions archivist/notebooks/Create Compliance CURRENT OUTSTANDING Policy.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,236 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "223675ce-b5ad-4c2b-83e8-3681b5c23b1e",
"metadata": {},
"source": [
"## Create Compliance CURRENT OUTSTANDING Policy"
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "0a6bf094-1f8d-412f-ac1a-c303ee77fdac",
"metadata": {},
"outputs": [],
"source": [
"# Create Compliance CURRENT OUTSTANDING Policy\n",
"#\n",
"# Main function, establishes a connection to RKVST using an App Registration then uses that\n",
"# to create a Compliance CURRENT OUTSTANDING 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": "e01c8b81-7a3a-4591-bfee-47da41db95f8",
"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.compliance_policy_requests import (\n",
" CompliancePolicyCurrentOutstanding,\n",
")\n",
"from archivist.proof_mechanism import ProofMechanism\n",
"from archivist.logger import set_logger"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "c9c8be0b-3d49-4655-9ac0-1a9c3c1758ee",
"metadata": {},
"outputs": [],
"source": [
"%reload_ext dotenv\n",
"%dotenv -o notebooks.env"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "5438ccf8-1ea0-4bc8-bbf4-7ddb7aab59e2",
"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": "358d3939-87df-4b36-b19c-399c6ee18278",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Connecting to RKVST\n",
"RKVST_URL https://app.rkvst.io\n"
]
}
],
"source": [
"\"\"\"\n",
"Main function of CURRENT OUTSTANDING policy creation.\n",
"\n",
"* Connect to RKVST with client ID and client secret\n",
"* Creates a Compliance CURRENT OUTSTANDING Policy\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": "d62d889b-d9f1-43a0-81c0-eda9c013091f",
"metadata": {},
"outputs": [],
"source": [
"def create_compliance_policy(arch):\n",
" \"\"\"\n",
" Creates a CURRENT OUTSTANDING compliance policy for feeding one's dog. If RKVST sees a \"Feed\"\n",
" event without a closing \"Fed\" event, then Golden Retriever Asset is out of compliance.\n",
" \"\"\"\n",
" current_outstanding_policy = arch.compliance_policies.create(\n",
" CompliancePolicyCurrentOutstanding(\n",
" description=\"Ensuring my dog is fed\",\n",
" display_name=\"Feeding My Dog\",\n",
" asset_filter=[\n",
" [\"attributes.arc_display_type=Golden Retriever\"],\n",
" ],\n",
" event_display_type=\"Feed\",\n",
" closing_event_display_type=\"Fed\",\n",
" )\n",
" )\n",
" print(\n",
" \"CURRENT_OUTSTANDING_POLICY:\", json_dumps(current_outstanding_policy, indent=4)\n",
" )\n",
" return current_outstanding_policy"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "fb43cce9-6222-46b2-bd94-ac07263a2bd9",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"Refresh token\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"CURRENT_OUTSTANDING_POLICY: {\n",
" \"identity\": \"compliance_policies/f896247e-bca5-4410-8c30-09adf81e9244\",\n",
" \"compliance_type\": \"COMPLIANCE_CURRENT_OUTSTANDING\",\n",
" \"description\": \"Ensuring my dog is fed\",\n",
" \"display_name\": \"Feeding My Dog\",\n",
" \"asset_filter\": [\n",
" {\n",
" \"or\": [\n",
" \"attributes.arc_display_type=Golden Retriever\"\n",
" ]\n",
" }\n",
" ],\n",
" \"event_display_type\": \"Feed\",\n",
" \"closing_event_display_type\": \"Fed\",\n",
" \"time_period_seconds\": \"0\",\n",
" \"dynamic_window\": \"0\",\n",
" \"dynamic_variability\": 0,\n",
" \"richness_assertions\": []\n",
"}\n",
"Compliance_Policy {\n",
" \"identity\": \"compliance_policies/f896247e-bca5-4410-8c30-09adf81e9244\",\n",
" \"compliance_type\": \"COMPLIANCE_CURRENT_OUTSTANDING\",\n",
" \"description\": \"Ensuring my dog is fed\",\n",
" \"display_name\": \"Feeding My Dog\",\n",
" \"asset_filter\": [\n",
" {\n",
" \"or\": [\n",
" \"attributes.arc_display_type=Golden Retriever\"\n",
" ]\n",
" }\n",
" ],\n",
" \"event_display_type\": \"Feed\",\n",
" \"closing_event_display_type\": \"Fed\",\n",
" \"time_period_seconds\": \"0\",\n",
" \"dynamic_window\": \"0\",\n",
" \"dynamic_variability\": 0,\n",
" \"richness_assertions\": []\n",
"}\n"
]
}
],
"source": [
"# Creates CURRENT OUTSTANDING compliance policy and prints result\n",
"compliance_policy = create_compliance_policy(arch)\n",
"print(\"Compliance_Policy\", json_dumps(compliance_policy, indent=4))"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "base",
"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.9.6"
},
"vscode": {
"interpreter": {
"hash": "c11202d2846b22eec7deaf37ea813ba92a5f75b5344a4d16688175855af7948e"
}
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Loading

0 comments on commit 1e18920

Please sign in to comment.