Skip to content

Commit

Permalink
updates for escrow fix, align with kerupy 1.1.17 and #235
Browse files Browse the repository at this point in the history
Signed-off-by: Kevin Griffin <[email protected]>
  • Loading branch information
m00sey committed Jul 8, 2024
1 parent a36a3b6 commit 24664ac
Show file tree
Hide file tree
Showing 11 changed files with 86 additions and 63 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.PHONY: build-keria
build-keria:
@docker buildx build --platform=linux/amd64 --no-cache -f images/keria.dockerfile --tag weboftrust/keria:0.1.3 --tag weboftrust/keria:latest .
@docker buildx build --platform=linux/amd64 --no-cache -f images/keria.dockerfile --tag weboftrust/keria:0.1.4-dev0 --tag weboftrust/keria:latest .

publish-keria:
@docker push weboftrust/keria --all-tags
57 changes: 6 additions & 51 deletions images/keria.dockerfile
Original file line number Diff line number Diff line change
@@ -1,55 +1,10 @@
# Builder stage
FROM python:3.10.13-alpine3.18 as builder
FROM weboftrust/keri:1.1.17

# Install compilation dependencies
RUN apk --no-cache add \
bash \
alpine-sdk \
libffi-dev \
libsodium \
libsodium-dev
WORKDIR /usr/local/var

SHELL ["/bin/bash", "-c"]
RUN mkdir keria
COPY . /usr/local/var/keria

# Install Rust for blake3 dependency build
RUN curl https://sh.rustup.rs -sSf | bash -s -- -y
WORKDIR /usr/local/var/keria

WORKDIR /keria

RUN python -m venv venv
ENV PATH=/keria/venv/bin:${PATH}
RUN pip install --upgrade pip

# Copy in Python dependency files
COPY requirements.txt setup.py ./
# "src/" dir required for installation of dependencies with setup.py
RUN mkdir /keria/src
# Install Python dependencies
RUN . "$HOME/.cargo/env" && \
pip install -r requirements.txt

# Runtime stage
FROM python:3.10.13-alpine3.18

# Install runtime dependencies
RUN apk --no-cache add \
bash \
alpine-sdk \
libsodium-dev

WORKDIR /keria

# Copy over compiled dependencies
COPY --from=builder /keria /keria
# Copy in KERIA source files - enables near instantaneous builds for source only changes
RUN mkdir -p /usr/local/var/keri
ENV KERI_AGENT_CORS=${KERI_AGENT_CORS:-false}
ENV PATH=/keria/venv/bin:${PATH}

EXPOSE 3901
EXPOSE 3902
EXPOSE 3903

COPY src/ src/

ENTRYPOINT ["keria", "start", "--config-file", "demo-witness-oobis", "--config-dir", "./scripts"]
RUN pip install -r requirements.txt
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

