Checking the Dog's Weight

[1]:
# Create Compliance RICHNESS Policy
#
# Main function, establishes a connection to DataTrails using an App Registration then uses that
# to create a Compliance RICHNESS Policy.
#
# Note: The purpose of DataTrails Jupyter Notebooks is to provide simplified examples that one can easily execute and digest.
# The DataTrails Python SDK is authored to work cleanly with more advanced coding techniques.
#
# DataTrails Python SDK: https://github.com/datatrails/datatrails-python
#
[2]:
import random
import string

from json import dumps as json_dumps
from os import getenv
from warnings import filterwarnings

from dotenv import load_dotenv

from archivist.archivist import Archivist
from archivist.compliance_policy_requests import (
    CompliancePolicyRichness,
)
from archivist.logger import set_logger
[3]:
%reload_ext dotenv
%dotenv -o notebooks.env
[4]:
# DATATRAILS_URL, DATATRAILS_APPREG_CLIENT, DATATRAILS_APPREG_SECRET are environment variables that represent connection parameters.
#
# DATATRAILS_URL = represents the url to the DataTrails application
# DATATRAILS_APPREG_CLIENT = represents the client ID from an Application Registration
# DATATRAILS_APPREG_SECRET = represents the client secret from an Application Registration
DATATRAILS_URL = getenv("DATATRAILS_URL")
DATATRAILS_APPREG_CLIENT = getenv("DATATRAILS_APPREG_CLIENT")
DATATRAILS_APPREG_SECRET = getenv("DATATRAILS_APPREG_SECRET")
[5]:
"""
Main function of RICHNESS policy creation.

* Connect to DataTrails with client ID and client secret
* Creates a Compliance RICHNESS Policy
"""

# Optional call to set the logger level.  The argument can be either
# "INFO" or "DEBUG".  For more sophisticated logging control see our
# documentation.
set_logger("INFO")

# Initialize connection to DATATRAILS
print("Connecting to DATATRAILS")
print("DATATRAILS_URL", DATATRAILS_URL)
arch = Archivist(
    DATATRAILS_URL, (DATATRAILS_APPREG_CLIENT, DATATRAILS_APPREG_SECRET), max_time=300
)
Connecting to DATATRAILS
DATATRAILS_URL https://app.datatrails.ai
[6]:
def create_compliance_policy(arch):
    """
    Creates a RICHNESS compliance policy for a dog's weight. If the dog's weight is
    over 60lbs then Golden Retriever Asset is out of compliance.
    """
    richness_policy = arch.compliance_policies.create(
        CompliancePolicyRichness(
            description="Dog's weight not over 60lbs",
            display_name="Dog's weight not over 60lbs",
            asset_filter=[
                ["attributes.arc_display_type=Golden Retriever"],
            ],
            richness_assertions=[
                ["Weight<61"],
            ],
        )
    )
    print("RICHNESS_POLICY:", json_dumps(richness_policy, indent=4))
    return richness_policy
[7]:
# Creates RICHNESS compliance policy and prints result
compliance_policy = create_compliance_policy(arch)
print("Compliance_Policy", json_dumps(compliance_policy, indent=4))
Refresh token
RICHNESS_POLICY: {
    "identity": "compliance_policies/c459c04d-4664-4ce1-9855-b64ed03dbec1",
    "compliance_type": "COMPLIANCE_RICHNESS",
    "description": "Dog's weight not over 60lbs",
    "display_name": "Dog's weight not over 60lbs",
    "asset_filter": [
        {
            "or": [
                "attributes.arc_display_type=Golden Retriever"
            ]
        }
    ],
    "event_display_type": "",
    "closing_event_display_type": "",
    "time_period_seconds": "0",
    "dynamic_window": "0",
    "dynamic_variability": 0,
    "richness_assertions": [
        {
            "or": [
                "Weight<61"
            ]
        }
    ]
}
Compliance_Policy {
    "identity": "compliance_policies/c459c04d-4664-4ce1-9855-b64ed03dbec1",
    "compliance_type": "COMPLIANCE_RICHNESS",
    "description": "Dog's weight not over 60lbs",
    "display_name": "Dog's weight not over 60lbs",
    "asset_filter": [
        {
            "or": [
                "attributes.arc_display_type=Golden Retriever"
            ]
        }
    ],
    "event_display_type": "",
    "closing_event_display_type": "",
    "time_period_seconds": "0",
    "dynamic_window": "0",
    "dynamic_variability": 0,
    "richness_assertions": [
        {
            "or": [
                "Weight<61"
            ]
        }
    ]
}