Skip to content

Commit

Permalink
⬆️ Upgrading contracts, zenroom and fastapi
Browse files Browse the repository at this point in the history
  • Loading branch information
puria committed Jul 16, 2019
1 parent 1aa8bb6 commit e7626c8
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 24 deletions.
4 changes: 2 additions & 2 deletions app/config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
debug = true

# This is a unique ID that distinguish the Credential Issuer instance
uid = Credential Issuer 01
uid = issuer_identifier

# The abs path of the file where the keypair of the CI is stored
# WARNING: if it does not exists will be created the first time
Expand All @@ -22,4 +22,4 @@ AUTH_USERNAME = demo
AUTH_PASSWORD = demo

# Database
SQLALCHEMY_DATABASE_URI = sqlite:////app/app/test.db
SQLALCHEMY_DATABASE_URI = sqlite:////app/app/test.db
31 changes: 14 additions & 17 deletions app/zencontract.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from pathlib import Path

from zenroom import zenroom
from zenroom.zenroom import Error

from app.config.config import BaseConfig

Expand Down Expand Up @@ -41,34 +40,32 @@ def get_contract(self):
contract = contracts_dir.joinpath(self.name).read_text()
for k, v in self.placeholder.items():
contract = contract.replace(f"'{k}'", f"'{v}'")
return contract.encode()
return contract

def execute(self):
if config.getboolean("debug"): # pragma: no cover
log.debug("+" * 50)
log.debug("EXECUTING %s" % self.name)
log.debug("+" * 50)
log.debug("DATA: %s" % self.data())
log.debug("KEYS: %s" % self.keys())
log.debug("CODE: \n%s" % self.zencode.decode())
try:
result, errors = zenroom.execute(
self.zencode, keys=self._keys, data=self._data
)
self._error = errors
return result.decode()
except Error:
return None
log.debug("DATA: %s" % self._data)
log.debug("KEYS: %s" % self._keys)
log.debug("CODE: \n%s" % self.zencode)

result, errors = zenroom.zencode_exec(
script=self.zencode, keys=self._keys, data=self._data
)
self._error = errors
return result

def keys(self, keys=None):
if keys:
self._keys = keys.encode()
return self._keys.decode() if self._keys else None
self._keys = keys
return self._keys

def data(self, data=None):
if data:
self._data = data.encode()
return self._data.decode() if self._data else None
self._data = data
return self._data

def errors(self):
return self._error
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
test=pytest

[tool:pytest]
addopts = --cov=app --cov-report term-missing
addopts = --maxfail=1 --cov=app --cov-report term-missing
env =
DDDC_CREDENTIAL_ISSUER_CONFIGFILE=/home/puria/src/dddc-credential-issuer/app/test.ini

Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
packages=find_packages(),
install_requires=[
"bunch==1.0.1",
"fastapi==0.7.1",
"fastapi==0.33.0",
"pytest_runner==4.4",
"zenroom==0.2.5",
"zenroom==1.0.5",
"pre-commit==1.14.4",
"python-multipart==0.0.5",
"pyjwt==1.7.1",
Expand Down
2 changes: 1 addition & 1 deletion start.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh

docker build -t dddc-credential-issuer .
docker run --rm -p 80:80 -e APP_MODULE="app.main:api" -e LOG_LEVEL="debug" -it dddc-credential-issuer
docker run --rm -p 5000:80 -e APP_MODULE="app.main:api" -e LOG_LEVEL="debug" -it dddc-credential-issuer

0 comments on commit e7626c8

Please sign in to comment.