setup(
name='keria',
version='0.1.3', # also change in src/keria/__init__.py
version='0.1.4-dev0', # also change in src/keria/__init__.py
license='Apache Software License 2.0',
description='KERIA: KERI Agent in the cloud',
long_description="KERIA: KERI Agent in the cloud.",
Expand Down Expand Up @@ -76,7 +76,7 @@
python_requires='>=3.10.4',
install_requires=[
'hio>=0.6.9',
'keri>=1.1.6',
'keri>=1.1.17',
'mnemonic>=0.20',
'multicommand>=1.0.0',
'falcon>=3.1.0',
Expand Down
2 changes: 1 addition & 1 deletion src/keria/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
main package
"""

__version__ = '0.1.3' # also change in setup.py
__version__ = '0.1.4-dev0' # also change in setup.py

8 changes: 6 additions & 2 deletions src/keria/app/agenting.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,11 +308,12 @@ def __init__(self, hby, rgy, agentHab, agency, caid, **opts):
self.witq = agenting.WitnessInquisitor(hby=self.hby)
self.witPub = agenting.WitnessPublisher(hby=self.hby)
self.witDoer = agenting.WitnessReceiptor(hby=self.hby)
self.submitter = agenting.WitnessReceiptor(hby=self.hby, force=True, tock=5.0)

self.rep = storing.Respondant(hby=hby, cues=self.cues, mbx=Mailboxer(name=self.hby.name, temp=self.hby.temp))

doers = [habbing.HaberyDoer(habery=hby), receiptor, self.witq, self.witPub, self.rep, self.swain,
self.counselor, self.witDoer, *oobiery.doers]
self.counselor, self.witDoer, self.submitter, *oobiery.doers]

signaler = signaling.Signaler()
self.notifier = Notifier(hby=hby, signaler=signaler)
Expand All @@ -336,7 +337,7 @@ def __init__(self, hby, rgy, agentHab, agency, caid, **opts):
grouping.loadHandlers(exc=self.exc, mux=self.mux)
protocoling.loadHandlers(hby=self.hby, exc=self.exc, notifier=self.notifier)
self.monitor = longrunning.Monitor(hby=hby, swain=self.swain, counselor=self.counselor, temp=hby.temp,
registrar=self.registrar, credentialer=self.credentialer, exchanger=self.exc)
registrar=self.registrar, credentialer=self.credentialer, exchanger=self.exc, submitter=self.submitter)

self.rvy = routing.Revery(db=hby.db, cues=self.cues)
self.kvy = eventing.Kevery(db=hby.db,
Expand Down Expand Up @@ -405,6 +406,9 @@ def inceptExtern(self, pre, verfers, digers, **kwargs):

self.agency.incept(self.caid, pre)

def witnessResubmit(self, pre):
self.submitDoer.msgs.append(dict(pre=pre))


class ParserDoer(doing.Doer):

Expand Down
30 changes: 30 additions & 0 deletions src/keria/app/aiding.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ def loadEnds(app, agency, authn):

aidsEnd = IdentifierCollectionEnd()
app.add_route("/identifiers", aidsEnd)
submitEnd = IdentifierSubmitResourceEnd()
app.add_route("/identifiers/{name}/submit", submitEnd)
aidEnd = IdentifierResourceEnd()
app.add_route("/identifiers/{name}", aidEnd)

Expand Down Expand Up @@ -615,7 +617,35 @@ def info(hab, rm, full=False):

return data

class IdentifierSubmitResourceEnd:
""" Resource class to submit identifier to its witnesses for receipts """

@staticmethod
def on_put(req, rep, name):
""" Submit request POST endpoint
Parameters:
req (Request): falcon.Request HTTP request object
rep (Response): falcon.Response HTTP response object
name (str): human readable name for Hab to submit
"""
agent = req.context.agent
try:
hab = agent.hby.habByName(name)
if not hab:
raise falcon.HTTPNotFound(description=f"invalid alias {name}")

oid = hab.pre
op = agent.monitor.submit(oid, longrunning.OpTypes.submit, metadata=dict(pre=hab.pre))

rep.content_type = "application/json"
rep.status = falcon.HTTP_202
rep.data = op.to_json().encode("utf-8")

except (kering.AuthError, ValueError) as e:
raise falcon.HTTPBadRequest(description=e.args[0])

class IdentifierOOBICollectionEnd:
"""
This class represents the OOBI subresource collection endpoint for identifiers
Expand Down
2 changes: 2 additions & 0 deletions src/keria/core/keeping.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
from keri.db import dbing, subing, koming
from keri.help import helping

from keria import core


@dataclass()
class Prefix:
Expand Down
25 changes: 20 additions & 5 deletions src/keria/core/longrunning.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@

# long running operationt types
Typeage = namedtuple("Tierage", 'oobi witness delegation group query registry credential endrole challenge exchange '
'done')
'submit done')

OpTypes = Typeage(oobi="oobi", witness='witness', delegation='delegation', group='group', query='query',
registry='registry', credential='credential', endrole='endrole', challenge='challenge',
exchange='exchange', done='done')
exchange='exchange', submit='submit', done='done')


