-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathacapy_clients.py
67 lines (53 loc) · 1.84 KB
/
acapy_clients.py
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
from typing import Union
from aries_cloudcontroller import AcaPyClient
from fastapi import HTTPException
from app.dependencies.auth import AcaPyAuth, AcaPyAuthVerified
from app.dependencies.role import Role
from shared.constants import GOVERNANCE_LABEL
# todo: remove these defaults by migrating relevant methods to endorser service
# and refactoring methods using tenant-admin internally
GOVERNANCE_AUTHED = AcaPyAuthVerified(
role=Role.GOVERNANCE,
token=Role.GOVERNANCE.agent_type.x_api_key,
wallet_id=GOVERNANCE_LABEL,
)
TENANT_ADMIN_AUTHED = AcaPyAuthVerified(
role=Role.TENANT_ADMIN,
token=Role.TENANT_ADMIN.agent_type.x_api_key,
wallet_id="admin",
)
def get_governance_controller(
auth: AcaPyAuthVerified = GOVERNANCE_AUTHED,
) -> AcaPyClient:
return AcaPyClient(
base_url=Role.GOVERNANCE.agent_type.base_url,
api_key=auth.token,
)
def get_tenant_admin_controller(
auth: AcaPyAuthVerified = TENANT_ADMIN_AUTHED,
) -> AcaPyClient:
return AcaPyClient(
base_url=Role.TENANT_ADMIN.agent_type.base_url,
api_key=auth.token,
)
def get_tenant_controller(auth_token: str) -> AcaPyClient:
return AcaPyClient(
base_url=Role.TENANT.agent_type.base_url,
api_key=Role.TENANT.agent_type.x_api_key,
tenant_jwt=auth_token,
)
def client_from_auth(auth: Union[AcaPyAuth, AcaPyAuthVerified]) -> AcaPyClient:
if not auth or not auth.token:
raise HTTPException(403, "Missing authorization key.")
tenant_jwt = None
if auth.role.is_multitenant and not auth.role.is_admin:
tenant_jwt = auth.token
x_api_key = auth.role.agent_type.x_api_key
else:
x_api_key = auth.token
client = AcaPyClient(
base_url=auth.role.agent_type.base_url,
api_key=x_api_key,
tenant_jwt=tenant_jwt,
)
return client