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

18284: digital business card #2256

Closed
wants to merge 14 commits into from
Closed
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
15 changes: 15 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM mcr.microsoft.com/devcontainers/python:1-3.8-bookworm

ENV PYTHONUNBUFFERED 1

# [Optional] If your requirements rarely change, uncomment this section to add them to the image.
# COPY requirements.txt /tmp/pip-tmp/
# RUN pip3 --disable-pip-version-check --no-cache-dir install -r /tmp/pip-tmp/requirements.txt \
# && rm -rf /tmp/pip-tmp

# [Optional] Uncomment this section to install additional OS packages.
# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
# && apt-get -y install --no-install-recommends <your-package-list-here>



31 changes: 31 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/postgres
{
"name": "Python 3 & PostgreSQL",
"dockerComposeFile": "docker-compose.yml",
"service": "app",
"workspaceFolder": "/workspaces/${localWorkspaceFolderBasename}",
"features": {
"ghcr.io/devcontainers/features/docker-outside-of-docker:1": {},
"ghcr.io/itsmechlark/features/postgresql:1": {}
},

// Features to add to the dev container. More info: https://containers.dev/features.
// "features": {},

// Use 'forwardPorts' to make a list of ports inside the container available locally.
// This can be used to network with other containers or the host.
// "forwardPorts": [5000, 5432],

// Use 'postCreateCommand' to run commands after the container is created.
// "postCreateCommand": "pip install --user -r requirements.txt",

// Configure tool-specific properties.
// "customizations": {},

// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
// "remoteUser": "root",

// Enable this on OSX to add ssh key to agent inside container
"initializeCommand": "find ~/.ssh/ -type f -exec grep -l 'PRIVATE' {} \\; | xargs ssh-add"
}
35 changes: 35 additions & 0 deletions .devcontainer/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
version: '3.8'

services:
app:
build:
context: ..
dockerfile: .devcontainer/Dockerfile

volumes:
- ../..:/workspaces:cached

# Overrides default command so things don't shut down after the process ends.
command: sleep infinity

# Runs app on the same network as the database container, allows "forwardPorts" in devcontainer.json function.
network_mode: service:db

# Use "forwardPorts" in **devcontainer.json** to forward an app port locally.
# (Adding the "ports" property to this file will not forward from a Codespace.)

db:
image: postgres:latest
restart: unless-stopped
volumes:
- postgres-data:/var/lib/postgresql/data
environment:
POSTGRES_USER: postgres
POSTGRES_DB: postgres
POSTGRES_PASSWORD: postgres

# Add "forwardPorts": ["5432"] to **devcontainer.json** to forward PostgreSQL locally.
# (Adding the "ports" property to this file will not forward from a Codespace.)

volumes:
postgres-data:
5 changes: 4 additions & 1 deletion legal-api/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,10 @@ tag: push ## tag image
# COMMANDS - Local #
#################################################################################
run: ## Run the project in local
. venv/bin/activate && python -m flask run -p 5000
. venv/bin/activate && python -m flask run -p 5050

run-websockets: ## Run the project in local with websockets
. venv/bin/activate && python -m gunicorn --threads 100 --bind :5050 wsgi

#################################################################################
# Self Documenting Commands #
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
"""add revocation to dc_credentials

Revision ID: 6b65b40a5164
Revises: 9a9ac165365e
Create Date: 2023-10-11 22:20:14.023687

"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = '6b65b40a5164'
down_revision = '9a9ac165365e'
branch_labels = None
depends_on = None


def upgrade():
op.add_column('dc_issued_credentials', sa.Column('credential_revocation_id', sa.String(length=10), nullable=True))
op.add_column('dc_issued_credentials', sa.Column('revocation_registry_id', sa.String(length=200), nullable=True))


def downgrade():
op.drop_column('dc_issued_credentials', 'credential_revocation_id')
op.drop_column('dc_issued_credentials', 'revocation_registry_id')
28 changes: 28 additions & 0 deletions legal-api/migrations/versions/8148a25d695e_change_field_type.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
"""change field type

Revision ID: 8148a25d695e
Revises: 6b65b40a5164
Create Date: 2023-10-17 01:05:30.977475

"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = '8148a25d695e'
down_revision = '6b65b40a5164'
branch_labels = None
depends_on = None


def upgrade():
op.alter_column('dc_issued_credentials', 'credential_id',
existing_type=sa.String(length=100),
type_=sa.String(length=10))


