-
Notifications
You must be signed in to change notification settings - Fork 8
/
credentials.py
203 lines (167 loc) · 6.81 KB
/
credentials.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
from typing import Optional
from aries_cloudcontroller import (
AttributeMimeTypesResult,
CredInfoList,
CredRevokedResult,
IndyCredInfo,
VCRecord,
VCRecordList,
W3CCredentialsListRequest,
)
from fastapi import APIRouter, Depends
from app.dependencies.acapy_clients import client_from_auth
from app.dependencies.auth import AcaPyAuth, acapy_auth
from app.exceptions import handle_acapy_call
from shared.log_config import get_logger
logger = get_logger(__name__)
router = APIRouter(prefix="/v1/wallet/credentials", tags=["wallet"])
@router.get("", response_model=CredInfoList)
async def list_credentials(
count: Optional[str] = None,
start: Optional[str] = None,
wql: Optional[str] = None,
auth: AcaPyAuth = Depends(acapy_auth),
) -> CredInfoList:
"""Fetch a list of credentials from the wallet."""
logger.info("GET request received: List credentials")
async with client_from_auth(auth) as aries_controller:
logger.debug("Fetching credentials")
results = await handle_acapy_call(
logger=logger,
acapy_call=aries_controller.credentials.get_records,
count=count,
start=start,
wql=wql,
)
logger.info("Successfully listed credentials.")
return results
@router.get("/{credential_id}", response_model=IndyCredInfo)
async def get_credential_record(
credential_id: str,
auth: AcaPyAuth = Depends(acapy_auth),
) -> IndyCredInfo:
"""Fetch a specific credential by ID."""
bound_logger = logger.bind(credential_id=credential_id)
bound_logger.info("GET request received: Fetch specific credential by ID")
async with client_from_auth(auth) as aries_controller:
bound_logger.debug("Fetching credential")
result = await handle_acapy_call(
logger=bound_logger,
acapy_call=aries_controller.credentials.get_record,
credential_id=credential_id,
)
bound_logger.info("Successfully fetched credential.")
return result
@router.delete("/{credential_id}", status_code=204)
async def delete_credential(
credential_id: str,
auth: AcaPyAuth = Depends(acapy_auth),
) -> None:
"""Remove a specific credential from the wallet by ID."""
bound_logger = logger.bind(credential_id=credential_id)
bound_logger.info("DELETE request received: Remove specific credential by ID")
async with client_from_auth(auth) as aries_controller:
bound_logger.debug("Deleting credential")
await handle_acapy_call(
logger=bound_logger,
acapy_call=aries_controller.credentials.delete_record,
credential_id=credential_id,
)
bound_logger.info("Successfully deleted credential.")
@router.get("/{credential_id}/mime-types", response_model=AttributeMimeTypesResult)
async def get_credential_mime_types(
credential_id: str,
auth: AcaPyAuth = Depends(acapy_auth),
) -> AttributeMimeTypesResult:
"""Retrieve attribute MIME types of a specific credential by ID."""
bound_logger = logger.bind(credential_id=credential_id)
bound_logger.info(
"GET request received: Retrieve attribute MIME types for a specific credential"
)
async with client_from_auth(auth) as aries_controller:
bound_logger.debug("Fetching MIME types")
result = await handle_acapy_call(
logger=bound_logger,
acapy_call=aries_controller.credentials.get_credential_mime_types,
credential_id=credential_id,
)
bound_logger.info("Successfully fetched attribute MIME types.")
return result
@router.get("/{credential_id}/revocation-status", response_model=CredRevokedResult)
async def get_credential_revocation_status(
credential_id: str,
from_: Optional[str] = None,
to: Optional[str] = None,
auth: AcaPyAuth = Depends(acapy_auth),
) -> CredRevokedResult:
"""Query the revocation status of a specific credential by ID."""
bound_logger = logger.bind(credential_id=credential_id)
bound_logger.info(
"GET request received: Query revocation status for a specific credential"
)
async with client_from_auth(auth) as aries_controller:
bound_logger.debug("Fetching revocation status")
result = await handle_acapy_call(
logger=bound_logger,
acapy_call=aries_controller.credentials.get_revocation_status,
credential_id=credential_id,
var_from=from_,
to=to,
)
bound_logger.info("Successfully fetched revocation status.")
return result
@router.get("/w3c", response_model=VCRecordList)
async def list_w3c_credentials(
count: Optional[str] = None,
start: Optional[str] = None,
wql: Optional[str] = None,
body: Optional[W3CCredentialsListRequest] = None,
auth: AcaPyAuth = Depends(acapy_auth),
) -> VCRecordList:
"""Fetch a list of W3C credentials from the wallet."""
logger.info("GET request received: List W3C credentials")
async with client_from_auth(auth) as aries_controller:
logger.debug("Fetching W3C credentials")
results = await handle_acapy_call(
logger=logger,
acapy_call=aries_controller.credentials.get_w3c_credentials,
count=count,
start=start,
wql=wql,
body=body,
)
logger.info("Successfully listed W3C credentials.")
return results
@router.get("/w3c/{credential_id}", response_model=VCRecord)
async def get_w3c_credential(
credential_id: str,
auth: AcaPyAuth = Depends(acapy_auth),
) -> VCRecord:
"""Fetch a specific W3C credential by ID."""
bound_logger = logger.bind(credential_id=credential_id)
bound_logger.info("GET request received: Fetch specific W3C credential by ID")
async with client_from_auth(auth) as aries_controller:
bound_logger.debug("Fetching W3C credential")
result = await handle_acapy_call(
logger=bound_logger,
acapy_call=aries_controller.credentials.get_w3c_credential,
credential_id=credential_id,
)
bound_logger.info("Successfully fetched W3C credential.")
return result
@router.delete("/w3c/{credential_id}", status_code=204)
async def delete_w3c_credential(
credential_id: str,
auth: AcaPyAuth = Depends(acapy_auth),
) -> None:
"""Remove a specific W3C credential from the wallet by ID."""
bound_logger = logger.bind(credential_id=credential_id)
bound_logger.info("DELETE request received: Remove specific W3C credential by ID")
async with client_from_auth(auth) as aries_controller:
bound_logger.debug("Deleting W3C credential")
await handle_acapy_call(
logger=bound_logger,
acapy_call=aries_controller.credentials.delete_w3c_credential,
credential_id=credential_id,
)
bound_logger.info("Successfully deleted W3C credential.")