@dataclass_json
Expand Down Expand Up @@ -93,13 +93,18 @@ class Monitor:
"""

def __init__(self, hby, swain, counselor=None, registrar=None, exchanger=None, credentialer=None, opr=None,
temp=False):
submitter=None, temp=False):
""" Create long running operation monitor
Parameters:
hby (Habery): identifier database environment
swain(Sealer): Delegation processes tracker
counselor (Counselor): Group processes tracker
registrar (Registrar): Registry processes tracker
exchanger (Exchanger): Exchange processes tracker
credentialer (Credentialer): Credential processes tracker
opr (Operator): long running operations database
submitter (Submitter): Submit processes tracker
"""
self.hby = hby
Expand All @@ -109,6 +114,7 @@ def __init__(self, hby, swain, counselor=None, registrar=None, exchanger=None, c
self.exchanger = exchanger
self.credentialer = credentialer
self.opr = opr if opr is not None else Operator(name=hby.name, temp=temp)
self.submitter = submitter

def submit(self, oid, typ, metadata=None):
""" Submit a new long running operation to track
Expand Down Expand Up @@ -357,7 +363,7 @@ def status(self, op):
elif op.type in (OpTypes.endrole, ):
if "cid" not in op.metadata or "role" not in op.metadata or "eid" not in op.metadata:
raise kering.ValidationError(
f"invalid long running {op.type} operation, metadata missing 'ced' field")
f"invalid long running {op.type} operation, metadata missing 'cid'/'role'/'eid' field")

cid = op.metadata['cid']
role = op.metadata['role']
Expand All @@ -378,7 +384,7 @@ def status(self, op):

if "words" not in op.metadata:
raise kering.ValidationError(
f"invalid long running {op.type} operation, metadata missing 'ced' field")
f"invalid long running {op.type} operation, metadata missing 'words' field")

found = False
words = op.metadata["words"]
Expand All @@ -394,6 +400,15 @@ def status(self, op):
operation.response = dict(exn=exn.ked)
else:
operation.done = False
elif op.type in (OpTypes.submit, ):
if "pre" not in op.metadata:
raise kering.ValidationError(
f"invalid long running {op.type} operation, metadata missing 'pre' field")

pre = op.metadata['pre']
self.submitter.msgs.append(dict(pre=pre))

operation.done = True

elif op.type in (OpTypes.done, ):
operation.done = True
Expand Down
8 changes: 8 additions & 0 deletions tests/app/test_aiding.py
Original file line number Diff line number Diff line change
Expand Up @@ -1218,8 +1218,10 @@ def test_identifier_resource_end(helpers):
habbing.openHby(name="p2", temp=True) as p2hby:
end = aiding.IdentifierCollectionEnd()
resend = aiding.IdentifierResourceEnd()
subend = aiding.IdentifierSubmitResourceEnd()
app.add_route("/identifiers", end)
app.add_route("/identifiers/{name}", resend)
app.add_route("/identifiers/{name}/submit", subend)

client = testing.TestClient(app)
salt = b'0123456789abcdef'
Expand Down Expand Up @@ -1248,6 +1250,12 @@ def test_identifier_resource_end(helpers):
assert res.status_code == 200
assert res.json['prefix'] == 'EHgwVwQT15OJvilVvW57HE4w0-GPs_Stj2OFoAHZSysY'

res = client.simulate_put(path="/identifiers/bad/submit")
assert res.status_code == 404
assert res.json == {'description': 'invalid alias bad', 'title': '404 Not Found'}

res = client.simulate_put(path="/identifiers/aid1/submit")
assert res.status_code == 202

def test_oobi_ends(helpers):
with helpers.openKeria() as (agency, agent, app, client):
Expand Down
Loading

0 comments on commit 24664ac

Please sign in to comment.