11
22# Adapter application (Python)
33
4- This application is an adapter for Pääsuke written in Python Flask.
5- This is used by a party who keeps mandates on their side but offers a standard service
4+ This application is an adapter for [ Pääsuke] ( https://github.com/e-gov/PH ) written in Python Flask.
5+ This can be used by a party who keeps mandates on their side and offers a standard web service
66for Pääsuke for it to query mandates.
77
88The idea is that there is a Postgres database that keeps the data.
9- Into that Postgres database we create view and procedures that this app calls.
9+ Into that Postgres database we create view and stored procedures that this app calls.
1010
1111## Sequence diagram illustrating the application
1212![ Sequence diagram] ( doc/sequence-diagram-pr.png )
@@ -31,8 +31,6 @@ This database has a few tables to sore information about mandates.
3131
3232
3333## Configuration
34- 1 . List of roles => view
35-
3634
3735## How to run API app in development environment
3836
@@ -52,18 +50,15 @@ Check configuration example in example.cfg.
5250## How to run API app with docker-compose
5351 `docker-compose up -d`
5452
55- Access API on http://localhost:5002/v1
53+ ## How to configure the list of roles
54+
55+ Configure the list of roles in tests/pg_data/02b_view_paasuke_roles_view.sql
5656
57- ```
58- curl --location 'http://localhost:5002/v1/representees/EE33333333/delegates/mandates' \
59- --header 'X-Road-UserId: test-header-xroad-userid' \
60- --header 'X-Road-Represented-Party: TEST-Represented-Party' \
61- --header 'X-Road-Id: TEST-ID-12345'
62- ```
6357
64- ## Tests
58+ ## How to run tests
6559
66- Tests are using the Postgres database running on a Docker container and fixture data inside.
60+ Tests are using the Postgres database running on a Docker container (so you need to have ` docker-compose up postgres ` )
61+ Database contains fixture data .
6762 ` python3 -m venv venv `
6863 ` source venv/bin/activate `
6964 ` pip install -r requirements.txt `
@@ -82,17 +77,20 @@ Point gunicorn to WSGI entrypoint `wsgi.py`
8277
8378## Endpoints
8479
80+ When running locally then access API on http://localhost:8082
81+
82+
8583### ` GET /v1/representees/<str:representee>/delegates/mandates `
8684
8785Accepts representee identifier as parameter in path
88- Raises ` 400 ` error if identifier does not validate
86+ Raises ` 400 ` error if identifier is not valid
8987Returns the list of ` MandateTriplet ` s with status code ` 200 ` if representee has valid mandates
9088Returns empty list if the representee has no valid mandates or the representee is unknown.
91- Uses Postgres view ` representee_mandates_view `
89+ Selects data from Postgres view ` paasuke_mandates_view `
9290
9391Example:
9492```
95- curl --location 'http://localhost:5002 /v1/representees/EE33333333 /delegates/mandates' \
93+ curl --location 'http://localhost:8082 /v1/representees/EE44444444 /delegates/mandates' \
9694--header 'X-Road-UserId: test-header-xroad-userid' \
9795--header 'X-Road-Represented-Party: test-header-xroad-represented-party' \
9896--header 'X-Road-Id: test-header-xroad-id'
@@ -102,49 +100,54 @@ curl --location 'http://localhost:5002/v1/representees/EE33333333/delegates/mand
102100### ` GET /v1/delegates/<str:delegate>/representees/mandates `
103101
104102Accepts delegate identifier as parameter in path
105- Raises ` 400 ` error if identifier does not validate
103+ Raises ` 400 ` error if identifier is not valid
106104Returns the list of ` MandateTriplet ` s with status code ` 200 ` if delegate has valid mandates
107105Returns an empty list if delegate has no valid mandates or the delegate is unknown.
108- Uses Postgres view ` representee_mandates_view `
106+ Selects data from Postgres view ` paasuke_mandates_view `
109107
110108Example:
111109```
112- curl --location 'http://127.0.0.1:5002 /v1/delegates/EE1111111 /representees/mandates' \
110+ curl --location 'http://127.0.0.1:8082 /v1/delegates/EE22202222222 /representees/mandates' \
113111--header 'X-Road-UserId: Test User Id'
114112```
115113
116114### ` GET /roles `
117115
118116Get a list of roles
119- Selects data from Postgres view ` roles_view `
117+ Selects data from Postgres view ` paasuke_roles_view `
120118
121119Example:
122120
123- ` curl --location 'http://localhost:5002 /v1/roles `
121+ ` curl --location 'http://localhost:8082 /v1/roles' `
124122
125123
126124
127125### ` POST /v1/representees/<str:representee>/delegates/<str:delegate>/mandates `
128126
129127Accepts repreentee and delegate identifiers as path parameters
130128Raises ` 400 ` error if payload data is not valid or identifiers are not valid
131- Raises ` 422 ` error if Postgres function ` function_create_mandate ` does not validate input data.
129+ Raises ` 422 ` error if Postgres function ` paasuke_add_mandate ` does not validate input data.
132130Return an empty list with status code ` 201 ` in case of success
133131
134132Example of successful request:
135133
136134```
137- curl --location 'http://127.0.0.1:5002 /v1/representees/EE12345678/delegates/EE38302250123/mandates' \
135+ curl --location 'http://127.0.0.1:8082 /v1/representees/EE12345678/delegates/EE38302250123/mandates' \
138136--header 'Content-Type: application/json' \
139137--header 'X-Road-UserId: LT123456' \
140138--header 'X-Road-Represented-Party: LV1234566' \
141139--data ' {
142140 "authorizations": [
143141 {
144- "hasRole": "FROM_BUSINESS_REGISTRY:MANAGEMENT_BOARD_MEMBER_FULL ",
142+ "hasRole": "BR_REPRIGHT:JUHL_SOLEREP ",
145143 "userIdentifier": "EE49028099999"
146144 }
147145 ],
146+ "representee": {
147+ "identifier": "EE12345678",
148+ "legalName": "Väikefirma OÜ",
149+ "type": "LEGAL_PERSON"
150+ },
148151 "delegate": {
149152 "firstName": "Jüri",
150153 "identifier": "EE38302250123",
@@ -157,16 +160,11 @@ curl --location 'http://127.0.0.1:5002/v1/representees/EE12345678/delegates/EE38
157160 },
158161 "mandate": {
159162 "canSubDelegate": true,
160- "role": "GLOBAL1_EMTA:ACCOUNTANT ",
163+ "role": "AGENCY_X:MANDATES_MANAGER ",
161164 "validityPeriod": {
162165 "from": "2028-01-01",
163166 "through": "2030-12-31"
164167 }
165- },
166- "representee": {
167- "identifier": "EE12345678",
168- "legalName": "Väikefirma OÜ",
169- "type": "LEGAL_PERSON"
170168 }
171169}'
172170```
@@ -176,19 +174,20 @@ curl --location 'http://127.0.0.1:5002/v1/representees/EE12345678/delegates/EE38
176174
177175Accepts ` representeeId ` , ` delegateId ` , ` mandateId ` as parameters in the path.
178176Raises ` 404 ` error if the mandate does not exist
179- Raises ` 422 ` error if Postgres function ` function_insert_mandate_subdelegate ` does not validate input data.
177+ Raises ` 422 ` error if Postgres function ` paasuke_add_mandate_subdelegate ` does not validate input data.
180178Returns empty list with status code ` 200 ` in success case
181179
182180Example of successful request:
181+
183182```
184- curl --location 'http://127.0.0.1:5002 /v1/representees/EE33333333 /delegates/100001 /mandates/150003/subdelegates' \
183+ curl --location 'http://127.0.0.1:8082 /v1/representees/100004 /delegates/100005 /mandates/150003/subdelegates' \
185184--header 'Content-Type: application/json' \
186185--header 'X-Road-UserId: EE23232323' \
187186--header 'X-Road-Represented-Party: EE2323224444' \
188187--data '{
189188 "authorizations": [
190189 {
191- "hasRole": "FROM_BUSINESS_REGISTRY:MANAGEMENT_BOARD_MEMBER_FULL ",
190+ "hasRole": "BR_REPRIGHT:PROK_SOLEREP ",
192191 "userIdentifier": "EE39912310123"
193192 }
194193 ],
@@ -214,13 +213,12 @@ curl --location 'http://127.0.0.1:5002/v1/representees/EE33333333/delegates/1000
214213
215214Accepts ` representeeId ` , ` delegateId ` , ` mandateId ` as parameters in the path.
216215Raises ` 404 ` error if the mandate does not exist
217- Raises ` 422 ` error if Postgres function ` function_delete_mandate ` does not validate input data.
218- Returns empty list with status code ` 200 ` in success case
216+ Raises ` 422 ` error if Postgres function ` paasuke_delete_mandate ` does not validate input data.
217+ Returns empty list with status code ` 200 ` if mandates has been marked deleted successfully
219218
220219Example of successful request:
221-
222220```
223- curl --location --request PUT 'http://127.0.0.1:5002 /v1/representees/EE33333333 /delegates/100001 /mandates/150003 ' \
221+ curl --location --request PUT 'http://127.0.0.1:8082 /v1/representees/100001 /delegates/100003 /mandates/150002 ' \
224222--header 'Content-Type: application/json' \
225223--data '{
226224 "action": "DELETE",
0 commit comments