Skip to content

Commit 7f7a58a

Browse files
committed
Add Validation to gwlf-e/run Endpoint
Make sure `input` and `job_uuid` are not specified together, and that `input` has all the required valid keys to run the modeling. We are not validating the value of the input in /run/ since there are more than 400 keys in the input object. A follow-up issue will be added to call out specific missing keys from the payload when checking the `input` of `gwlf-e/run/`
1 parent 24617e0 commit 7f7a58a

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

src/mmw/apps/geoprocessing_api/validation.py

+17
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,18 @@ def validate_gwlfe_prepare(data):
102102
raise ValidationError(error)
103103

104104

105+
def validate_gwlfe_run(input, job_uuid):
106+
if not check_gwlfe_only_one([input, job_uuid]):
107+
error = ('Invalid parameter: Only one type of prepared input'
108+
'(input JSON or job_uuid) is allowed')
109+
raise ValidationError(error)
110+
111+
if not check_gwlfe_run_input(input):
112+
error = ("Invalid input: Please use the full result "
113+
"of gwlf-e/prepare endpoint's result object")
114+
raise ValidationError(error)
115+
116+
105117
def check_gwlfe_only_one(params):
106118
if sum(map(check_is_none, params)) == 1:
107119
return True
@@ -132,6 +144,11 @@ def check_streams_layer_overrides(layers):
132144
return layers['__STREAMS__'] in STREAM_LAYER_OVERRIDES
133145

134146

147+
def check_gwlfe_run_input(input):
148+
result = all(el in input for el in settings.GWLFE_DEFAULTS.keys())
149+
return result
150+
151+
135152
def create_layer_overrides_keys_not_valid_msg(layers):
136153
error = 'These layers are not standard layers for layer overrides: '
137154
for layler in layers:

src/mmw/apps/geoprocessing_api/views.py

+7-4
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@
4545

4646
from apps.geoprocessing_api.validation import (validate_rwd,
4747
validate_uuid,
48-
validate_gwlfe_prepare)
48+
validate_gwlfe_prepare,
49+
validate_gwlfe_run)
4950

5051

5152
@swagger_auto_schema(method='post',
@@ -1707,11 +1708,12 @@ def _parse_gwlfe_input(request, raw_input=True):
17071708
model_input = request.data.get('input')
17081709

17091710
if model_input:
1710-
# TODO #3484 Validate model_input
1711+
validate_gwlfe_run(model_input, job_uuid)
17111712
return model_input, job_uuid, mods, hash
17121713

17131714
if not job_uuid:
1714-
raise ValidationError('`job_uuid` must be specified')
1715+
raise ValidationError('Either `input` or `job_uuid` '
1716+
'must be specified.')
17151717

17161718
if not validate_uuid(job_uuid):
17171719
raise ValidationError(f'Invalid `job_uuid`: {job_uuid}')
@@ -1727,5 +1729,6 @@ def _parse_gwlfe_input(request, raw_input=True):
17271729

17281730
model_input = json.loads(input_job.result)
17291731

1730-
# TODO #3484 Validate model_input
1732+
validate_gwlfe_run(model_input, job_uuid)
1733+
17311734
return model_input, job_uuid, mods, hash

0 commit comments

Comments
 (0)