-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmulti_scope_delegation.py
More file actions
34 lines (27 loc) · 1008 Bytes
/
multi_scope_delegation.py
File metadata and controls
34 lines (27 loc) · 1008 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/usr/bin/env python3
"""Issue one receipt with multiple categories and an optional spend cap."""
from datetime import timedelta
from agentveil import AVPAgent
owner = AVPAgent.create(mock=True, name="workflow-owner")
agent = AVPAgent.create(mock=True, name="release-agent")
receipt = owner.issue_delegation_receipt(
agent_did=agent.did,
allowed_categories=["deploy", "infrastructure"],
max_spend={"currency": "USD", "amount": 250},
valid_for=timedelta(minutes=45),
purpose="Deploy service changes and inspect infrastructure resources",
)
verification = agent.verify_delegation_receipt(receipt)
categories = [
entry["value"]
for entry in verification["scope"]
if entry["predicate"] == "allowed_category"
]
spend_caps = [
entry
for entry in verification["scope"]
if entry["predicate"] == "max_spend"
]
print("valid:", verification["valid"])
print("categories:", ", ".join(categories))
print("max_spend:", spend_caps[0]["currency"], spend_caps[0]["amount"])