Skip to content

Commit

Permalink
Assert db_connection format
Browse files Browse the repository at this point in the history
  • Loading branch information
index-git committed Jan 11, 2023
1 parent 0a629e7 commit 481210d
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/layman/layer/rest_workspace_layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,19 @@ def post(workspace):
db_connection_string = request.form.get('db_connection', '')
db_connection = db_util.parse_connection_string(db_connection_string) if db_connection_string else None

if db_connection:
if any(not db_connection.get(item) for item in ['url', 'table', 'geo_column']):
raise LaymanError(2, {
'parameter': 'db_connection',
'message': 'Parameter `db_connection` is expected to have `url` part and `table` and `geo_column` query parameters',
'expected': 'postgresql://<username>:<password>@<host>:<port>/dbname?table=<table_name>&geo_column=<geo_column_name>',
'found': {
'url': db_connection.get('url'),
'table': db_connection.get('table'),
'geo_column': db_connection.get('geo_column'),
}
})

if not input_files and not db_connection:
raise LaymanError(1, {
'parameters': ['file', 'db_connection'],
Expand Down
25 changes: 25 additions & 0 deletions tests/dynamic_data/publications/wrong_input/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1379,6 +1379,31 @@
},
},
},
'partial_db_connect': {
KEY_PUBLICATION_TYPE: process_client.LAYER_TYPE,
KEY_ACTION_PARAMS: {
'db_connection': 'db_connection',
'compress': False,
'with_chunks': False,
},
consts.KEY_EXCEPTION: LaymanError,
KEY_EXPECTED_EXCEPTION: {
KEY_DEFAULT: {'http_code': 400,
'sync': True,
'code': 2,
'message': 'Wrong parameter value',
'detail': {
'parameter': 'db_connection',
'message': 'Parameter `db_connection` is expected to have `url` part and `table` and `geo_column` query parameters',
'expected': 'postgresql://<username>:<password>@<host>:<port>/dbname?table=<table_name>&geo_column=<geo_column_name>',
'found': {
'url': 'db_connection',
'table': None,
'geo_column': None,
}},
},
},
},
}

VALIDATION_PATCH_ACTION = {
Expand Down

0 comments on commit 481210d

Please sign in to comment.