Skip to content

Commit

Permalink
Merge branch 'main' into per_tenant_settings
Browse files Browse the repository at this point in the history
  • Loading branch information
swcurran authored May 30, 2023
2 parents d65ac6d + a324357 commit 0d73bd8
Show file tree
Hide file tree
Showing 5 changed files with 24,015 additions and 9,414 deletions.
18 changes: 9 additions & 9 deletions UsingOpenAPI.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

ACA-Py provides an OpenAPI-documented REST interface for administering the agent's internal state and initiating communication with connected agents.

The running agent provides a `Swagger User Interface` that can be browsed and used to test various scenarios manually (see the [Admin API Readme](AdminApi.md) for details). However, it is often desirable to produce native language interfaces rather than coding `Controllers` using HTTP primitives. This is possible using several public code generation (codegen) tools. This page provides some suggestions based on experience with these tools when trying to generate `Typescript` wrappers. The information should be useful to those trying to generate other languages. Updates to this page based on experience are encouraged.
The running agent provides a `Swagger User Interface` that can be browsed and used to test various scenarios manually (see the [Admin API Readme](AdminAPI.md) for details). However, it is often desirable to produce native language interfaces rather than coding `Controllers` using HTTP primitives. This is possible using several public code generation (codegen) tools. This page provides some suggestions based on experience with these tools when trying to generate `Typescript` wrappers. The information should be useful to those trying to generate other languages. Updates to this page based on experience are encouraged.

## ACA-Py, OpenAPI Raw Output Characteristics

