Skip to content

Commit 1e18920

Browse files
authored
Merge pull request #219 from rkvst/mmwilder26/jpn_compliance_pytoml
Re-Adding Compliance Notebooks, Functests, Unittests, Notebooks.rst
2 parents 6b621b0 + 6692209 commit 1e18920

9 files changed

+1311
-2
lines changed
Lines changed: 236 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,236 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"id": "223675ce-b5ad-4c2b-83e8-3681b5c23b1e",
6+
"metadata": {},
7+
"source": [
8+
"## Create Compliance CURRENT OUTSTANDING Policy"
9+
]
10+
},
11+
{
12+
"cell_type": "code",
13+
"execution_count": 1,
14+
"id": "0a6bf094-1f8d-412f-ac1a-c303ee77fdac",
15+
"metadata": {},
16+
"outputs": [],
17+
"source": [
18+
"# Create Compliance CURRENT OUTSTANDING Policy\n",
19+
"#\n",
20+
"# Main function, establishes a connection to RKVST using an App Registration then uses that\n",
21+
"# to create a Compliance CURRENT OUTSTANDING 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": "e01c8b81-7a3a-4591-bfee-47da41db95f8",
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.compliance_policy_requests import (\n",
48+
" CompliancePolicyCurrentOutstanding,\n",
49+
")\n",
50+
"from archivist.proof_mechanism import ProofMechanism\n",
51+
"from archivist.logger import set_logger"
52+
]
53+
},
54+
{
55+
"cell_type": "code",
56+
"execution_count": 3,
57+
"id": "c9c8be0b-3d49-4655-9ac0-1a9c3c1758ee",
58+
"metadata": {},
59+
"outputs": [],
60+
"source": [
61+
"%reload_ext dotenv\n",
62+
"%dotenv -o notebooks.env"
63+
]
64+
},
65+
{
66+
"cell_type": "code",
67+
"execution_count": 4,
68+
"id": "5438ccf8-1ea0-4bc8-bbf4-7ddb7aab59e2",
69+
"metadata": {},
70+
"outputs": [],
71+
"source": [
72+
"# RKVST_URL, RKVST_APPREG_CLIENT, RKVST_APPREG_SECRET are environment variables that represent connection parameters.\n",
73+
"#\n",
74+
"# RKVST_URL = represents the url to the RKVST application\n",
75+
"# RKVST_APPREG_CLIENT = represents the client ID from an Application Registration\n",
76+
"# RKVST_APPREG_SECRET = represents the client secret from an Application Registration\n",
77+
"RKVST_URL = getenv(\"RKVST_URL\")\n",
78+
"RKVST_APPREG_CLIENT = getenv(\"RKVST_APPREG_CLIENT\")\n",
79+
"RKVST_APPREG_SECRET = getenv(\"RKVST_APPREG_SECRET\")"
80+
]
81+
},
82+
{
83+
"cell_type": "code",
84+
"execution_count": 5,
85+
"id": "358d3939-87df-4b36-b19c-399c6ee18278",
86+
"metadata": {},
87+
"outputs": [
88+
{
89+
"name": "stdout",
90+
"output_type": "stream",
91+
"text": [
92+
"Connecting to RKVST\n",
93+
"RKVST_URL https://app.rkvst.io\n"
94+
]
95+
}
96+
],
97+
"source": [
98+
"\"\"\"\n",
99+
"Main function of CURRENT OUTSTANDING policy creation.\n",
100+
"\n",
101+
"* Connect to RKVST with client ID and client secret\n",
102+
"* Creates a Compliance CURRENT OUTSTANDING Policy\n",
103+
"\"\"\"\n",
104+
"\n",
105+
"# Optional call to set the logger level. The argument can be either\n",
106+
"# \"INFO\" or \"DEBUG\". For more sophisticated logging control see our\n",
107+
"# documentation.\n",
108+
"set_logger(\"INFO\")\n",
109+
"\n",
110+
"# Initialize connection to RKVST\n",
111+
"print(\"Connecting to RKVST\")\n",
112+
"print(\"RKVST_URL\", RKVST_URL)\n",
113+
"arch = Archivist(RKVST_URL, (RKVST_APPREG_CLIENT, RKVST_APPREG_SECRET), max_time=300)"
114+
]
115+
},
116+
{
117+
"cell_type": "code",
118+
"execution_count": 6,
119+
"id": "d62d889b-d9f1-43a0-81c0-eda9c013091f",
120+
"metadata": {},
121+
"outputs": [],
122+
"source": [
123+
"def create_compliance_policy(arch):\n",
124+
" \"\"\"\n",
125+
" Creates a CURRENT OUTSTANDING compliance policy for feeding one's dog. If RKVST sees a \"Feed\"\n",
126+
" event without a closing \"Fed\" event, then Golden Retriever Asset is out of compliance.\n",
127+
" \"\"\"\n",
128+
" current_outstanding_policy = arch.compliance_policies.create(\n",
129+
" CompliancePolicyCurrentOutstanding(\n",
130+
" description=\"Ensuring my dog is fed\",\n",
131+
" display_name=\"Feeding My Dog\",\n",
132+
" asset_filter=[\n",
133+
" [\"attributes.arc_display_type=Golden Retriever\"],\n",
134+
" ],\n",
135+
" event_display_type=\"Feed\",\n",
136+
" closing_event_display_type=\"Fed\",\n",
137+
" )\n",
138+
" )\n",
139+
" print(\n",
140+
" \"CURRENT_OUTSTANDING_POLICY:\", json_dumps(current_outstanding_policy, indent=4)\n",
141+
" )\n",
142+
" return current_outstanding_policy"
143+
]
144+
},
145+
{
146+
"cell_type": "code",
147+
"execution_count": 7,
148+
"id": "fb43cce9-6222-46b2-bd94-ac07263a2bd9",
149+
"metadata": {},
150+
"outputs": [
151+
{
152+
"name": "stderr",
153+
"output_type": "stream",
154+
"text": [
155+
"Refresh token\n"
156+
]
157+
},
158+
{
159+
"name": "stdout",
160+
"output_type": "stream",
161+
"text": [
162+
"CURRENT_OUTSTANDING_POLICY: {\n",
163+
" \"identity\": \"compliance_policies/f896247e-bca5-4410-8c30-09adf81e9244\",\n",
164+
" \"compliance_type\": \"COMPLIANCE_CURRENT_OUTSTANDING\",\n",
165+
" \"description\": \"Ensuring my dog is fed\",\n",
166+
" \"display_name\": \"Feeding My Dog\",\n",
167+
" \"asset_filter\": [\n",
168+
" {\n",
169+
" \"or\": [\n",
170+
" \"attributes.arc_display_type=Golden Retriever\"\n",
171+
" ]\n",
172+
" }\n",
173+
" ],\n",
174+
" \"event_display_type\": \"Feed\",\n",
175+
" \"closing_event_display_type\": \"Fed\",\n",
176+
" \"time_period_seconds\": \"0\",\n",
177+
" \"dynamic_window\": \"0\",\n",
178+
" \"dynamic_variability\": 0,\n",
179+
" \"richness_assertions\": []\n",
180+
"}\n",
181+
"Compliance_Policy {\n",
182+
" \"identity\": \"compliance_policies/f896247e-bca5-4410-8c30-09adf81e9244\",\n",
183+
" \"compliance_type\": \"COMPLIANCE_CURRENT_OUTSTANDING\",\n",
184+
" \"description\": \"Ensuring my dog is fed\",\n",
185+
" \"display_name\": \"Feeding My Dog\",\n",
186+
" \"asset_filter\": [\n",
187+
" {\n",
188+
" \"or\": [\n",
189+
" \"attributes.arc_display_type=Golden Retriever\"\n",
190+
" ]\n",
191+
" }\n",
192+
" ],\n",
193+
" \"event_display_type\": \"Feed\",\n",
194+
" \"closing_event_display_type\": \"Fed\",\n",
195+
" \"time_period_seconds\": \"0\",\n",
196+
" \"dynamic_window\": \"0\",\n",
197+
" \"dynamic_variability\": 0,\n",
198+
" \"richness_assertions\": []\n",
199+
"}\n"
200+
]
201+
}
202+
],
203+
"source": [
204+
"# Creates CURRENT OUTSTANDING compliance policy and prints result\n",
205+
"compliance_policy = create_compliance_policy(arch)\n",
206+
"print(\"Compliance_Policy\", json_dumps(compliance_policy, indent=4))"
207+
]
208+
}
209+
],
210+
"metadata": {
211+
"kernelspec": {
212+
"display_name": "base",
213+
"language": "python",
214+
"name": "python3"
215+
},
216+
"language_info": {
217+
"codemirror_mode": {
218+
"name": "ipython",
219+
"version": 3
220+
},
221+
"file_extension": ".py",
222+
"mimetype": "text/x-python",
223+
"name": "python",
224+
"nbconvert_exporter": "python",
225+
"pygments_lexer": "ipython3",
226+
"version": "3.9.6"
227+
},
228+
"vscode": {
229+
"interpreter": {
230+
"hash": "c11202d2846b22eec7deaf37ea813ba92a5f75b5344a4d16688175855af7948e"
231+
}
232+
}
233+
},
234+
"nbformat": 4,
235+
"nbformat_minor": 5
236+
}

0 commit comments

Comments
 (0)