Skip to content

Issue permits as vc with mdt #1634

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

Merged
merged 47 commits into from
Feb 1, 2021
Merged
Show file tree
Hide file tree
Changes from 46 commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
ee7aa78
Merge branch 'develop' into Issue-permits-as-VC-with-MDT
Jsyro Jan 20, 2021
03ab7a8
Merge branch 'develop' into Issue-permits-as-VC-with-MDT
Jsyro Jan 21, 2021
eae7068
everything except config for api call that issued VC
Jsyro Jan 25, 2021
33e847b
file permission needs to be executable
Jsyro Jan 25, 2021
5ca44bf
Merge branch 'develop' into Issue-permits-as-VC-with-MDT
Jsyro Jan 25, 2021
f8a9bd0
config, placeholder apikey
Jsyro Jan 25, 2021
71bd131
first pass happy path with FE.
Jsyro Jan 25, 2021
a94a773
snapshot
Jsyro Jan 25, 2021
d3a3a35
renaming config
Jsyro Jan 25, 2021
71b76a3
Merge branch 'develop' into Issue-permits-as-VC-with-MDT
Jsyro Jan 26, 2021
010127e
folder sync
Jsyro Jan 26, 2021
a17bfb2
Merge remote-tracking branch 'origin/Issue-permits-as-VC-with-MDT' in…
Jsyro Jan 26, 2021
0fe7792
no button, and run liveness check first.
Jsyro Jan 26, 2021
bc7c8be
print on 'not live' retry
Jsyro Jan 26, 2021
2bcc281
better logging
Jsyro Jan 26, 2021
9eab05b
two tests.... but module drilling and attribute access got confused.
Jsyro Jan 27, 2021
15568b7
Merge branch 'develop' into Issue-permits-as-VC-with-MDT
Jsyro Jan 27, 2021
c0dcc8c
Merge remote-tracking branch 'origin/Issue-permits-as-VC-with-MDT' in…
Jsyro Jan 27, 2021
423a687
rename service and added attempted VC in permit issuance
Jsyro Jan 27, 2021
7e6c8cb
missed param
Jsyro Jan 27, 2021
681fea5
comment
Jsyro Jan 27, 2021
42db885
Merge branch 'develop' into Issue-permits-as-VC-with-MDT
Jsyro Jan 27, 2021
a199aff
error if explicit call does not complete properly.
Jsyro Jan 27, 2021
48269a4
remove unused imports
Jsyro Jan 27, 2021
667b2b2
needed this one.
Jsyro Jan 27, 2021
c06ba70
add context to popconfirm
Jsyro Jan 27, 2021
329a23c
get actual inspector name.
Jsyro Jan 27, 2021
1aa67f5
release this to admins only.
Jsyro Jan 27, 2021
e42c5f8
throw action creator errors
Jsyro Jan 27, 2021
8d8720b
Merge branch 'develop' into Issue-permits-as-VC-with-MDT
Jsyro Jan 27, 2021
0711f68
empty response bad.
Jsyro Jan 27, 2021
da9208f
Merge remote-tracking branch 'origin/Issue-permits-as-VC-with-MDT' in…
Jsyro Jan 27, 2021
5be8d8d
Merge branch 'develop' into Issue-permits-as-VC-with-MDT
Jsyro Jan 27, 2021
8caecdc
remove verb from references to resource
Jsyro Jan 27, 2021
4ea2e34
Merge remote-tracking branch 'origin/Issue-permits-as-VC-with-MDT' in…
Jsyro Jan 27, 2021
76f7662
Merge branch 'develop' into Issue-permits-as-VC-with-MDT
nayr974 Jan 29, 2021
13353d7
hard code values for major mines, try your best on regional.
Jsyro Jan 29, 2021
ff1c65b
always use set name if exists.
Jsyro Jan 29, 2021
46ed333
Merge remote-tracking branch 'origin/Issue-permits-as-VC-with-MDT' in…
Jsyro Jan 29, 2021
adee719
Merge branch 'develop' into Issue-permits-as-VC-with-MDT
Jsyro Jan 29, 2021
462fc45
formatting idfference
Jsyro Jan 29, 2021
d49781a
Merge remote-tracking branch 'origin/Issue-permits-as-VC-with-MDT' in…
Jsyro Jan 29, 2021
8e09bc6
permitee name and xref relationsihps
Jsyro Jan 29, 2021
603a203
super obtuse error.
Jsyro Jan 30, 2021
b1c3427
attributes
Jsyro Jan 30, 2021
6aa0b5f
typ
Jsyro Jan 30, 2021
ea3fb2c
rename
Jsyro Jan 30, 2021
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
4 changes: 4 additions & 0 deletions openshift/pipeline/config-dev.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ app {
'NRIS_API_URL': "${vars.modules.'mds-nris-backend'.HOST}${vars.modules.'mds-nris-backend'.PATH}",
'DOCUMENT_MANAGER_URL': "${vars.modules.'mds-docman-backend'.HOST}${vars.modules.'mds-docman-backend'.PATH}",
'DOCUMENT_GENERATOR_URL': "${vars.modules.'mds-docgen-api'.HOST}",
'VCR_ISSUER_URL':"${vars.modules.'mds-vc-issuer-api'.HOST}",
]
],
[
Expand Down Expand Up @@ -496,6 +497,9 @@ environments {
'mds-docgen-api' {
HOST = "http://docgen${vars.deployment.suffix}:3030"
}
'mds-vc-issuer-api'{
HOST = "https://mines-permitting-issuer-a3e512-dev.apps.silver.devops.gov.bc.ca/"
}
'filesystem-provider' {
HOST = "http://filesystem-provider${vars.deployment.suffix}:8080"
PATH = "/${vars.git.changeId}/file-api"
Expand Down
5 changes: 5 additions & 0 deletions openshift/pipeline/config-prod.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,8 @@ app {
'NRIS_API_URL': "${vars.modules.'mds-nris-backend'.HOST}${vars.modules.'mds-nris-backend'.PATH}",
'DOCUMENT_MANAGER_URL': "${vars.modules.'mds-docman-backend'.HOST}${vars.modules.'mds-docman-backend'.PATH}",
'DOCUMENT_GENERATOR_URL': "${vars.modules.'mds-docgen-api'.HOST}",
'VCR_ISSUER_URL':"${vars.modules.'mds-vc-issuer-api'.HOST}",

]
],
[
Expand Down Expand Up @@ -545,6 +547,9 @@ environments {
'mds-docgen-api' {
HOST = "http://docgen${vars.deployment.suffix}:3030"
}
'mds-vc-issuer-api'{
HOST = "https://mines-permitting-issuer-a3e512-prod.apps.silver.devops.gov.bc.ca/"
}
'schemaspy' {
HOST = "mds-schemaspy-${vars.deployment.namespace}.pathfinder.gov.bc.ca"
}
Expand Down
5 changes: 5 additions & 0 deletions openshift/pipeline/config-test.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,8 @@ app {
'NRIS_API_URL': "${vars.modules.'mds-nris-backend'.HOST}${vars.modules.'mds-nris-backend'.PATH}",
'DOCUMENT_MANAGER_URL': "${vars.modules.'mds-docman-backend'.HOST}${vars.modules.'mds-docman-backend'.PATH}",
'DOCUMENT_GENERATOR_URL': "${vars.modules.'mds-docgen-api'.HOST}",
'VCR_ISSUER_URL':"${vars.modules.'mds-vc-issuer-api'.HOST}",

]
],
[
Expand Down Expand Up @@ -505,6 +507,9 @@ environments {
'mds-docgen-api' {
HOST = "http://docgen${vars.deployment.suffix}:3030"
}
'mds-vc-issuer-api'{
HOST = "https://mines-permitting-issuer-a3e512-test.apps.silver.devops.gov.bc.ca/"
}
'schemaspy' {
HOST = "mds-schemaspy-${vars.deployment.namespace}.pathfinder.gov.bc.ca"
}
Expand Down
22 changes: 22 additions & 0 deletions openshift/templates/_python36.dc.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@
"required": false,
"value": "template.mds-vfcbc-client-service"
},
{
"name": "VCR_ISSUER_API_SECRET",
"required": false,
"value": "template.mds-issuer-api-secret"
},
{
"name": "MDS_NRIS_API_SECRET",
"required": false,
Expand Down Expand Up @@ -149,6 +154,10 @@
"name": "NRIS_API_URL",
"required": true
},
{
"name": "VCR_ISSUER_URL",
"required": true
},
{
"name": "DOCUMENT_MANAGER_URL",
"required": true
Expand Down Expand Up @@ -551,6 +560,19 @@
"key": "password"
}
}
},
{
"name": "VCR_ISSUER_URL",
"value": "${VCR_ISSUER_URL}"
},
{
"name": "VCR_ISSUER_SECRET_KEY",
"valueFrom": {
"secretKeyRef": {
"name": "${VCR_ISSUER_API_SECRET}",
"key": "vcr-issuer-secret-key"
}
}
}
],
"resources": {
Expand Down
51 changes: 26 additions & 25 deletions services/core-api/app/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@

from app.commands import register_commands
from app.config import Config
from app.extensions import db, jwt, api, cache
#alias api to avoid confusion with api folder (speifically on unittest.mock.patch calls)
from app.extensions import db, jwt, api as root_api_namespace, cache
from app.api.utils.setup_marshmallow import setup_marshmallow


Expand All @@ -52,12 +53,12 @@ def create_app(test_config=None):

def register_extensions(app):

api.app = app
root_api_namespace.app = app
Copy link
Contributor

Choose a reason for hiding this comment

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

I like this better, thanks


# Overriding swaggerUI base path to serve content under a prefix
apidoc.apidoc.static_url_path = '{}/swaggerui'.format(Config.BASE_PATH)

api.init_app(app)
root_api_namespace.init_app(app)

try:
jwt.init_app(app)
Expand All @@ -77,30 +78,30 @@ def register_routes(app):
# Set URL rules for resources
app.add_url_rule('/', endpoint='index')

api.add_namespace(compliance_api)
api.add_namespace(mines_api)
api.add_namespace(parties_api)
api.add_namespace(download_token_api)
api.add_namespace(users_api)
api.add_namespace(search_api)
api.add_namespace(variances_api)
api.add_namespace(incidents_api)
api.add_namespace(reporting_api)
api.add_namespace(now_sub_api)
api.add_namespace(now_app_api)
api.add_namespace(exports_api)
api.add_namespace(doc_gen_api)
api.add_namespace(securities_api)
api.add_namespace(verify_api)
api.add_namespace(orgbook_api)
root_api_namespace.add_namespace(compliance_api)
root_api_namespace.add_namespace(mines_api)
root_api_namespace.add_namespace(parties_api)
root_api_namespace.add_namespace(download_token_api)
root_api_namespace.add_namespace(users_api)
root_api_namespace.add_namespace(search_api)
root_api_namespace.add_namespace(variances_api)
root_api_namespace.add_namespace(incidents_api)
root_api_namespace.add_namespace(reporting_api)
root_api_namespace.add_namespace(now_sub_api)
root_api_namespace.add_namespace(now_app_api)
root_api_namespace.add_namespace(exports_api)
root_api_namespace.add_namespace(doc_gen_api)
root_api_namespace.add_namespace(securities_api)
root_api_namespace.add_namespace(verify_api)
root_api_namespace.add_namespace(orgbook_api)

# Healthcheck endpoint
@api.route('/health')
@root_api_namespace.route('/health')
class Healthcheck(Resource):
def get(self):
return {'status': 'pass'}

@api.errorhandler(AuthError)
@root_api_namespace.errorhandler(AuthError)
def jwt_oidc_auth_error_handler(error):
app.logger.error(str(error))
app.logger.error('REQUEST\n' + str(request))
Expand All @@ -110,7 +111,7 @@ def jwt_oidc_auth_error_handler(error):
'message': str(error),
}, getattr(error, 'status_code', 401)

@api.errorhandler(Forbidden)
@root_api_namespace.errorhandler(Forbidden)
def forbidden_error_handler(error):
app.logger.error(str(error))
app.logger.error('REQUEST\n' + str(request))
Expand All @@ -120,7 +121,7 @@ def forbidden_error_handler(error):
'message': str(error),
}, getattr(error, 'status_code', 403)

