Skip to content

Commit bfba727

Browse files
authored
Merge pull request #93 from didx-xyz/feat/0.8.1
Feat/0.8.1
2 parents 0e8c2b9 + 1703488 commit bfba727

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+427
-99
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,14 @@ Each Cloud Controller version maps to a specific ACA-Py version, which is outlin
4747
| 0.6.0-0.6.3 | 0.7.4 |
4848
| 0.7.0 | 0.7.5 |
4949
| 0.8.0 | 0.8.0 |
50+
| 0.8.1 | 0.8.1 |
5051

5152
## Features
5253

5354
Aries Cloud Controller Python is a fully featured client for interacting with ACA-Py.
5455

5556
- Fully Typed wrapper around Aries Cloud Agent Python
56-
- Supports latest ACA-Py version (0.8.0)
57+
- Supports latest ACA-Py version (0.8.1)
5758
- Client is auto generated based on OpenAPI definitions, allowing us to keep up to date with new releases.
5859
- Supports multi-tenant APIs and authentication
5960
- Async API
Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
from typing import Optional
2+
23
from aiohttp.client import ClientSession
34

45
from aries_cloudcontroller.client import Client
6+
from aries_cloudcontroller.util.acapy_client_session import AcaPyClientSession
57
from aries_cloudcontroller.util.pydantic_converter import PydanticConverter
68

79

@@ -10,30 +12,42 @@ def __init__(
1012
self,
1113
base_url: str,
1214
*,
15+
client_session: Optional[ClientSession] = None,
1316
api_key: Optional[str] = None,
1417
admin_insecure: Optional[bool] = False,
1518
tenant_jwt: Optional[str] = None,
1619
):
20+
self.base_url = base_url
21+
22+
self._should_close_session = False # only close ClientSession when created here
23+
# A provided ClientSession should be closed externally.
24+
25+
if client_session and not api_key:
26+
api_key = client_session.headers.get("x-api-key")
27+
1728
if not api_key and not admin_insecure:
1829
raise Exception(
1930
"api_key property is missing. Use admin_insecure=True if you want"
2031
" to use the controller without authentication."
2132
)
2233

23-
headers = {}
24-
25-
if api_key:
26-
headers["x-api-key"] = api_key
27-
if tenant_jwt:
28-
headers["authorization"] = f"Bearer {tenant_jwt}"
29-
30-
client_session = ClientSession(
31-
headers=headers,
32-
raise_for_status=True,
33-
)
34+
if not client_session:
35+
self.client_session = AcaPyClientSession(
36+
api_key=api_key, tenant_jwt=tenant_jwt
37+
).client_session
38+
self._should_close_session = True
39+
else:
40+
self.client_session = client_session
3441

3542
super().__init__(
36-
base_url,
37-
client=client_session,
43+
self.base_url,
44+
client=self.client_session,
3845
extra_service_params={"converter": PydanticConverter()},
3946
)
47+
48+
async def __aenter__(self):
49+
return self
50+
51+
async def __aexit__(self, exc_type, exc_value, traceback):
52+
if self._should_close_session and not self.client_session.closed:
53+
await self.client_session.close()

