Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for notifications API in KERIA #63

Merged
merged 1 commit into from
Aug 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion scripts/create_person_aid.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def create_aid():
oobis = client.oobis()

aids = identifiers.list()
assert aids == []
assert aids['aids'] == []

wits = [
"BBilc4-L3tFUnfM_wJr4S4OJanAv_VmF_dJNN6vkf2Ha",
Expand Down
9 changes: 6 additions & 3 deletions scripts/issue-ecr.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,24 @@ kli vc registry incept --name legal-entity --alias legal-entity --registry-name

# Issue QVI credential vLEI from GLEIF External to QVI
kli vc issue --name external --alias external --registry-name vLEI-external --schema EBfdlu8R27Fbx-ehrqwImnK-8Cm79sqbAQ4MmvEAYqao --recipient EHMnCf8_nIemuPx-cUHaDQq8zSnQIFAurdEpwHpNbnvX --data @"${KERI_DEMO_SCRIPT_DIR}"/data/qvi-data.json
kli vc list --name qvi --alias qvi --poll
kli vc accept --name qvi --alias qvi --poll --auto
kli vc list --name qvi --alias qvi

# Issue LE credential from QVI to Legal Entity - have to create the edges first
QVI_SAID=$(kli vc list --name qvi --alias qvi --said --schema EBfdlu8R27Fbx-ehrqwImnK-8Cm79sqbAQ4MmvEAYqao)
echo \"$QVI_SAID\" | jq -f "${KERI_DEMO_SCRIPT_DIR}"/data/legal-entity-edges-filter.jq > /tmp/legal-entity-edges.json
kli saidify --file /tmp/legal-entity-edges.json
kli vc issue --name qvi --alias qvi --registry-name vLEI-qvi --schema ENPXp1vQzRF6JwIuS-mp2U8Uf1MoADoP_GqQ62VsDZWY --recipient EIitNxxiNFXC1HDcPygyfyv3KUlBfS_Zf-ZYOvwjpTuz --data @"${KERI_DEMO_SCRIPT_DIR}"/data/legal-entity-data.json --edges @/tmp/legal-entity-edges.json --rules @"${KERI_DEMO_SCRIPT_DIR}"/data/rules.json
kli vc list --name legal-entity --alias legal-entity --poll
kli vc accept --name legal-entity --alias legal-entity --poll --auto
kli vc list --name legal-entity --alias legal-entity

# Issue ECR Authorization credential from Legal Entity to QVI - have to create the edges first
LE_SAID=$(kli vc list --name legal-entity --alias legal-entity --said)
echo \"$LE_SAID\" | jq -f "${KERI_DEMO_SCRIPT_DIR}"/data/ecr-auth-edges-filter.jq > /tmp/ecr-auth-edges.json
kli saidify --file /tmp/ecr-auth-edges.json
kli vc issue --name legal-entity --alias legal-entity --registry-name vLEI-legal-entity --schema EH6ekLjSr8V32WyFbGe1zXjTzFs9PkTYmupJ9H65O14g --recipient EHMnCf8_nIemuPx-cUHaDQq8zSnQIFAurdEpwHpNbnvX --data @"${KERI_DEMO_SCRIPT_DIR}"/data/ecr-auth-data.json --edges @/tmp/ecr-auth-edges.json --rules @"${KERI_DEMO_SCRIPT_DIR}"/data/ecr-auth-rules.json
kli vc list --name qvi --alias qvi --poll
kli vc accept --name qvi --alias qvi --poll --auto
kli vc list --name qvi --alias qvi

# Issue ECR credential from QVI to Person
AUTH_SAID=$(kli vc list --name qvi --alias qvi --said --schema EH6ekLjSr8V32WyFbGe1zXjTzFs9PkTYmupJ9H65O14g)
Expand Down
2 changes: 1 addition & 1 deletion src/signify/app/aiding.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def list(self, start=0, end=24):
res = self.client.get(f"/identifiers", headers=headers)

cr = res.headers["content-range"]
start, end, total = httping.parseRangeHeader(cr)
start, end, total = httping.parseRangeHeader(cr, "aids")

return dict(start=start, end=end, total=total, aids=res.json())

Expand Down
4 changes: 4 additions & 0 deletions src/signify/app/clienting.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,10 @@ def endroles(self):
from signify.app.ending import EndRoleAuthorizations
return EndRoleAuthorizations(client=self)

def notifications(self):
from signify.app.notifying import Notifications
return Notifications(client=self)

@staticmethod
def raiseForStatus(res):
try:
Expand Down
59 changes: 59 additions & 0 deletions src/signify/app/notifying.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# -*- encoding: utf-8 -*-
"""
SIGNIFY
signify.app.notifying module

"""
from signify.app.clienting import SignifyClient
from signify.core import httping


class Notifications:
""" Domain class for accessing Endpoint Role Authorizations """

def __init__(self, client: SignifyClient):
self.client = client

def list(self, start=0, end=24):
""" Returns list of notifications

Parameters:
start (int): start index of list of notifications, defaults to 0
end (int): end index of list of notifications, defaults to 24

Returns:
dict: data with start, end, total and notes of list result

"""
headers = dict(Range=f"notes={start}-{end}")
res = self.client.get(f"/notifications", headers=headers)
cr = res.headers["content-range"]
start, end, total = httping.parseRangeHeader(cr, "notes")

return dict(start=start, end=end, total=total, notes=res.json())

def markAsRead(self, nid):
""" Mark notification as read

Parameters:
nid (str): qb64 SAID of notification to mark as read

Returns:
bool: True means notification marked as read

"""
res = self.client.put(f"/notifications/{nid}", json={})
return res.status == 202

def delete(self, nid):
""" Delete notification

Parameters:
nid(str): qb64 SAID of notification to delete

Returns:
bool: True means notification deleted

"""
res = self.client.delete(path=f"/notifications/{nid}")
return res.status == 202
7 changes: 4 additions & 3 deletions src/signify/core/httping.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
# -*- encoding: utf-8 -*-
from typing import Tuple
"""
SignifyPy
signify.core.httping module

"""
from typing import Tuple


def parseRangeHeader(header: str) -> Tuple[int, int, int]:
def parseRangeHeader(header: str, typ: str) -> Tuple[int, int, int]:
""" Parse start, end and total from HTTP Content-Range header value

Parameters:
header (str): HTTP Content-Range header value
typ (str): Type in range header

Returns: Tuple[int, int int]

"""
data = header.lstrip("aids ")
data = header.lstrip(f"{typ} ")

values = data.split("/")
rng = values[0].split("-")
Expand Down
Loading
Loading