Skip to content
This repository was archived by the owner on Feb 12, 2021. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
4090c38
modifications that match new api specification
teemukataja Nov 5, 2018
3e21326
fix post and patch date handling
teemukataja Nov 5, 2018
2432ef5
removed datasetowner key from schemas
teemukataja Nov 5, 2018
791b440
allow PATCHing of user details and other fixes
teemukataja Nov 6, 2018
54ec91a
change PATCH OK from 200 to 204, remove comments
teemukataja Nov 6, 2018
b527644
fix 400 at /user get, patch, delete
teemukataja Nov 6, 2018
7c1491f
update docs and readme, remove suggestions and add suggestion for api…
teemukataja Nov 6, 2018
e6d460e
remove urlprefix from patch and post
teemukataja Nov 6, 2018
981ddf0
validate api key from database instead of environment, docs updates, …
teemukataja Nov 7, 2018
e0d4180
move to openapi 3.0.0
blankdots Nov 12, 2018
d62f7a0
add missing 401s
teemukataja Nov 12, 2018
5301710
#16 remove lingering user details on delete request
teemukataja Nov 20, 2018
2f60a73
#16 restructure
teemukataja Nov 20, 2018
d92050d
#17 verify existance of datasets before POST/PATCH requests and chang…
teemukataja Nov 20, 2018
f4c59ab
#17 add userid to roles table
teemukataja Nov 20, 2018
96caa05
#18 remove eppn and use elixir id instead
teemukataja Nov 20, 2018
257c83c
remove eppn
teemukataja Nov 20, 2018
eccdf8a
update docs
teemukataja Nov 20, 2018
ec226bd
add affiliation key to userdetails and datasetpermissions
teemukataja Nov 28, 2018
14f78cb
change default value of logging debug env
teemukataja Nov 28, 2018
fe35290
fix patch endpoint user check
teemukataja Nov 28, 2018
6f54414
update docs
teemukataja Nov 28, 2018
466a861
changes
teemukataja Nov 28, 2018
16c7f8b
flake8
teemukataja Dec 3, 2018
f8192bb
forgot to add file
teemukataja Dec 3, 2018
02858bc
update docs
teemukataja Dec 11, 2018
3ba2584
update docs, remove old envvar
teemukataja Dec 11, 2018
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
60 changes: 24 additions & 36 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,22 +61,24 @@ For more technical details, consult the [API Specification](https://app.swaggerh
curl -X POST \
http://localhost:8080/user \
-H 'Content-Type: application/json' \
-H 'elixir-api-key: secret' \
-d '{
"user_identifier": "test_user",
"affiliation": "",
"datasets": [
"userDetails": {
"elixirId": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa@elixir-europe.org",
"eduPersonPrincipalName": "user@org.org",
"userEmail": "firstname.lastname@organisation.org",
"realName": "Firstname Lastname"
},
"datasetPermissions": [
{
"permissions": [
{
"affiliation": "example-org",
"source_signature": "",
"url_prefix": "",
"datasets": [
"urn:example-dataset-1",
"urn:example-dataset-2"
]
}
]
"datasetId": "urn:example-dataset-1",
"startDate": "2018-01-01 12:00:00.000000+0000",
"endDate": "2019-01-01 12:00:00.000000+0000"
},
{
"datasetId": "urn:example-dataset-2",
"startDate": "",
"endDate": ""
}
]
}'
Expand All @@ -85,30 +87,21 @@ curl -X POST \
#### GET /user/username
`GET` method at `/user` endpoint is used to fetch dataset permissions for user.
```
curl -X GET http://localhost:8080/user/test_user
curl -X GET -H 'elixir-api-key: secret' http://localhost:8080/user/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa@elixir-europe.org
```

#### PATCH /user/username
`PATCH` method at `/user` endpoint is used to update dataset permissions for user.
`PATCH` method at `/user` endpoint is used to update user details and dataset permissions for user. `PATCH` endpoint consumes the same schema as `POST` endpoint, but all fields are optional instead of mandatory.
```
curl -X PATCH \
http://localhost:8080/user/test_user \
http://localhost:8080/user/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa@elixir-europe.org \
-H 'Content-Type: application/json' \
-H 'elixir-api-key: secret' \
-d '{
"user_identifier": "",
"affiliation": "",
"datasets": [
"datasetPermissions": [
{
"permissions": [
{
"affiliation": "example-org",
"source_signature": "",
"url_prefix": "",
"datasets": [
"urn:example-dataset-3"
]
}
]
"datasetId": "urn:example-dataset-1",
"endDate": "2020-01-01 12:00:00.000000+0000"
}
]
}'
Expand All @@ -117,10 +110,5 @@ curl -X PATCH \
#### DELETE /user/username
`DELETE` method at `/user` endpoint is used to delete user along with dataset permissions.
```
curl -X DELETE http://localhost:8080/user/test_user
curl -X DELETE -H 'elixir-api-key: secret' http://localhost:8080/user/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa@elixir-europe.org
```

</details>

### Other Business
The [Permissions API Specification](https://app.swaggerhub.com/apis-docs/ELIXIR-Finland/Permissions/1.2) contains some typos. A [suggestions](suggestions.md) document has been drafted to correct those issues. Expect changes to be made to the specification in the near future, along with changes to the API app.
112 changes: 67 additions & 45 deletions docs/example.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,26 +31,25 @@ An example ``POST`` request and response to the ``user`` endpoint:

.. code-block:: console

$ curl -X POST \
curl -X POST \
http://localhost:8080/user \
-H 'Content-Type: application/json' \
-H 'elixir-api-key: secret' \
-d '{
"user_identifier": "test_user",
"affiliation": "",
"datasets": [
"userDetails": {
"elixirId": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa@elixir-europe.org",
"eduPersonPrincipalName": "username@organisation.org",
"userEmail": "firstname.lastname@organisation.org",
"realName": "Firstname Lastname"
},
"datasetPermissions": [
{
"permissions": [
{
"affiliation": "example-org",
"source_signature": "",
"url_prefix": "",
"datasets": [
"urn:example-dataset-1",
"urn:example-dataset-2"
]
}
]
"datasetId": "urn:example-dataset-1",
"startDate": "2018-01-01 12:00:00.000000+0000",
"endDate": "2019-01-01 12:00:00.000000+0000"
},
{
"datasetId": "urn:example-dataset-2",
}
]
}'
Expand All @@ -65,58 +64,81 @@ An example ``GET`` request and response to the ``user`` endpoint:

.. code-block:: console

$ curl -X GET -H 'elixir-api-key: secret' http://localhost:8080/user/test_user
$ curl -X GET -H 'elixir-api-key: secret' http://localhost:8080/user/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa@elixir-europe.org

Example Response:

.. code-block:: javascript

{
"permissions": [
{
"affiliation": "",
"source_signature": "",
"url_prefix": "",
"datasets": [
"urn:example-dataset-1",
"urn:example-dataset-2"
]
}
"sourceSignature": "string",
"datasetPermissions": [
{
"userAffiliation": "username@organisation.org",
"urlPrefix": "",
"datasetId": "urn:example-dataset-1",
"startDate": "2018-01-01 12:00:00.000000+0000",
"endDate": "2019-01-01 12:00:00.000000+0000"
},
{
"datasetOwner": "example-org",
"urlPrefix": "",
"datasetId": "urn:example-dataset-2",
"startDate": "2018-11-06 12:00:00.000000+0000",
"endDate": "None"
}
]
}

An example ``PATCH`` request and response to the ``user`` endpoint:
Few examples of ``PATCH`` requests to the ``user`` endpoint:

CASE 1: Update dataset permissions

.. code-block:: console

$ curl -X PATCH \
http://localhost:8080/user/test_user \
curl -X PATCH \
http://localhost:8080/user/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa@elixir-europe.org \
-H 'Content-Type: application/json' \
-H 'elixir-api-key: secret' \
-d '{
"user_identifier": "",
"affiliation": "",
"datasets": [
"datasetPermissions": [
{
"permissions": [
{
"affiliation": "example-org",
"source_signature": "",
"url_prefix": "",
"datasets": [
"urn:example-dataset-3"
]
}
]
"datasetId": "urn:example-dataset-1",
"endDate": "2020-01-01 12:00:00.000000+0000"
}
]
}'

Example Response:
CASE 2: Clear dataset permissions by sending an empty ``datasetPermissions`` object

.. code-block:: text
.. code-block:: console

Successful operation
curl -X PATCH \
http://localhost:8080/user/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa@elixir-europe.org \
-H 'Content-Type: application/json' \
-H 'elixir-api-key: secret' \
-d '{
"datasetPermissions": [{}]
}'

CASE 3: Update user details

.. code-block:: console

curl -X PATCH \
http://localhost:8080/user/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa@elixir-europe.org \
-H 'Content-Type: application/json' \
-H 'elixir-api-key: secret' \
-d '{
"userDetails": {
"userEmail": "user.name@organisation.org",
"realName": "User Name"
}
}'

.. note:: ``PATCH`` endpoint consumes the same schema as ``POST`` endpoint, but all fields are optional instead of mandatory.

.. note:: Successful ``PATCH`` requests respond with ``HTTP 204 No Content``.

An example ``DELETE`` request and response to the ``user`` endpoint:

Expand Down
37 changes: 17 additions & 20 deletions docs/instructions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,23 @@ Environment Setup
The application requires some environmental arguments in order to run properly, these are illustrated in
the table below.

+------------- +-------------------------------+-------------------------------------+
| ENV | Default | Description |
+------------- +-------------------------------+-------------------------------------+
| `DB_HOST` | `postgresql://localhost:5432` | The URL for the PostgreSQL server. |
+------------- +-------------------------------+-------------------------------------+
| `DB_NAME` | `rems` | Name of the database. |
+------------- +-------------------------------+-------------------------------------+
| `DB_USER` | `rems` | Database username. |
+------------- +-------------------------------+-------------------------------------+
| `DB_PASS` | `rems` | Database password. |
+------------- +-------------------------------+-------------------------------------+
| `APP_HOST` | `0.0.0.0` | Default Host for the Web Server. |
+------------- +-------------------------------+-------------------------------------+
| `APP_PORT` | `8080` | Default port for the Web Server. |
+------------- +-------------------------------+-------------------------------------+
| `PUBLIC_KEY` | `None` | Mandatory api key. |
+------------- +-------------------------------+-------------------------------------+
| `DEBUG` | `True` | If set to `True`, logs all actions. |
+------------- +-------------------------------+-------------------------------------+
+-------------+-------------------------------+-----------------------------------------------+
| ENV | Default | Description |
+-------------+-------------------------------+-----------------------------------------------+
| `DB_HOST` | `postgresql://localhost:5432` | The URL for the PostgreSQL server. |
+-------------+-------------------------------+-----------------------------------------------+
| `DB_NAME` | `rems` | Name of the database. |
+-------------+-------------------------------+-----------------------------------------------+
| `DB_USER` | `rems` | Database username. |
+-------------+-------------------------------+-----------------------------------------------+
| `DB_PASS` | `rems` | Database password. |
+-------------+-------------------------------+-----------------------------------------------+
| `APP_HOST` | `0.0.0.0` | Default Host for the Web Server. |
+-------------+-------------------------------+-----------------------------------------------+
| `APP_PORT` | `8080` | Default port for the Web Server. |
+-------------+-------------------------------+-----------------------------------------------+
| `DEBUG` | `False` | If set to any string value, logs all actions. |
+-------------+-------------------------------+-----------------------------------------------+

Setting the necessary environment variables can be done e.g. via the command line:

Expand All @@ -39,7 +37,6 @@ Setting the necessary environment variables can be done e.g. via the command li
$ export DB_PASS=rems
$ export HOST=0.0.0.0
$ export PORT=8080
$ export PUBLIC_KEY=secret_string
$ export DEBUG=True

.. _app-setup:
Expand Down
25 changes: 7 additions & 18 deletions elixir_rems_proxy/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,10 @@ async def user_post(request):
LOG.debug('POST Request received.')
db_pool = request.app['pool']

missing_datasets = await process_post_request(request, db_pool)
processed_request = await process_post_request(request, db_pool)

if len(missing_datasets) == 0:
if processed_request:
return web.HTTPOk(text='Successful operation')
else:
return web.HTTPCreated(text=f'Following datasets are missing from REMS ({missing_datasets}), check "GET /user" endpoint for added permissions')


@routes.get('/user/')
Expand All @@ -47,16 +45,9 @@ async def user_get(request):
List all datasets user has access to.
"""
LOG.debug('GET Request received.')
user_identifier = None # username in REMS
user_identifier = None # ELIXIR id == REMS userid
db_pool = request.app['pool']

# try:
# # Optional query parameter, retrieved from /user/{user}?user_affiliation={organisation}
# # user_affiliation = request.query['user_affiliation'] # NOT IN USE
# except KeyError as key_error:
# LOG.debug(f'KeyError at optional key {key_error}, ignore and pass.')
# pass

if 'user' in request.match_info:
user_identifier = request.match_info['user']
processed_request = await process_get_request(user_identifier, db_pool)
Expand All @@ -72,18 +63,16 @@ async def user_get(request):
async def user_patch(request):
"""PATCH request to the /user endpoint.

Update dataset permissions for given user.
Update user details or dataset permissions for given user.
"""
LOG.debug('PATCH Request received.')
db_pool = request.app['pool']

if 'user' in request.match_info:
user_identifier = request.match_info['user']
processed_request = await process_patch_request(user_identifier, request, db_pool)
if len(processed_request) == 0 or processed_request is True:
return web.HTTPOk(text='Successful operation')
else:
return web.HTTPCreated(text=f'Following datasets are missing from REMS ({processed_request}), check "GET /user" endpoint for permissions')
if processed_request:
return web.HTTPNoContent()
else:
raise web.HTTPBadRequest(text='Username not provided')

Expand All @@ -96,7 +85,7 @@ async def user_delete(request):
Delete user.
"""
LOG.debug('DELETE Request received.')
user_identifier = None # username in REMS
user_identifier = None # ELIXIR id == REMS userid
db_pool = request.app['pool']

if 'user' in request.match_info:
Expand Down
Loading