aries_cloudcontroller/api/action_menu.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ async def perform_action(
3939
self, *, conn_id: str, body: Optional[PerformRequest] = None
4040
) -> Dict[str, Any]:
4141
"""Perform an action associated with the active menu"""
42+
if not body:
43+
body = PerformRequest()
4244
return await self.__perform_action(
4345
conn_id=conn_id,
4446
body=body,
@@ -54,6 +56,8 @@ async def send_menu(
5456
self, *, conn_id: str, body: Optional[SendMenu] = None
5557
) -> Dict[str, Any]:
5658
"""Send an action menu to a connection"""
59+
if not body:
60+
body = SendMenu()
5761
return await self.__send_menu(
5862
conn_id=conn_id,
5963
body=body,

aries_cloudcontroller/api/basicmessage.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ async def send_message(
2525
self, *, conn_id: str, body: Optional[SendMessage] = None
2626
) -> Dict[str, Any]:
2727
"""Send a basic message to a connection"""
28+
if not body:
29+
body = SendMessage()
2830
return await self.__send_message(
2931
conn_id=conn_id,
3032
body=body,

aries_cloudcontroller/api/connection.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ async def create_invitation(
7373
body: Optional[CreateInvitationRequest] = None
7474
) -> InvitationResult:
7575
"""Create a new connection invitation"""
76+
if not body:
77+
body = CreateInvitationRequest()
7678
return await self.__create_invitation(
7779
alias=alias,
7880
auto_accept=bool_query(auto_accept),
@@ -85,6 +87,8 @@ async def create_static_connection(
8587
self, *, body: Optional[ConnectionStaticRequest] = None
8688
) -> ConnectionStaticResult:
8789
"""Create a new static connection"""
90+
if not body:
91+
body = ConnectionStaticRequest()
8892
return await self.__create_static_connection(
8993
body=body,
9094
)
@@ -158,6 +162,8 @@ async def receive_invitation(
158162
body: Optional[ReceiveInvitationRequest] = None
159163
) -> ConnRecord:
160164
"""Receive a new connection invitation"""
165+
if not body:
166+
body = ReceiveInvitationRequest()
161167
return await self.__receive_invitation(
162168
alias=alias,
163169
auto_accept=bool_query(auto_accept),
@@ -169,6 +175,8 @@ async def set_metadata(
169175
self, *, conn_id: str, body: Optional[ConnectionMetadataSetRequest] = None
170176
) -> ConnectionMetadata:
171177
"""Set connection metadata"""
178+
if not body:
179+
body = ConnectionMetadataSetRequest()
172180
return await self.__set_metadata(
173181
conn_id=conn_id,
174182
body=body,

aries_cloudcontroller/api/credential_definition.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ async def publish_cred_def(
7474
body: Optional[CredentialDefinitionSendRequest] = None
7575
) -> TxnOrCredentialDefinitionSendResult:
7676
"""Sends a credential definition to the ledger"""
77+
if not body:
78+
body = CredentialDefinitionSendRequest()
7779
return await self.__publish_cred_def(
7880
conn_id=conn_id,
7981
create_transaction_for_endorser=bool_query(create_transaction_for_endorser),

aries_cloudcontroller/api/credentials.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ async def get_w3c_credentials(
100100
body: Optional[W3CCredentialsListRequest] = None
101101
) -> VCRecordList:
102102
"""Fetch W3C credentials from wallet"""
103+
if not body:
104+
body = W3CCredentialsListRequest()
103105
return await self.__get_w3c_credentials(
104106
count=count,
105107
start=start,

aries_cloudcontroller/api/did_exchange.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ async def receive_request(
8080
body: Optional[DIDXRequest] = None
8181
) -> ConnRecord:
8282
"""Receive request against public DID's implicit invitation"""
83+
if not body:
84+
body = DIDXRequest()
8385
return await self.__receive_request(
8486
alias=alias,
8587
auto_accept=bool_query(auto_accept),

aries_cloudcontroller/api/endorse_transaction.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ async def create_request(
3939
body: Optional[Date] = None
4040
) -> TransactionRecord:
4141
"""For author to send a transaction request"""
42+
if not body:
43+
body = Date()
4244
return await self.__create_request(
4345
tran_id=tran_id,
4446
endorser_write_txn=bool_query(endorser_write_txn),

aries_cloudcontroller/api/issue_credential_v1_0.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ async def create_credential(
5353
self, *, body: Optional[V10CredentialCreate] = None
5454
) -> V10CredentialExchange:
5555
"""Create a credential record without sending (generally for use with Out-Of-Band)"""
56+
if not body:
57+
body = V10CredentialCreate()
5658
return await self.__create_credential(
5759
body=body,
5860
)
@@ -61,6 +63,8 @@ async def create_offer(
6163
self, *, body: Optional[V10CredentialConnFreeOfferRequest] = None
6264
) -> V10CredentialExchange:
6365
"""Create a credential offer, independent of any proposal or connection"""
66+
if not body:
67+
body = V10CredentialConnFreeOfferRequest()
6468
return await self.__create_offer(
6569
body=body,
6670
)
@@ -97,6 +101,8 @@ async def issue_credential(
97101
self, *, cred_ex_id: str, body: Optional[V10CredentialIssueRequest] = None
98102
) -> V10CredentialExchange:
99103
"""Send holder a credential"""
104+
if not body:
105+
body = V10CredentialIssueRequest()
100106
return await self.__issue_credential(
101107
cred_ex_id=cred_ex_id,
102108
body=body,
@@ -106,6 +112,8 @@ async def issue_credential_automated(
106112
self, *, body: Optional[V10CredentialProposalRequestMand] = None
107113
) -> V10CredentialExchange:
108114
"""Send holder a credential, automating entire flow"""
115+
if not body:
116+
body = V10CredentialProposalRequestMand()
109117
return await self.__issue_credential_automated(
110118
body=body,
111119
)
@@ -117,6 +125,8 @@ async def report_problem(
117125
body: Optional[V10CredentialProblemReportRequest] = None
118126
) -> Dict[str, Any]:
119127
"""Send a problem report for credential exchange"""
128+
if not body:
129+
body = V10CredentialProblemReportRequest()
120130
return await self.__report_problem(
121131
cred_ex_id=cred_ex_id,
122132
body=body,
@@ -126,6 +136,8 @@ async def send_offer(
126136
self, *, cred_ex_id: str, body: Optional[V10CredentialBoundOfferRequest] = None
127137
) -> V10CredentialExchange:
128138
"""Send holder a credential offer in reference to a proposal with preview"""
139+
if not body:
140+
body = V10CredentialBoundOfferRequest()
129141
return await self.__send_offer(
130142
cred_ex_id=cred_ex_id,
131143
body=body,
@@ -135,6 +147,8 @@ async def send_offer_free(
135147
self, *, body: Optional[V10CredentialFreeOfferRequest] = None
136148
) -> V10CredentialExchange:
137149
"""Send holder a credential offer, independent of any proposal"""
150+
if not body:
151+
body = V10CredentialFreeOfferRequest()
138152
return await self.__send_offer_free(
139153
body=body,
140154
)
@@ -143,6 +157,8 @@ async def send_proposal(
143157
self, *, body: Optional[V10CredentialProposalRequestOpt] = None
144158
) -> V10CredentialExchange:
145159
"""Send issuer a credential proposal"""
160+
if not body:
161+
body = V10CredentialProposalRequestOpt()
146162
return await self.__send_proposal(
147163
body=body,
148164
)
@@ -157,6 +173,8 @@ async def store_credential(
157173
self, *, cred_ex_id: str, body: Optional[V10CredentialStoreRequest] = None
158174
) -> V10CredentialExchange:
159175
"""Store a received credential"""
176+
if not body:
177+
body = V10CredentialStoreRequest()
160178
return await self.__store_credential(
161179
cred_ex_id=cred_ex_id,
162180
body=body,

0 commit comments

Comments
 (0)