def downgrade():
op.alter_column('dc_issued_credentials', 'credential_id',
existing_type=sa.String(length=10),
type_=sa.String(length=100))
14 changes: 7 additions & 7 deletions legal-api/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,16 @@ Flask-Moment==0.11.0
Flask-Pydantic==0.8.0
Flask-SQLAlchemy==2.5.1
Flask-Script==2.0.6
Flask-SocketIO==5.3.6
Flask==1.1.2
Jinja2==2.11.3
Mako==1.1.4
MarkupSafe==1.1.1
PyPDF2==1.26.0
SQLAlchemy-Continuum==1.3.13
SQLAlchemy-Utils==0.37.8
SQLAlchemy==1.4.44
Werkzeug==1.0.1
nest_asyncio
alembic==1.7.5
aniso8601==9.0.1
asyncio-nats-client==0.11.4
Expand All @@ -31,11 +32,15 @@ ecdsa==0.14.1
expiringdict==1.1.4
flask-jwt-oidc==0.3.0
flask-restx==0.3.0
git+https://github.com/bcgov/business-schemas.git@2.18.13#egg=registry_schemas
gunicorn==20.1.0
html-sanitizer==1.9.3
idna==2.10
itsdangerous==1.1.0
jsonschema==4.19.0
launchdarkly-server-sdk==7.1.0
minio==7.0.2
nest_asyncio
protobuf==3.15.8
psycopg2-binary==2.8.6
pyRFC3339==1.1
Expand All @@ -48,16 +53,11 @@ python-dotenv==0.17.1
python-editor==1.0.4
python-jose==3.2.0
pytz==2021.1
reportlab==3.6.12
requests==2.25.1
rsa==4.7.2
semver==2.13.0
sentry-sdk==1.20.0
six==1.15.0
strict-rfc3339==0.7
urllib3==1.26.11
minio==7.0.2
PyPDF2==1.26.0
reportlab==3.6.12
html-sanitizer==1.9.3
git+https://github.com/bcgov/business-schemas.git@2.18.13#egg=registry_schemas

52 changes: 0 additions & 52 deletions legal-api/requirements.txt.1

This file was deleted.

3 changes: 3 additions & 0 deletions legal-api/src/legal_api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from registry_schemas.flask import SchemaServices # noqa: I001

from legal_api import config, models
from legal_api.extensions import socketio
from legal_api.models import db
from legal_api.resources import endpoints
from legal_api.schemas import rsbc_schemas
Expand Down Expand Up @@ -67,6 +68,8 @@ def create_app(run_mode=os.getenv('FLASK_ENV', 'production')):

register_shellcontext(app)

socketio.init_app(app, cors_allowed_origins='*')

return app


Expand Down
13 changes: 10 additions & 3 deletions legal-api/src/legal_api/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,16 @@ class _Config(): # pylint: disable=too-few-public-methods

NAICS_API_URL = os.getenv('NAICS_API_URL', 'https://NAICS_API_URL/api/v2/naics')

ACA_PY_ADMIN_API_URL = os.getenv('ACA_PY_ADMIN_API_URL')
ACA_PY_ADMIN_API_KEY = os.getenv('ACA_PY_ADMIN_API_KEY')
ACA_PY_ENTITY_DID = os.getenv('ACA_PY_ENTITY_DID')
# Digital Credential configuration values
TRACTION_API_URL = os.getenv('TRACTION_API_URL')
TRACTION_API_TOKEN = os.getenv('TRACTION_API_TOKEN')
TRACTION_PUBLIC_SCHEMA_DID = os.getenv('TRACTION_PUBLIC_SCHEMA_DID')
TRACTION_PUBLIC_ISSUER_DID = os.getenv('TRACTION_PUBLIC_ISSUER_DID')

BUSINESS_SCHEMA_NAME = os.getenv('BUSINESS_SCHEMA_NAME')
BUSINESS_SCHEMA_VERSION = os.getenv('BUSINESS_SCHEMA_VERSION')
BUSINESS_SCHEMA_ID = os.getenv('BUSINESS_SCHEMA_ID')
BUSINESS_CRED_DEF_ID = os.getenv('BUSINESS_CRED_DEF_ID')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure where these come from (for the BE) but probably need to work with Patrick Wei to configure these (in 1Password, I assume).

Are there different values for Dev/Test/Prod environments?

Also, where are these key values for running locally?


TESTING = False
DEBUG = False
Expand Down
25 changes: 25 additions & 0 deletions legal-api/src/legal_api/extensions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Copyright © 2022 Province of British Columbia
#
# Licensed under the Apache License, Version 2.0 (the 'License');
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an 'AS IS' BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Extensions module."""
from flask import current_app
from flask_socketio import SocketIO


socketio = SocketIO()


@socketio.on('connect')
def on_connect():
"""Handle socket connection."""
current_app.logger.debug('Socket connected to client')
5 changes: 5 additions & 0 deletions legal-api/src/legal_api/models/dc_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ def save(self):
db.session.add(self)
db.session.commit()

def delete(self):
"""Delete the object from the database immediately."""
db.session.delete(self)
db.session.commit()

@classmethod
def find_by_id(cls, dc_connection_id: str) -> DCConnection:
"""Return the digital credential connection matching the id."""
Expand Down
11 changes: 6 additions & 5 deletions legal-api/src/legal_api/models/dc_definition.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,15 @@ def find_by_credential_type(cls, credential_type: CredentialType) -> DCDefinitio
@classmethod
def find_by(cls,
credential_type: CredentialType,
schema_name: str,
schema_version: str) -> DCDefinition:
schema_id: str,
credential_definition_id: str,
) -> DCDefinition:
"""Return the digital credential definition matching the filter."""
query = db.session.query(DCDefinition). \
filter(DCDefinition.is_deleted is False). \
filter(DCDefinition.credential_type == credential_type). \
filter(DCDefinition.schema_name == schema_name). \
filter(DCDefinition.schema_version == schema_version)

filter(DCDefinition.schema_id == schema_id). \
filter(DCDefinition.credential_definition_id == credential_definition_id)
return query.one_or_none()

@classmethod
Expand Down
Loading
Loading