ACA-Py uses [aiohttp_apispec](https://github.com/maximdanilchenko/aiohttp-apispec) tags in code to produce the OpenAPI spec file at runtime dependent on what features have been loaded. How these tags are created is documented in the [API Standard Behaviour](https://github.com/hyperledger/aries-cloudagent-python/blob/main/AdminAPI.md#api-standard-behaviour) section of the [Admin API Readme](AdminApi.md). The OpenAPI spec is available in raw, unformatted form from a running ACA-Py instance using a route of `http://<acapy host and port>/api/docs/swagger.json` or from the browser `Swagger User Interface` directly.
ACA-Py uses [aiohttp_apispec](https://github.com/maximdanilchenko/aiohttp-apispec) tags in code to produce the OpenAPI spec file at runtime dependent on what features have been loaded. How these tags are created is documented in the [API Standard Behaviour](https://github.com/hyperledger/aries-cloudagent-python/blob/main/AdminAPI.md#api-standard-behaviour) section of the [Admin API Readme](AdminAPI.md). The OpenAPI spec is available in raw, unformatted form from a running ACA-Py instance using a route of `http://<acapy host and port>/api/docs/swagger.json` or from the browser `Swagger User Interface` directly.

To help identify changes in the ACA-Py Admin API over releases, there is a tool that can be run located at `scripts/generate-open-api-spec`. This tool will start ACA-Py, pull the `swagger.json` file, run a codegen tool, and specify a language output of `json`. Apart from providing a better format to compare changes (i.e., by comparing this output to the checked-in `open-api/openapi.json` version), the tool can be used to identify any non-conformance to the OpenAPI specification. At the moment, `validation` is turned off via the `open-api/openAPIJSON.config` file, so warning messages are printed for non-conformance, but the `json` is still output. Most of the warnings reported by `generate-open-api-spec` relate to missing `operationId` fields which results in manufactured method names being created by codegen tools. At the moment, [aiohttp_apispec](https://github.com/maximdanilchenko/aiohttp-apispec) does not support adding `operationId` annotations via tags.
The ACA-Py Admin API evolves across releases. To track these changes and ensure conformance with the OpenAPI specification, we provide a tool located at [`scripts/generate-open-api-spec`](scripts/generate-open-api-spec). This tool starts ACA-Py, retrieves the `swagger.json` file, and runs codegen tools to generate specifications in both Swagger and OpenAPI formats with `json` language output. The output of this tool enables comparison with the checked-in `open-api/swagger.json` and `open-api/openapi.json`, and also serves as a useful resource for identifying any non-conformance to the OpenAPI specification. At the moment, `validation` is turned off via the `open-api/openAPIJSON.config` file, so warning messages are printed for non-conformance, but the `json` is still output. Most of the warnings reported by `generate-open-api-spec` relate to missing `operationId` fields which results in manufactured method names being created by codegen tools. At the moment, [aiohttp_apispec](https://github.com/maximdanilchenko/aiohttp-apispec) does not support adding `operationId` annotations via tags.

The `generate-open-api-spec` tool was initially created to help identify issues with method parameters not being sorted, resulting in somewhat random ordering each time a codegen operation was performed. This is relevant for languages which do not have support for [named parameters](https://en.wikipedia.org/wiki/Named_parameter) such as `Javascript`. It is recommended that the `generate-open-api-spec` is run prior to each release, and the resulting `open-api/openapi.json` file checked in to allow tracking of API changes over time. At the moment, this process is not automated as part of the release pipeline.

Expand All @@ -30,15 +30,15 @@ Another suggestion for code generation is to keep the `modelPropertyNaming` set

### Python

- [aries-cloudcontroller (PyPI)](https://pypi.org/project/aries-cloudcontroller/)
- [aries-cloudcontroller-python (GitHub)](https://github.com/didx-xyz/aries-cloudcontroller-python)
- [traction (GitHub)](https://github.com/bcgov/traction/tree/develop/services/traction/acapy_client)
- [acapy-client (GitHub)](https://github.com/Indicio-tech/acapy-client)
- [Aries Cloud Controller Python (GitHub / didx-xyz)](https://github.com/didx-xyz/aries-cloudcontroller-python)
- [Aries Cloud Controller (PyPi)](https://pypi.org/project/aries-cloudcontroller/)
- [Traction (GitHub / bcgov)](https://github.com/bcgov/traction)
- [acapy-client (GitHub / Indicio-tech)](https://github.com/Indicio-tech/acapy-client)

### Go

- [go-acapy-client (GitHub)](https://github.com/ldej/go-acapy-client)
- [go-acapy-client (GitHub / Idej)](https://github.com/ldej/go-acapy-client)

### Java

- [acapy-java-client (GitHub)](https://github.com/hyperledger-labs/acapy-java-client)
- [ACA-Py Java Client Library (GitHub / hyperledger-labs)](https://github.com/hyperledger-labs/acapy-java-client)
16 changes: 13 additions & 3 deletions demo/runners/support/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,7 @@ def get_agent_args(self):
"--preserve-exchange-records",
"--auto-provision",
"--public-invites",
# ("--log-level", "debug"),
]
if self.aip == 20:
result.append("--emit-new-didcomm-prefix")
Expand Down Expand Up @@ -844,6 +845,10 @@ async def handle_revocation_registry(self, message):
async def handle_mediation(self, message):
self.log(f"Received mediation message ...\n")

async def handle_keylist(self, message):
self.log(f"Received handle_keylist message ...\n")
self.log(json.dumps(message))

async def taa_accept(self):
taa_info = await self.admin_GET("/ledger/taa")
if taa_info["result"]["taa_required"]:
Expand Down Expand Up @@ -1215,6 +1220,8 @@ async def get_invite(
"handshake_protocols": ["rfc23"],
"use_public_did": reuse_connections,
}
if self.mediation:
payload["mediation_id"] = self.mediator_request_id
invi_rec = await self.admin_POST(
"/out-of-band/create-invitation",
payload,
Expand All @@ -1225,9 +1232,10 @@ async def get_invite(
invi_params = {
"auto_accept": json.dumps(auto_accept),
}
payload = {"mediation_id": self.mediator_request_id}
invi_rec = await self.admin_POST(
"/connections/create-invitation",
{"mediation_id": self.mediator_request_id},
payload,
params=invi_params,
)
else:
Expand All @@ -1240,6 +1248,8 @@ async def receive_invite(self, invite, auto_accept: bool = True):
params = {"alias": "endorser"}
else:
params = {}
if self.mediation:
params["mediation_id"] = self.mediator_request_id
if "/out-of-band/" in invite.get("@type", ""):
# always reuse connections if possible
params["use_existing_connection"] = "true"
Expand Down Expand Up @@ -1337,12 +1347,12 @@ async def connect_wallet_to_mediator(agent, mediator_agent):
log_msg("Connected agent to mediator:", agent.ident, mediator_agent.ident)

# setup mediation on our connection
log_msg("Request mediation ...")
log_msg(f"Request mediation on connection {agent.mediator_connection_id} ...")
mediation_request = await agent.admin_POST(
"/mediation/request/" + agent.mediator_connection_id, {}
)
agent.mediator_request_id = mediation_request["mediation_id"]
log_msg("Mediation request id:", agent.mediator_request_id)
log_msg(f"Mediation request id: {agent.mediator_request_id}")

count = 3
while 0 < count:
Expand Down
Loading

0 comments on commit 0d73bd8

Please sign in to comment.