@api.errorhandler(AssertionError)
@root_api_namespace.errorhandler(AssertionError)
def assertion_error_handler(error):
app.logger.error(str(error))
return {
Expand All @@ -139,14 +140,14 @@ def sqlalchemy_error_handler(error):

def _add_sqlalchemy_error_handlers(classname):
for subclass in classname.__subclasses__():
(api.errorhandler(subclass))(sqlalchemy_error_handler)
(root_api_namespace.errorhandler(subclass))(sqlalchemy_error_handler)

if len(subclass.__subclasses__()) != 0:
_add_sqlalchemy_error_handlers(subclass)

_add_sqlalchemy_error_handlers(SQLAlchemyError)

@api.errorhandler(Exception)
@root_api_namespace.errorhandler(Exception)
def default_error_handler(error):
app.logger.error(str(error))
return {
Expand Down
6 changes: 6 additions & 0 deletions services/core-api/app/api/mines/namespace.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from app.api.mines.permits.permit.resources.permit_status_code import PermitStatusCodeResource
from app.api.mines.permits.permit_amendment.resources.permit_amendment import PermitAmendmentResource, PermitAmendmentListResource
from app.api.mines.permits.permit_amendment.resources.permit_amendment_document import PermitAmendmentDocumentListResource, PermitAmendmentDocumentResource
from app.api.mines.permits.permit_amendment.resources.permit_amendment_vc import PermitAmendmentVCResource
from app.api.mines.permits.permit.resources.permit_document_upload import PermitDocumentUploadInitializationResource
from app.api.mines.region.resources.region import MineRegionResource
from app.api.mines.reports.resources.mine_report_document import MineReportDocumentListResource
Expand Down Expand Up @@ -111,6 +112,11 @@
PermitAmendmentResource,
'/<string:mine_guid>/permits/<string:permit_guid>/amendments/<string:permit_amendment_guid>')

api.add_resource(
PermitAmendmentVCResource,
'/<string:mine_guid>/permits/<string:permit_guid>/amendments/<string:permit_amendment_guid>/verifiable-credential'
)

api.add_resource(
PermitAmendmentDocumentListResource,
'/<string:mine_guid>/permits/<string:permit_guid>/amendments/<string:permit_amendment_guid>/documents',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@ class MinePermitXref(SoftDeleteMixin, AuditMixin, Base):
permit_id = db.Column(db.Integer, db.ForeignKey('permit.permit_id'), primary_key=True)

start_date = db.Column(db.DateTime, nullable=False)
end_date = db.Column(db.DateTime)
end_date = db.Column(db.DateTime)

mine = db.relationship('Mine')
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from datetime import datetime
from datetime import datetime, date

import uuid

Expand Down Expand Up @@ -70,17 +70,40 @@ class PermitAmendment(SoftDeleteMixin, AuditMixin, Base):
primaryjoin=
"and_(PermitAmendment.mine_guid==foreign(MinePermitXref.mine_guid), PermitAmendment.permit_id==foreign(MinePermitXref.permit_id))"
)
all_mine_permit_xref = db.relationship(
'MinePermitXref',
primaryjoin="PermitAmendment.permit_id==foreign(MinePermitXref.permit_id)")

now_application_identity = db.relationship(
'NOWApplicationIdentity', lazy='selectin', uselist=False)

@hybrid_property
def issuing_inspector_name(self):
title = "Inspector of Mines"

#with i had null propogation
now_identity = self.now_identity
if now_identity:
now_application = now_identity.now_application
if now_application:
issuing_inspector = now_application.issuing_inspector
if issuing_inspector:
return issuing_inspector.party_name

used_by_major_mine = any([m.mine.major_mine_ind for m in self.all_mine_permit_xref])
if used_by_major_mine:
if self.issue_date >= date(2020, 7, 17):
return 'Chief Permitting Officer'
else:
return 'Chief Inspector of Mines'
return title

@hybrid_property
def now_application_documents(self):
_now_app_docs = []
if self.now_application_identity:
_now_app_docs = self.now_application_identity.now_application.documents
return _now_app_docs


@hybrid_property
def imported_now_application_documents(self):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from datetime import datetime
from flask import request, current_app
from flask_restplus import Resource, reqparse
from werkzeug.exceptions import BadRequest

from app.api.mines.permits.permit_amendment.models.permit_amendment import PermitAmendment

from app.extensions import api
from app.api.utils.access_decorators import requires_role_mine_admin
from app.api.utils.resources_mixins import UserMixin

from app.api.services.issue_to_orgbook_service import OrgBookIssuerService


class PermitAmendmentVCResource(Resource, UserMixin):
@requires_role_mine_admin
@api.response(200, "VC Issued to OrgBook, no local data created")
def post(self, mine_guid, permit_guid, permit_amendment_guid):
permit_amendment = PermitAmendment.find_by_permit_amendment_guid(permit_amendment_guid)

response = OrgBookIssuerService().issue_permit_amendment_vc(permit_amendment)
if not response:
raise BadRequest(
"Credential Not Issued, ensure permittee is associated with OrgBook Entity")
return
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
from app.api.mines.permits.permit_amendment.models.permit_amendment import PermitAmendment
from app.api.mines.permits.permit_amendment.models.permit_amendment_document import PermitAmendmentDocument
from app.api.parties.party_appt.models.mine_party_appt import MinePartyAppointment

from app.api.services.issue_to_orgbook_service import OrgBookIssuerService
from werkzeug.exceptions import BadRequest, NotFound, NotImplemented


Expand Down Expand Up @@ -141,6 +143,17 @@ def put(self, application_guid):

permit_amendment.save()

#Issue Permit as Verifiable Credential to OrgBook
try:
Copy link
Contributor

Choose a reason for hiding this comment

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

Should any possible exceptions be blocking? Do we just want to log the messages?

OrgBookIssuerService().issue_permit_amendment_vc(permit_amendment)
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we want to check the return value of this here, i.e. the response.status_code maybe?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I don't want this code to effect this method at all. I could be talked into not modifying this at all.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Up to you guys on this one.

except AssertionError as e:
#non-blocking failure
current_app.logger.info('VC Not issued due to non-200 status code')
current_app.logger.debug(str(e))
except Exception as ex:
current_app.logger.warning('VC Not issued due to unknown error')
current_app.logger.info(str(e))

#create contacts
for contact in now_application_identity.now_application.contacts:
if contact.mine_party_appt_type_code == 'PMT' or contact.mine_party_appt_type_code == 'MMG':
Expand Down
Loading