Administrative operations#

This notebook showcases the usage of admin operations provided by the library. These operations typically involve tasks related to managing the library environment, such as setting up configurations, managing dependencies, and performing administrative tasks.

[ ]:
!pip install antimatter
[ ]:
import os
from antimatter import new_domain, Session
from antimatter.builders import *
from antimatter.datatype.datatypes import Datatype

os.environ["ANTIMATTER_API_URL"] = "https://api.dev.antimatter.io"

Register a domain and create a read/write context#

[ ]:
# Either create a new domain or use an existing one
if True:
    sess = new_domain("<my_email_address>")
    print ("domain: %s" % (sess.domain_id))
    print(f"sess = Session.from_api_key(domain_id='{sess.domain_id}', api_key='{sess.api_key}')")
else:
    sess = Session.from_api_key(domain_id='<domain_id>', api_key='<api_key>')

file_name = "/tmp/testdata.capsule"

List the write context#

[ ]:
sess.list_write_context()

Describe the write context#

[ ]:
sess.describe_write_context('default')

List the read context#

[ ]:
sess.list_read_context()

Describe the read context#

[ ]:
sess.describe_read_context('default')

List the facts#

[ ]:
sess.list_fact_types()

Add a fact type#

[ ]:
sess.add_fact_type(
    "is_project_member",
    description="Team membership",
    arguments={"name": "name of the member", "project": "name of the project"},
)
[ ]:
sess.add_fact(
    "is_project_member",
    "bazProject",
    "fooPerson",
)
sess.add_fact(
    "is_project_member",
    "bazProject",
    "fooPerson2",
)
[ ]:
sess.add_fact(
    "is_project_member",
    "bazProject2",
    "fooPerson3",
)
sess.add_fact(
    "is_project_member",
    "bazProject2",
    "fooPerson4",
)
[ ]:
sess.get_fact_type('is_project_member')
[ ]:
facts = sess.list_facts('is_project_member')
facts

Get a fact from the id#

[ ]:
sess.get_fact('is_project_member', facts[0].id)

Add a data policy with rules to redact#

Add a data policy with rules to redact “tag.antimatter.io/pii/email_address” & the “tag.antimatter.io/pii/credit_card” tags and bind it to the read context

[ ]:
res = sess.create_data_policy("my_data_policy", "sample description")
policy_id = res.policy_id

res = sess.update_data_policy_rules(
    policy_id=policy_id,
    rules=DataPolicyRuleChangesBuilder().add_rule(
        NewDataPolicyRuleBuilder(comment="Deny", effect=RuleEffect.REDACT, priority=10).add_clause(
            clause=DataPolicyClauseBuilder(ClauseOperator.AnyOf).add_tag(
                TagExpressionBuilder()
                .set_name("tag.antimatter.io/pii/email_address")
                .set_operator(Operator.Exists)
            )
        )
    ),
)

sess.set_data_policy_binding(
    policy_id=policy_id,
    default_attachment=Attachment.NotAttached,
    read_contexts=[("default", Attachment.Attached)],
)
[ ]:
res = sess.update_data_policy_rules(
    policy_id=policy_id,
    rules=DataPolicyRuleChangesBuilder().add_rule(
        NewDataPolicyRuleBuilder(comment="Deny", effect=RuleEffect.REDACT, priority=20).add_clause(
            clause=DataPolicyClauseBuilder(ClauseOperator.AnyOf).add_tag(
                TagExpressionBuilder()
                .set_name("tag.antimatter.io/pii/credit_card")
                .set_operator(Operator.Exists)
            )
        )
    ),
)

Describe the data policy rules which should now show the updated rules#

[ ]:
rules = sess.describe_data_policy(policy_id)
rules

Delete the last rule created#

[ ]:
sess.delete_data_policy_rule(policy_id, rules.rules[-1].id)

Describe the data policy which should now show just the first rule#

[ ]:
rules = sess.describe_data_policy(policy_id)
rules
[ ]: