Skip to content

Commit

Permalink
Merge branch 'GLEIF-IT:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
ronakseth96 authored Aug 28, 2024
2 parents df6431c + aceccd5 commit 2d28502
Show file tree
Hide file tree
Showing 20 changed files with 576 additions and 331 deletions.
18 changes: 14 additions & 4 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ on:
- "main"
workflow_dispatch:
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v2
- uses: chartboost/ruff-action@v1
with:
args: check .
test:
name: Run Tests${{ matrix.keria-version }}
runs-on: ${{ matrix.os }}
Expand All @@ -31,11 +39,13 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install flake8 pytest hio httpx
pip install flake8 pytest pytest-cov hio httpx
pip install -r requirements.txt
- name: Start dependencies
run: docker compose up -d
- name: Run unit tests
run: pytest
run: |
sudo docker compose up -d vlei-verifier
sudo docker compose up -d --build reg-pilot-api
- name: Run unit tests wit coverage
run: pytest --cov=./src/regps/app --cov-report=term-missing --cov-fail-under=50


32 changes: 21 additions & 11 deletions .github/workflows/publish-api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
name: Publish Docker image

on:
# push:
# branches:
# - "main"
# pull_request:
# branches:
# - "main"
push:
branches:
- "main"
pull_request:
types: [closed]
workflow_dispatch:
inputs:
version:
required: true
required: false
default: 'dev'
jobs:
push_to_registry:
name: Push Docker image to Docker Hub
Expand All @@ -30,15 +30,25 @@ jobs:
id: meta
uses: docker/metadata-action@v4
with:
images: GLEIF-it/reg-pilot-api
images: gleif/reg-pilot-api

- name: Determine Docker tag
id: docker_tag
run: |
if [[ "${{ github.event_name }}" == "pull_request" && "${{ github.event.action }}" == "closed" && "${{ github.event.pull_request.merged }}" == "true" ]]; then
echo "::set-output name=tag::dev"
elif [[ -n "${{ github.event.inputs.version }}" ]]; then
echo "::set-output name=tag::${{ github.event.inputs.version }}"
else
echo "::set-output name=tag::dev"
fi
- name: Build and push Docker image
uses: docker/build-push-action@v3
with:
context: .
file: images/reg-pilot-api.dockerfile
push: true
tags: |
WebOfTrust/reg-poc-api:${{ github.event.inputs.version }}
WebOfTrust/reg-poc-api:latest
labels: ${{ github.event.inputs.version }}
gleif/reg-pilot-api:${{ steps.docker_tag.outputs.tag }}
labels: ${{ steps.docker_tag.outputs.tag }}
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@
venv
**/__pycache__
*.egg-info/
.vscode/
.vscode/
.coverage
.coverage.*
11 changes: 4 additions & 7 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ services:
build:
context: .
dockerfile: ./images/reg-pilot-api.dockerfile
image: 2byrds/reg-pilot-api:latest
image: gleif/reg-pilot-api:dev
ports:
- 8000:8000
# command: python src/regps/app/fastapi_app.py
Expand All @@ -25,14 +25,11 @@ services:
timeout: 3s
retries: 5
start_period: 2s
# depends_on:
# - verifier
# depends_on:
# - vlei-verifier

vlei-verifier:
build:
context: .
dockerfile: ./images/verifier.dockerfile
image: 2byrds/vlei-verifier:latest
image: gleif/vlei-verifier:dev
container_name: vlei-verifier
hostname: vlei-verifier
# depends_on:
Expand Down
2 changes: 1 addition & 1 deletion images/reg-pilot-api.dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM 2byrds/keri:1.1.7
FROM weboftrust/keri:1.2.0-dev13

WORKDIR /usr/local/var

Expand Down
78 changes: 39 additions & 39 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,38 +27,38 @@
from setuptools import setup

setup(
name='reg-pilot-api',
version='0.0.2', # also change in src/regps/__init__.py
license='Apache Software License 2.0',
description='RegPS: Regulation Portal Service API.',
name="reg-pilot-api",
version="0.0.2", # also change in src/regps/__init__.py
license="Apache Software License 2.0",
description="RegPS: Regulation Portal Service API.",
long_description="RegPS: A Regulation Portal Service to orchestate web app, vLEI validation, etc.",
author='Lance Byrd',
author_email='[email protected]',
url='https://github.com/gleif-it/reg-pilot-api',
packages=find_packages('src'),
package_dir={'': 'src'},
py_modules=[splitext(basename(path))[0] for path in glob('src/*.py')],
author="Lance Byrd",
author_email="[email protected]",
url="https://github.com/gleif-it/reg-pilot-api",
packages=find_packages("src"),
package_dir={"": "src"},
py_modules=[splitext(basename(path))[0] for path in glob("src/*.py")],
include_package_data=True,
zip_safe=False,
classifiers=[
# complete classifier list: http://pypi.python.org/pypi?%3Aaction=list_classifiers
'Development Status :: 3 - Alpha',
'Intended Audience :: Developers',
'License :: OSI Approved :: Apache Software License',
'Operating System :: Unix',
'Operating System :: POSIX',
'Operating System :: Microsoft :: Windows',
'Programming Language :: Python :: 3.12',
'Programming Language :: Python :: Implementation :: CPython',
"Development Status :: 3 - Alpha",
"Intended Audience :: Developers",
"License :: OSI Approved :: Apache Software License",
"Operating System :: Unix",
"Operating System :: POSIX",
"Operating System :: Microsoft :: Windows",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: Implementation :: CPython",
# uncomment if you test on these interpreters:
# 'Programming Language :: Python :: Implementation :: PyPy',
# 'Programming Language :: Python :: Implementation :: IronPython',
# 'Programming Language :: Python :: Implementation :: Jython',
# 'Programming Language :: Python :: Implementation :: Stackless',
'Topic :: Utilities',
"Topic :: Utilities",
],
project_urls={
'Issue Tracker': 'https://github.com/gleif-it/regulation-portal-service/issues',
"Issue Tracker": "https://github.com/gleif-it/regulation-portal-service/issues",
},
keywords=[
"secure attribution",
Expand All @@ -67,35 +67,35 @@
"vLEI",
# eg: 'keyword1', 'keyword2', 'keyword3',
],
python_requires='>=3.12.0',
python_requires=">=3.12.0",
install_requires=[
'apispec>=6.3.0',
'asyncio>=3.4.3',
'dataclasses_json>=0.5.7',
'falcon>=3.1.0',
'gunicorn>=20.1.0',
'uvicorn>=0.30.3',
'http_sfv>=0.9.8',
'requests>=2.31.0',
'swagger-ui-py>=22.7.13',
'keri>=1.1.11',
'fastapi>=0.111.1',
'requests>=2.32.3'
"apispec>=6.3.0",
"asyncio>=3.4.3",
"dataclasses_json>=0.5.7",
"falcon>=3.1.0",
"gunicorn>=20.1.0",
"uvicorn>=0.30.3",
"http_sfv>=0.9.8",
"requests>=2.31.0",
"swagger-ui-py>=22.7.13",
"keri>=1.1.11",
"fastapi>=0.111.1",
"requests>=2.32.3",
"python-multipart"
],
extras_require={
# eg:
# 'rst': ['docutils>=0.11'],
# ':python_version=="2.6"': ['argparse'],
},
tests_require=[
'coverage>=5.5',
'pytest>=6.2.4',
],
setup_requires=[
"coverage>=5.5",
"pytest>=6.2.4",
],
setup_requires=[],
entry_points={
'console_scripts': [
'regps = regps.app.cli.regps:main',
"console_scripts": [
"regps = regps.app.cli.regps:main",
]
},
)
49 changes: 37 additions & 12 deletions src/regps/app/adapters/verifier_service_adapter.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import os
from time import sleep
import json
import logging
Expand All @@ -20,28 +19,45 @@
class VerifierServiceAdapter:
def __init__(self):
# TODO: take only base url for the verifier service from the environment variable
self.auths_url = os.environ.get('VERIFIER_AUTHORIZATIONS', "http://127.0.0.1:7676/authorizations/")
self.presentations_url = os.environ.get('VERIFIER_PRESENTATIONS', "http://127.0.0.1:7676/presentations/")
self.reports_url = os.environ.get('VERIFIER_REPORTS', "http://127.0.0.1:7676/reports/")
self.request_url = os.environ.get('VERIFIER_REQUESTS', "http://localhost:7676/request/verify/")
self.auths_url = os.environ.get(
"VERIFIER_AUTHORIZATIONS", "http://127.0.0.1:7676/authorizations/"
)
self.presentations_url = os.environ.get(
"VERIFIER_PRESENTATIONS", "http://127.0.0.1:7676/presentations/"
)
self.reports_url = os.environ.get(
"VERIFIER_REPORTS", "http://127.0.0.1:7676/reports/"
)
self.request_url = os.environ.get(
"VERIFIER_REQUESTS", "http://localhost:7676/request/verify/"
)

def check_login_request(self, aid: str) -> requests.Response:
logger.info(f"checking login: {aid}")
logger.info(f"getting from {self.auths_url}{aid}")
res = requests.get(f"{self.auths_url}{aid}", headers={"Content-Type": "application/json"})
res = requests.get(
f"{self.auths_url}{aid}", headers={"Content-Type": "application/json"}
)
logger.info(f"login status: {json.dumps(res.json())}")
return res

def verify_vlei_request(self, said: str, vlei: str) -> requests.Response:
logger.info(f"Verify vlei task started {said} {vlei[:50]}")
logger.info(f"presenting vlei ecr to url {self.presentations_url}{said}")
res = requests.put(f"{self.presentations_url}{said}", headers={"Content-Type": "application/json+cesr"},
data=vlei)
res = requests.put(
f"{self.presentations_url}{said}",
headers={"Content-Type": "application/json+cesr"},
data=vlei,
)
logger.info(f"verify vlei task response {json.dumps(res.json())}")
return res

def verify_cig_request(self, aid, cig, ser) -> requests.Response:
logger.info("Verify header sig started aid = {}, cig = {}, ser = {}....".format(aid, cig, ser))
logger.info(
"Verify header sig started aid = {}, cig = {}, ser = {}....".format(
aid, cig, ser
)
)
logger.info("posting to {}".format(self.request_url + f"{aid}"))
res = requests.post(self.request_url + aid, params={"sig": cig, "data": ser})
logger.info(f"Verify sig response {json.dumps(res.json())}")
Expand All @@ -50,11 +66,16 @@ def verify_cig_request(self, aid, cig, ser) -> requests.Response:
def check_upload_request(self, aid: str, dig: str) -> requests.Response:
logger.info(f"checking upload: aid {aid} and dig {dig}")
logger.info(f"getting from {self.reports_url}{aid}/{dig}")
res = requests.get(f"{self.reports_url}{aid}/{dig}", headers={"Content-Type": "application/json"})
res = requests.get(
f"{self.reports_url}{aid}/{dig}",
headers={"Content-Type": "application/json"},
)
logger.info(f"upload status: {json.dumps(res.json())}")
return res

def upload_request(self, aid: str, dig: str, contype: str, report) -> requests.Response:
def upload_request(
self, aid: str, dig: str, contype: str, report
) -> requests.Response:
logger.info(f"upload report type {type(report)}")
# first check to see if we've already uploaded
cres = self.check_upload_request(aid, dig)
Expand All @@ -63,7 +84,11 @@ def upload_request(self, aid: str, dig: str, contype: str, report) -> requests.R
return cres
else:
logger.info(f"upload posting to {self.reports_url}{aid}/{dig}")
cres = requests.post(f"{self.reports_url}{aid}/{dig}", headers={"Content-Type": contype}, data=report)
cres = requests.post(
f"{self.reports_url}{aid}/{dig}",
headers={"Content-Type": contype},
data=report,
)
logger.info(f"post response {json.dumps(cres.json())}")
if cres.status_code < 300:
cres = self.check_upload_request(aid, dig)
Expand Down
Loading

0 comments on commit 2d28502

Please sign in to comment.