Skip to content

Commit

Permalink
Merge branch 'main' of github.com:e-gov/PH-sample-provider-python
Browse files Browse the repository at this point in the history
  • Loading branch information
aasaru committed Sep 1, 2023
2 parents 7638690 + 3f907f9 commit 4b5c213
Show file tree
Hide file tree
Showing 6 changed files with 1,356 additions and 12 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.idea
venv
tests/postgres-volume
tests/postgres-volume
config/dev.cfg
18 changes: 11 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,21 @@ and create their own database views and stored functions.
## Sequence diagram illustrating the application
![Sequence diagram](doc/sequence-diagram-pr.png)

## Running
## Running the built docker image

Use Docker-compose to start up a Postgres database and the application.
The scripts create a few tables to sore information about mandates and views and functions to interact
with this data.
Every time this repository is tag-ed with a new version,
GitHub Actions builds a public Docker image and uploads it to GitHub Container Registry (ghcr.io)
See [the details of recent actions](https://github.com/e-gov/PH-sample-provider-python/actions) and [the list of tags](https://github.com/e-gov/PH-sample-provider-python/tags).

For example, one can get the version 0.9.0 like this:
`docker pull ghcr.io/e-gov/ph-sample-provider-python:v0.9.0`
`docker pull --platform linux/x86_64 ghcr.io/e-gov/ph-sample-provider-python:v0.9.0` (Mac)

## How this app was made
## Running locally

1. Open https://app.swaggerhub.com/apis/aasaru/x-road-services-consumed-by-paasuke/0.8.0#/
2. Export server stub -> python flask
Use Docker-compose to start up a Postgres database and the application.
The scripts create a few tables to sore information about mandates and views and functions to interact
with this data.


## Configuration
Expand Down
13 changes: 12 additions & 1 deletion api/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import yaml
from flask import Flask, jsonify, request
from flask_sqlalchemy import SQLAlchemy
from flask_swagger_ui import get_swaggerui_blueprint

from api.exceptions import (CompanyCodeInvalid,
ErrorConfigBase, MandateDataInvalid,
Expand Down Expand Up @@ -40,6 +41,17 @@ def create_app():
db.init_app(app)
app.config['SETTINGS'] = parse_settings(app.config['SETTINGS_PATH'])

SWAGGER_URL = "/v1/api-docs"
API_URL = "/static/aasaru-x-road-services-consumed-by-paasuke-0.9.3-resolved.json"
SWAGGER_BLUEPRINT = get_swaggerui_blueprint(
SWAGGER_URL,
API_URL,
config={
'app_name': "X-road services consumed by Pääsuke"
}
)
app.register_blueprint(SWAGGER_BLUEPRINT, url_prefix=SWAGGER_URL)

app.errorhandler(ActionInvalid)(create_error_handler(501))
app.errorhandler(CompanyCodeInvalid)(create_error_handler(400))
app.errorhandler(MandateDataInvalid)(create_error_handler(400))
Expand Down Expand Up @@ -110,7 +122,6 @@ def get_representees_delegates_mandates(representee_identifier):
methods=['POST'])
def post_representee_delegate_mandate(representee_identifier, delegate_identifier):
xroad_user_id = request.headers.get('X-Road-UserId')
xroad_represented_party = request.headers.get('X-Road-Represented-Party')
app.logger.info(f'X-Road-UserId: {xroad_user_id} is about to add a mandate')

error_config = app.config['SETTINGS']['errors']['legal_person_format_validation_failed']
Expand Down
3 changes: 1 addition & 2 deletions api/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,7 @@ def extract_mandate_data(payload):
data['data_created_by'] = data_.get('createdBy', '')
data['data_original_mandate_id'] = data_.get('originalMandateId')
data['document_uuid'] = document.get('uuid')
if document.get('singleDelegate') and document.get('uuid'):
data['data_can_display_document_to_delegate'] = True
data['data_can_display_document_to_delegate'] = bool(document.get('singleDelegate') and document.get('uuid'))

return data

Expand Down
Loading

0 comments on commit 4b5c213

Please sign in to comment.