Skip to content

Commit d8e414c

Browse files
committed
Merge branch 'main' into issue_18/prob_report_endpoints
2 parents 0c3cbc6 + 7501498 commit d8e414c

File tree

11 files changed

+386
-42
lines changed

11 files changed

+386
-42
lines changed

.github/workflows/main.yml renamed to .github/workflows/create-release-changelog.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
name: 'CI'
1+
name: 'Create release and changelog'
22
on:
33
release:
44
types: [created]
55

66
jobs:
77
release:
8-
if: startsWith(github.ref, 'refs/tags/')
8+
if: ${{ startsWith(github.ref, 'refs/tags/') && github.event.base_ref == 'refs/heads/main' }}
99
runs-on: ubuntu-latest
1010
steps:
1111
- name: Build Changelog

.github/workflows/lint-black.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: 'Run black linting'
2+
3+
on:
4+
# Trigger the workflow on push or pull request,
5+
# but only for the main branch
6+
push:
7+
branches:
8+
- main
9+
pull_request:
10+
branches:
11+
- main
12+
13+
jobs:
14+
PythonLinting:
15+
name: Python linting
16+
runs-on: ubuntu-latest
17+
steps:
18+
- uses: actions/checkout@master
19+
- name: Black Python linting
20+
uses: lgeiger/black-action@master
21+
with:
22+
args: . --check

.github/workflows/python-publish.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,8 @@ on:
99

1010
jobs:
1111
deploy:
12-
12+
if: ${{ startsWith(github.ref, 'refs/tags/') && github.event.base_ref == 'refs/heads/main' }}
1313
runs-on: ubuntu-latest
14-
1514
steps:
1615
- uses: actions/checkout@v2
1716
- name: Set up Python

.github/workflows/run-py-tests.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: Run Python Tests
2+
on:
3+
pull_request:
4+
branches:
5+
- staging
6+
- main
7+
8+
jobs:
9+
RunPytest:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v2
13+
- name: Install Python 3
14+
uses: actions/setup-python@v1
15+
with:
16+
python-version: 3.7
17+
- name: Install dependencies
18+
run: |
19+
python -m pip install --upgrade pip
20+
pip install -r requirements.txt
21+
- name: Run tests with pytest
22+
run: pytest

aries_cloudcontroller/aries_controller.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from .controllers.multitenant import MultitenancyController
66

77
import logging
8+
import ipaddress
89

910
logger = logging.getLogger("aries_controller")
1011

@@ -36,35 +37,34 @@ def __post_init__(self):
3637
self.admin_url, self.client_session
3738
)
3839

39-
def init_webhook_server(
40-
self, webhook_host: str = None, webhook_port: int = None, webhook_base: str = ""
40+
async def init_webhook_server(
41+
self, webhook_host: str, webhook_port: int, webhook_base: str = ""
4142
):
42-
"""Create a webhooklisteners
43+
"""Create a webhook listeners
4344
4445
Args:
4546
----
4647
webhook_host : str
47-
The url of the webhook host (default is None)
48+
The url of the webhook host
4849
webhook_port : int
49-
The exposed port for webhooks on the host (default is None)
50+
The exposed port for webhooks on the host
5051
webhook_base : str
5152
The base url for webhooks (default is "")
5253
"""
53-
self.webhook_server: AriesWebhookServer = AriesWebhookServer(
54-
webhook_host=webhook_host,
55-
webhook_port=webhook_port,
56-
webhook_base=webhook_base,
57-
is_multitenant=self.is_multitenant,
58-
)
59-
60-
async def listen_webhooks(self):
54+
assert type(webhook_host) is str
55+
assert ipaddress.ip_address(webhook_host)
56+
assert type(webhook_port) is int
6157
try:
58+
self.webhook_server: AriesWebhookServer = AriesWebhookServer(
59+
webhook_host=webhook_host,
60+
webhook_port=webhook_port,
61+
webhook_base=webhook_base,
62+
is_multitenant=self.is_multitenant,
63+
)
6264
await self.webhook_server.listen_webhooks()
63-
logger.info("Webhook server started.")
64-
except AttributeError:
65-
warning = "Webhook server not initialised."
66-
logger.warning(warning)
67-
raise AttributeError(warning)
65+
logger.info(
66+
f"Webhook server started on {self.webhook_server.webhook_host}."
67+
)
6868
except Exception as exc:
69-
logger.warning(f"Listening webhooks failed! {exc!r} occurred.")
69+
logger.error(f"Listening webhooks failed! {exc!r} occurred.")
7070
raise Exception(f"{exc!r}")

aries_cloudcontroller/controllers/issuer.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,10 @@ async def issue_credential(self, cred_ex_id, comment, attributes):
141141
raise e(exc_msg)
142142

143143
# Store a received credential
144-
async def store_credential(self, cred_ex_id, credential_id):
145-
body = {"credential_id": credential_id}
144+
async def store_credential(self, cred_ex_id, credential_id: str = None):
145+
body = {}
146+
if credential_id:
147+
body["credential_id"] = credential_id
146148
return await self.admin_POST(
147149
f"{self.base_url}/records/{cred_ex_id}/store", json_data=body
148150
)

aries_cloudcontroller/controllers/messaging.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,13 @@ async def send_message(self, connection_id, msg):
2121
)
2222
return response
2323

24-
async def trust_ping(self, connection_id: str, msg: str):
25-
response = await self.admin_POST(
26-
f"/connections/{connection_id}/send-ping", {"content": msg}
27-
)
24+
async def trust_ping(self, connection_id: str, comment_msg: str = None):
25+
if comment_msg:
26+
response = await self.admin_POST(
27+
f"/connections/{connection_id}/send-ping", {"comment": comment_msg}
28+
)
29+
else:
30+
response = await self.admin_POST(
31+
f"/connections/{connection_id}/send-ping", {}
32+
)
2833
return response
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import json
2+
import logging
3+
4+
logger = logging.getLogger("aries_controller.models.proof_request")
5+
6+
7+
class ProofRequest:
8+
def __init__(self, proof_request_json):
9+
try:
10+
self.json_data = json.loads(proof_request_json)
11+
except Exception:
12+
logger.error("Failed to load proof request JSON")
13+
raise
14+
self.validate_proof_request_json(proof_request_json)
15+
16+
def get_requested_attributes(self):
17+
return self.json_data["requested_attributes"]
18+
19+
def get_requested_predicates(self):
20+
return self.json_data["requested_predicates"]
21+
22+
def get_connection_id(self):
23+
return self.json_data["connection_id"]
24+
25+
def get_version(self):
26+
return self.json_data["version"]
27+
28+
def get_name(self):
29+
return self.json_data["name"]
30+
31+
def validate_proof_request_json(self, presentation_json):
32+
try:
33+
# Taken from sample response in swagger UI
34+
# TODO Determine whether this is the minimal set of keys
35+
presentation_keys = [
36+
"connection_id",
37+
"version",
38+
"name",
39+
"requested_attributes",
40+
"requested_predicates",
41+
]
42+
for key in presentation_keys:
43+
assert key in json.loads(
44+
presentation_json
45+
), f"Invalid proof request. Missing key {key}"
46+
except AssertionError:
47+
raise

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
aiohttp~=3.7.3
22
asyncio
3+
black
34
prompt_toolkit
45
pygments
56
PyPubSub

0 commit comments

Comments
 (0)