summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZuul <zuul@review.openstack.org>2019-01-09 22:20:40 +0000
committerGerrit Code Review <review@openstack.org>2019-01-09 22:20:40 +0000
commit78090dee690954e83cf242d488380af013c1def6 (patch)
tree7cbdb5cab52c5c2e882a76083a1097665255192f
parent359b89de3ff105c78aec189650d2feabfbb07ae8 (diff)
parent7105a891c23ca066d87f68e07a7098ea692ca112 (diff)
Merge "APIv2 - Fix 500 on malformed query string on"
-rw-r--r--sahara/api/v2/cluster_templates.py6
-rw-r--r--sahara/api/v2/clusters.py6
-rw-r--r--sahara/api/v2/data_sources.py5
-rw-r--r--sahara/api/v2/images.py7
-rw-r--r--sahara/api/v2/job_binaries.py6
-rw-r--r--sahara/api/v2/job_templates.py6
-rw-r--r--sahara/api/v2/job_types.py2
-rw-r--r--sahara/api/v2/jobs.py5
-rw-r--r--sahara/api/v2/node_group_templates.py6
-rw-r--r--sahara/api/v2/plugins.py4
-rw-r--r--sahara/service/validation.py19
-rw-r--r--sahara/utils/api.py12
12 files changed, 84 insertions, 0 deletions
diff --git a/sahara/api/v2/cluster_templates.py b/sahara/api/v2/cluster_templates.py
index 466ca86..bfcc895 100644
--- a/sahara/api/v2/cluster_templates.py
+++ b/sahara/api/v2/cluster_templates.py
@@ -29,6 +29,7 @@ rest = u.RestV2('cluster-templates', __name__)
29@v.check_exists(api.get_cluster_template, 'marker') 29@v.check_exists(api.get_cluster_template, 'marker')
30@v.validate(None, v.validate_pagination_limit, 30@v.validate(None, v.validate_pagination_limit,
31 v.validate_sorting_cluster_templates) 31 v.validate_sorting_cluster_templates)
32@v.validate_request_params(['plugin_name', 'hadoop_version', 'name'])
32def cluster_templates_list(): 33def cluster_templates_list():
33 result = api.get_cluster_templates(**u.get_request_args().to_dict()) 34 result = api.get_cluster_templates(**u.get_request_args().to_dict())
34 for ct in result: 35 for ct in result:
@@ -41,6 +42,7 @@ def cluster_templates_list():
41@acl.enforce("data-processing:cluster-templates:create") 42@acl.enforce("data-processing:cluster-templates:create")
42@v.validate(ct_schema.CLUSTER_TEMPLATE_SCHEMA_V2, 43@v.validate(ct_schema.CLUSTER_TEMPLATE_SCHEMA_V2,
43 v_ct.check_cluster_template_create) 44 v_ct.check_cluster_template_create)
45@v.validate_request_params([])
44def cluster_templates_create(data): 46def cluster_templates_create(data):
45 # renaming hadoop_version -> plugin_version 47 # renaming hadoop_version -> plugin_version
46 # this can be removed once APIv1 is deprecated 48 # this can be removed once APIv1 is deprecated
@@ -55,6 +57,7 @@ def cluster_templates_create(data):
55@rest.get('/cluster-templates/<cluster_template_id>') 57@rest.get('/cluster-templates/<cluster_template_id>')
56@acl.enforce("data-processing:cluster-templates:get") 58@acl.enforce("data-processing:cluster-templates:get")
57@v.check_exists(api.get_cluster_template, 'cluster_template_id') 59@v.check_exists(api.get_cluster_template, 'cluster_template_id')
60@v.validate_request_params([])
58def cluster_templates_get(cluster_template_id): 61def cluster_templates_get(cluster_template_id):
59 result = u.to_wrapped_dict_no_render( 62 result = u.to_wrapped_dict_no_render(
60 api.get_cluster_template, cluster_template_id) 63 api.get_cluster_template, cluster_template_id)
@@ -68,6 +71,7 @@ def cluster_templates_get(cluster_template_id):
68@v.check_exists(api.get_cluster_template, 'cluster_template_id') 71@v.check_exists(api.get_cluster_template, 'cluster_template_id')
69@v.validate(ct_schema.CLUSTER_TEMPLATE_UPDATE_SCHEMA_V2, 72@v.validate(ct_schema.CLUSTER_TEMPLATE_UPDATE_SCHEMA_V2,
70 v_ct.check_cluster_template_update) 73 v_ct.check_cluster_template_update)
74@v.validate_request_params([])
71def cluster_templates_update(cluster_template_id, data): 75def cluster_templates_update(cluster_template_id, data):
72 if data.get('plugin_version', None): 76 if data.get('plugin_version', None):
73 data['hadoop_version'] = data['plugin_version'] 77 data['hadoop_version'] = data['plugin_version']
@@ -83,6 +87,7 @@ def cluster_templates_update(cluster_template_id, data):
83@acl.enforce("data-processing:cluster-templates:delete") 87@acl.enforce("data-processing:cluster-templates:delete")
84@v.check_exists(api.get_cluster_template, 'cluster_template_id') 88@v.check_exists(api.get_cluster_template, 'cluster_template_id')
85@v.validate(None, v_ct.check_cluster_template_usage) 89@v.validate(None, v_ct.check_cluster_template_usage)
90@v.validate_request_params([])
86def cluster_templates_delete(cluster_template_id): 91def cluster_templates_delete(cluster_template_id):
87 api.terminate_cluster_template(cluster_template_id) 92 api.terminate_cluster_template(cluster_template_id)
88 return u.render() 93 return u.render()
@@ -101,6 +106,7 @@ def _cluster_template_export_helper(template):
101@rest.get('/cluster-templates/<cluster_template_id>/export') 106@rest.get('/cluster-templates/<cluster_template_id>/export')
102@acl.enforce("data-processing:cluster-templates:get") 107@acl.enforce("data-processing:cluster-templates:get")
103@v.check_exists(api.get_cluster_template, 'cluster_template_id') 108@v.check_exists(api.get_cluster_template, 'cluster_template_id')
109@v.validate_request_params([])
104def cluster_template_export(cluster_template_id): 110def cluster_template_export(cluster_template_id):
105 content = u.to_wrapped_dict_no_render( 111 content = u.to_wrapped_dict_no_render(
106 api.export_cluster_template, cluster_template_id) 112 api.export_cluster_template, cluster_template_id)
diff --git a/sahara/api/v2/clusters.py b/sahara/api/v2/clusters.py
index c44b4bf..79035c2 100644
--- a/sahara/api/v2/clusters.py
+++ b/sahara/api/v2/clusters.py
@@ -31,6 +31,7 @@ rest = u.RestV2('clusters', __name__)
31@acl.enforce("data-processing:clusters:get_all") 31@acl.enforce("data-processing:clusters:get_all")
32@v.check_exists(api.get_cluster, 'marker') 32@v.check_exists(api.get_cluster, 'marker')
33@v.validate(None, v.validate_pagination_limit) 33@v.validate(None, v.validate_pagination_limit)
34@v.validate_request_params(['plugin_name', 'hadoop_version', 'name'])
34def clusters_list(): 35def clusters_list():
35 result = api.get_clusters(**u.get_request_args().to_dict()) 36 result = api.get_clusters(**u.get_request_args().to_dict())
36 for c in result: 37 for c in result:
@@ -43,6 +44,7 @@ def clusters_list():
43@acl.enforce("data-processing:clusters:create") 44@acl.enforce("data-processing:clusters:create")
44@v.validate(v_c_schema.CLUSTER_SCHEMA_V2, 45@v.validate(v_c_schema.CLUSTER_SCHEMA_V2,
45 v_c.check_one_or_multiple_clusters_create) 46 v_c.check_one_or_multiple_clusters_create)
47@v.validate_request_params([])
46def clusters_create(data): 48def clusters_create(data):
47 # renaming hadoop_version -> plugin_version 49 # renaming hadoop_version -> plugin_version
48 # this can be removed once APIv1 is deprecated 50 # this can be removed once APIv1 is deprecated
@@ -65,6 +67,7 @@ def clusters_create(data):
65@acl.enforce("data-processing:clusters:scale") 67@acl.enforce("data-processing:clusters:scale")
66@v.check_exists(api.get_cluster, 'cluster_id') 68@v.check_exists(api.get_cluster, 'cluster_id')
67@v.validate(v_c_schema.CLUSTER_SCALING_SCHEMA_V2, v_c_s.check_cluster_scaling) 69@v.validate(v_c_schema.CLUSTER_SCALING_SCHEMA_V2, v_c_s.check_cluster_scaling)
70@v.validate_request_params([])
68def clusters_scale(cluster_id, data): 71def clusters_scale(cluster_id, data):
69 result = u.to_wrapped_dict_no_render( 72 result = u.to_wrapped_dict_no_render(
70 api.scale_cluster, cluster_id, data) 73 api.scale_cluster, cluster_id, data)
@@ -76,6 +79,7 @@ def clusters_scale(cluster_id, data):
76@rest.get('/clusters/<cluster_id>') 79@rest.get('/clusters/<cluster_id>')
77@acl.enforce("data-processing:clusters:get") 80@acl.enforce("data-processing:clusters:get")
78@v.check_exists(api.get_cluster, 'cluster_id') 81@v.check_exists(api.get_cluster, 'cluster_id')
82@v.validate_request_params([])
79def clusters_get(cluster_id): 83def clusters_get(cluster_id):
80 data = u.get_request_args() 84 data = u.get_request_args()
81 show_events = six.text_type( 85 show_events = six.text_type(
@@ -91,6 +95,7 @@ def clusters_get(cluster_id):
91@acl.enforce("data-processing:clusters:modify") 95@acl.enforce("data-processing:clusters:modify")
92@v.check_exists(api.get_cluster, 'cluster_id') 96@v.check_exists(api.get_cluster, 'cluster_id')
93@v.validate(v_c_schema.CLUSTER_UPDATE_SCHEMA, v_c.check_cluster_update) 97@v.validate(v_c_schema.CLUSTER_UPDATE_SCHEMA, v_c.check_cluster_update)
98@v.validate_request_params([])
94def clusters_update(cluster_id, data): 99def clusters_update(cluster_id, data):
95 result = u.to_wrapped_dict_no_render( 100 result = u.to_wrapped_dict_no_render(
96 api.update_cluster, cluster_id, data) 101 api.update_cluster, cluster_id, data)
@@ -103,6 +108,7 @@ def clusters_update(cluster_id, data):
103@acl.enforce("data-processing:clusters:delete") 108@acl.enforce("data-processing:clusters:delete")
104@v.check_exists(api.get_cluster, 'cluster_id') 109@v.check_exists(api.get_cluster, 'cluster_id')
105@v.validate(v_c_schema.CLUSTER_DELETE_SCHEMA_V2, v_c.check_cluster_delete) 110@v.validate(v_c_schema.CLUSTER_DELETE_SCHEMA_V2, v_c.check_cluster_delete)
111@v.validate_request_params([])
106def clusters_delete(cluster_id): 112def clusters_delete(cluster_id):
107 data = u.request_data() 113 data = u.request_data()
108 force = data.get('force', False) 114 force = data.get('force', False)
diff --git a/sahara/api/v2/data_sources.py b/sahara/api/v2/data_sources.py
index 860e530..476254a 100644
--- a/sahara/api/v2/data_sources.py
+++ b/sahara/api/v2/data_sources.py
@@ -29,6 +29,7 @@ rest = u.RestV2('data-sources', __name__)
29@v.check_exists(api.get_data_source, 'marker') 29@v.check_exists(api.get_data_source, 'marker')
30@v.validate(None, v.validate_pagination_limit, 30@v.validate(None, v.validate_pagination_limit,
31 v.validate_sorting_data_sources) 31 v.validate_sorting_data_sources)
32@v.validate_request_params(['type'])
32def data_sources_list(): 33def data_sources_list():
33 result = api.get_data_sources(**u.get_request_args().to_dict()) 34 result = api.get_data_sources(**u.get_request_args().to_dict())
34 for ds in result: 35 for ds in result:
@@ -39,6 +40,7 @@ def data_sources_list():
39@rest.post('/data-sources') 40@rest.post('/data-sources')
40@acl.enforce("data-processing:data-sources:register") 41@acl.enforce("data-processing:data-sources:register")
41@v.validate(v_d_s_schema.DATA_SOURCE_SCHEMA, v_d_s.check_data_source_create) 42@v.validate(v_d_s_schema.DATA_SOURCE_SCHEMA, v_d_s.check_data_source_create)
43@v.validate_request_params([])
42def data_source_register(data): 44def data_source_register(data):
43 result = api.register_data_source(data).to_wrapped_dict() 45 result = api.register_data_source(data).to_wrapped_dict()
44 u._replace_tenant_id_project_id(result['data_source']) 46 u._replace_tenant_id_project_id(result['data_source'])
@@ -48,6 +50,7 @@ def data_source_register(data):
48@rest.get('/data-sources/<data_source_id>') 50@rest.get('/data-sources/<data_source_id>')
49@acl.enforce("data-processing:data-sources:get") 51@acl.enforce("data-processing:data-sources:get")
50@v.check_exists(api.get_data_source, 'data_source_id') 52@v.check_exists(api.get_data_source, 'data_source_id')
53@v.validate_request_params([])
51def data_source_get(data_source_id): 54def data_source_get(data_source_id):
52 result = u.to_wrapped_dict(api.get_data_source, data_source_id) 55 result = u.to_wrapped_dict(api.get_data_source, data_source_id)
53 u._replace_tenant_id_project_id(result['data_source']) 56 u._replace_tenant_id_project_id(result['data_source'])
@@ -57,6 +60,7 @@ def data_source_get(data_source_id):
57@rest.delete('/data-sources/<data_source_id>') 60@rest.delete('/data-sources/<data_source_id>')
58@acl.enforce("data-processing:data-sources:delete") 61@acl.enforce("data-processing:data-sources:delete")
59@v.check_exists(api.get_data_source, 'data_source_id') 62@v.check_exists(api.get_data_source, 'data_source_id')
63@v.validate_request_params([])
60def data_source_delete(data_source_id): 64def data_source_delete(data_source_id):
61 api.delete_data_source(data_source_id) 65 api.delete_data_source(data_source_id)
62 return u.render() 66 return u.render()
@@ -66,6 +70,7 @@ def data_source_delete(data_source_id):
66@acl.enforce("data-processing:data-sources:modify") 70@acl.enforce("data-processing:data-sources:modify")
67@v.check_exists(api.get_data_source, 'data_source_id') 71@v.check_exists(api.get_data_source, 'data_source_id')
68@v.validate(v_d_s_schema.DATA_SOURCE_UPDATE_SCHEMA) 72@v.validate(v_d_s_schema.DATA_SOURCE_UPDATE_SCHEMA)
73@v.validate_request_params([])
69def data_source_update(data_source_id, data): 74def data_source_update(data_source_id, data):
70 result = u.to_wrapped_dict(api.data_source_update, data_source_id, data) 75 result = u.to_wrapped_dict(api.data_source_update, data_source_id, data)
71 u._replace_tenant_id_project_id(result['data_source']) 76 u._replace_tenant_id_project_id(result['data_source'])
diff --git a/sahara/api/v2/images.py b/sahara/api/v2/images.py
index 1d3d6f9..1cced90 100644
--- a/sahara/api/v2/images.py
+++ b/sahara/api/v2/images.py
@@ -25,6 +25,7 @@ rest = u.RestV2('images', __name__)
25 25
26@rest.get('/images') 26@rest.get('/images')
27@acl.enforce("data-processing:images:get_all") 27@acl.enforce("data-processing:images:get_all")
28@v.validate_request_params(['name', 'tags', 'username'])
28def images_list(): 29def images_list():
29 tags = u.get_request_args().getlist('tags') 30 tags = u.get_request_args().getlist('tags')
30 name = u.get_request_args().get('name', None) 31 name = u.get_request_args().get('name', None)
@@ -34,6 +35,7 @@ def images_list():
34@rest.get('/images/<image_id>') 35@rest.get('/images/<image_id>')
35@acl.enforce("data-processing:images:get") 36@acl.enforce("data-processing:images:get")
36@v.check_exists(api.get_image, id='image_id') 37@v.check_exists(api.get_image, id='image_id')
38@v.validate_request_params([])
37def images_get(image_id): 39def images_get(image_id):
38 return u.render(api.get_registered_image(id=image_id).wrapped_dict) 40 return u.render(api.get_registered_image(id=image_id).wrapped_dict)
39 41
@@ -42,6 +44,7 @@ def images_get(image_id):
42@acl.enforce("data-processing:images:register") 44@acl.enforce("data-processing:images:register")
43@v.check_exists(api.get_image, id='image_id') 45@v.check_exists(api.get_image, id='image_id')
44@v.validate(v_images.image_register_schema, v_images.check_image_register) 46@v.validate(v_images.image_register_schema, v_images.check_image_register)
47@v.validate_request_params([])
45def images_set(image_id, data): 48def images_set(image_id, data):
46 return u.render(api.register_image(image_id, **data).wrapped_dict) 49 return u.render(api.register_image(image_id, **data).wrapped_dict)
47 50
@@ -49,6 +52,7 @@ def images_set(image_id, data):
49@rest.delete('/images/<image_id>') 52@rest.delete('/images/<image_id>')
50@acl.enforce("data-processing:images:unregister") 53@acl.enforce("data-processing:images:unregister")
51@v.check_exists(api.get_image, id='image_id') 54@v.check_exists(api.get_image, id='image_id')
55@v.validate_request_params([])
52def images_unset(image_id): 56def images_unset(image_id):
53 api.unregister_image(image_id) 57 api.unregister_image(image_id)
54 return u.render() 58 return u.render()
@@ -57,6 +61,7 @@ def images_unset(image_id):
57@rest.get('/images/<image_id>/tags') 61@rest.get('/images/<image_id>/tags')
58@acl.enforce("data-processing:images:get_tags") 62@acl.enforce("data-processing:images:get_tags")
59@v.check_exists(api.get_image, id='image_id') 63@v.check_exists(api.get_image, id='image_id')
64@v.validate_request_params([])
60def image_tags_get(image_id): 65def image_tags_get(image_id):
61 return u.render(api.get_image_tags(image_id)) 66 return u.render(api.get_image_tags(image_id))
62 67
@@ -65,6 +70,7 @@ def image_tags_get(image_id):
65@acl.enforce("data-processing:images:set_tags") 70@acl.enforce("data-processing:images:set_tags")
66@v.check_exists(api.get_image, id='image_id') 71@v.check_exists(api.get_image, id='image_id')
67@v.validate(v_images.image_tags_schema, v_images.check_tags) 72@v.validate(v_images.image_tags_schema, v_images.check_tags)
73@v.validate_request_params([])
68def image_tags_update(image_id, data): 74def image_tags_update(image_id, data):
69 return u.render(api.set_image_tags(image_id, **data).wrapped_dict) 75 return u.render(api.set_image_tags(image_id, **data).wrapped_dict)
70 76
@@ -72,6 +78,7 @@ def image_tags_update(image_id, data):
72@rest.delete('/images/<image_id>/tags') 78@rest.delete('/images/<image_id>/tags')
73@acl.enforce("data-processing:images:remove_tags") 79@acl.enforce("data-processing:images:remove_tags")
74@v.check_exists(api.get_image, id='image_id') 80@v.check_exists(api.get_image, id='image_id')
81@v.validate_request_params([])
75def image_tags_delete(image_id): 82def image_tags_delete(image_id):
76 api.remove_image_tags(image_id) 83 api.remove_image_tags(image_id)
77 return u.render() 84 return u.render()
diff --git a/sahara/api/v2/job_binaries.py b/sahara/api/v2/job_binaries.py
index d50f13a..396fd8d 100644
--- a/sahara/api/v2/job_binaries.py
+++ b/sahara/api/v2/job_binaries.py
@@ -27,6 +27,7 @@ rest = u.RestV2('job-binaries', __name__)
27@rest.post('/job-binaries') 27@rest.post('/job-binaries')
28@acl.enforce("data-processing:job-binaries:create") 28@acl.enforce("data-processing:job-binaries:create")
29@v.validate(v_j_b_schema.JOB_BINARY_SCHEMA, v_j_b.check_job_binary) 29@v.validate(v_j_b_schema.JOB_BINARY_SCHEMA, v_j_b.check_job_binary)
30@v.validate_request_params([])
30def job_binary_create(data): 31def job_binary_create(data):
31 result = api.create_job_binary(data).to_wrapped_dict() 32 result = api.create_job_binary(data).to_wrapped_dict()
32 u._replace_tenant_id_project_id(result['job_binary']) 33 u._replace_tenant_id_project_id(result['job_binary'])
@@ -38,6 +39,7 @@ def job_binary_create(data):
38@v.check_exists(api.get_job_binary, 'marker') 39@v.check_exists(api.get_job_binary, 'marker')
39@v.validate(None, v.validate_pagination_limit, 40@v.validate(None, v.validate_pagination_limit,
40 v.validate_sorting_job_binaries) 41 v.validate_sorting_job_binaries)
42@v.validate_request_params(['name'])
41def job_binary_list(): 43def job_binary_list():
42 result = api.get_job_binaries(**u.get_request_args().to_dict()) 44 result = api.get_job_binaries(**u.get_request_args().to_dict())
43 for jb in result: 45 for jb in result:
@@ -48,6 +50,7 @@ def job_binary_list():
48@rest.get('/job-binaries/<job_binary_id>') 50@rest.get('/job-binaries/<job_binary_id>')
49@acl.enforce("data-processing:job-binaries:get") 51@acl.enforce("data-processing:job-binaries:get")
50@v.check_exists(api.get_job_binary, 'job_binary_id') 52@v.check_exists(api.get_job_binary, 'job_binary_id')
53@v.validate_request_params([])
51def job_binary_get(job_binary_id): 54def job_binary_get(job_binary_id):
52 result = api.get_job_binary(job_binary_id).to_wrapped_dict() 55 result = api.get_job_binary(job_binary_id).to_wrapped_dict()
53 u._replace_tenant_id_project_id(result['job_binary']) 56 u._replace_tenant_id_project_id(result['job_binary'])
@@ -57,6 +60,7 @@ def job_binary_get(job_binary_id):
57@rest.delete('/job-binaries/<job_binary_id>') 60@rest.delete('/job-binaries/<job_binary_id>')
58@acl.enforce("data-processing:job-binaries:delete") 61@acl.enforce("data-processing:job-binaries:delete")
59@v.check_exists(api.get_job_binary, id='job_binary_id') 62@v.check_exists(api.get_job_binary, id='job_binary_id')
63@v.validate_request_params([])
60def job_binary_delete(job_binary_id): 64def job_binary_delete(job_binary_id):
61 api.delete_job_binary(job_binary_id) 65 api.delete_job_binary(job_binary_id)
62 return u.render() 66 return u.render()
@@ -65,6 +69,7 @@ def job_binary_delete(job_binary_id):
65@rest.get('/job-binaries/<job_binary_id>/data') 69@rest.get('/job-binaries/<job_binary_id>/data')
66@acl.enforce("data-processing:job-binaries:get_data") 70@acl.enforce("data-processing:job-binaries:get_data")
67@v.check_exists(api.get_job_binary, 'job_binary_id') 71@v.check_exists(api.get_job_binary, 'job_binary_id')
72@v.validate_request_params([])
68def job_binary_data(job_binary_id): 73def job_binary_data(job_binary_id):
69 data = api.get_job_binary_data(job_binary_id) 74 data = api.get_job_binary_data(job_binary_id)
70 if type(data) == dict: 75 if type(data) == dict:
@@ -75,6 +80,7 @@ def job_binary_data(job_binary_id):
75@rest.patch('/job-binaries/<job_binary_id>') 80@rest.patch('/job-binaries/<job_binary_id>')
76@acl.enforce("data-processing:job-binaries:modify") 81@acl.enforce("data-processing:job-binaries:modify")
77@v.validate(v_j_b_schema.JOB_BINARY_UPDATE_SCHEMA, v_j_b.check_job_binary) 82@v.validate(v_j_b_schema.JOB_BINARY_UPDATE_SCHEMA, v_j_b.check_job_binary)
83@v.validate_request_params([])
78def job_binary_update(job_binary_id, data): 84def job_binary_update(job_binary_id, data):
79 result = api.update_job_binary(job_binary_id, data).to_wrapped_dict() 85 result = api.update_job_binary(job_binary_id, data).to_wrapped_dict()
80 u._replace_tenant_id_project_id(result['job_binary']) 86 u._replace_tenant_id_project_id(result['job_binary'])
diff --git a/sahara/api/v2/job_templates.py b/sahara/api/v2/job_templates.py
index 3cf69ab..6ac5ebc 100644
--- a/sahara/api/v2/job_templates.py
+++ b/sahara/api/v2/job_templates.py
@@ -29,6 +29,7 @@ rest = u.RestV2('job-templates', __name__)
29@v.check_exists(api.get_job_templates, 'marker') 29@v.check_exists(api.get_job_templates, 'marker')
30@v.validate(None, v.validate_pagination_limit, 30@v.validate(None, v.validate_pagination_limit,
31 v.validate_sorting_jobs) 31 v.validate_sorting_jobs)
32@v.validate_request_params(['type', 'name'])
32def job_templates_list(): 33def job_templates_list():
33 result = api.get_job_templates(**u.get_request_args().to_dict()) 34 result = api.get_job_templates(**u.get_request_args().to_dict())
34 for jt in result: 35 for jt in result:
@@ -39,6 +40,7 @@ def job_templates_list():
39@rest.post('/job-templates') 40@rest.post('/job-templates')
40@acl.enforce("data-processing:job-templates:create") 41@acl.enforce("data-processing:job-templates:create")
41@v.validate(v_j_schema.JOB_SCHEMA, v_j.check_mains_libs, v_j.check_interface) 42@v.validate(v_j_schema.JOB_SCHEMA, v_j.check_mains_libs, v_j.check_interface)
43@v.validate_request_params([])
42def job_templates_create(data): 44def job_templates_create(data):
43 result = {'job_template': api.create_job_template(data).to_dict()} 45 result = {'job_template': api.create_job_template(data).to_dict()}
44 u._replace_tenant_id_project_id(result['job_template']) 46 u._replace_tenant_id_project_id(result['job_template'])
@@ -48,6 +50,7 @@ def job_templates_create(data):
48@rest.get('/job-templates/<job_templates_id>') 50@rest.get('/job-templates/<job_templates_id>')
49@acl.enforce("data-processing:job-templates:get") 51@acl.enforce("data-processing:job-templates:get")
50@v.check_exists(api.get_job_templates, id='job_templates_id') 52@v.check_exists(api.get_job_templates, id='job_templates_id')
53@v.validate_request_params([])
51def job_templates_get(job_templates_id): 54def job_templates_get(job_templates_id):
52 result = {'job_template': api.get_job_template( 55 result = {'job_template': api.get_job_template(
53 job_templates_id).to_dict()} 56 job_templates_id).to_dict()}
@@ -59,6 +62,7 @@ def job_templates_get(job_templates_id):
59@acl.enforce("data-processing:jobs:modify") 62@acl.enforce("data-processing:jobs:modify")
60@v.check_exists(api.get_job_templates, id='job_templates_id') 63@v.check_exists(api.get_job_templates, id='job_templates_id')
61@v.validate(v_j_schema.JOB_UPDATE_SCHEMA) 64@v.validate(v_j_schema.JOB_UPDATE_SCHEMA)
65@v.validate_request_params([])
62def job_templates_update(job_templates_id, data): 66def job_templates_update(job_templates_id, data):
63 result = {'job_template': api.update_job_template( 67 result = {'job_template': api.update_job_template(
64 job_templates_id, data).to_dict()} 68 job_templates_id, data).to_dict()}
@@ -69,6 +73,7 @@ def job_templates_update(job_templates_id, data):
69@rest.delete('/job-templates/<job_templates_id>') 73@rest.delete('/job-templates/<job_templates_id>')
70@acl.enforce("data-processing:jobs:delete") 74@acl.enforce("data-processing:jobs:delete")
71@v.check_exists(api.get_job_templates, id='job_templates_id') 75@v.check_exists(api.get_job_templates, id='job_templates_id')
76@v.validate_request_params([])
72def job_templates_delete(job_templates_id): 77def job_templates_delete(job_templates_id):
73 api.delete_job_template(job_templates_id) 78 api.delete_job_template(job_templates_id)
74 return u.render() 79 return u.render()
@@ -77,5 +82,6 @@ def job_templates_delete(job_templates_id):
77@rest.get('/job-templates/config-hints/<job_type>') 82@rest.get('/job-templates/config-hints/<job_type>')
78@acl.enforce("data-processing:jobs:get_config_hints") 83@acl.enforce("data-processing:jobs:get_config_hints")
79@v.check_exists(api.get_job_config_hints, job_type='job_type') 84@v.check_exists(api.get_job_config_hints, job_type='job_type')
85@v.validate_request_params([])
80def job_config_hints_get(job_type): 86def job_config_hints_get(job_type):
81 return u.render(api.get_job_config_hints(job_type)) 87 return u.render(api.get_job_config_hints(job_type))
diff --git a/sahara/api/v2/job_types.py b/sahara/api/v2/job_types.py
index aa9ef9e..5c81416 100644
--- a/sahara/api/v2/job_types.py
+++ b/sahara/api/v2/job_types.py
@@ -15,6 +15,7 @@
15 15
16from sahara.api import acl 16from sahara.api import acl
17from sahara.service.api.v2 import job_types as api 17from sahara.service.api.v2 import job_types as api
18from sahara.service import validation as v
18import sahara.utils.api as u 19import sahara.utils.api as u
19 20
20 21
@@ -23,6 +24,7 @@ rest = u.RestV2('job-types', __name__)
23 24
24@rest.get('/job-types') 25@rest.get('/job-types')
25@acl.enforce("data-processing:job-types:get_all") 26@acl.enforce("data-processing:job-types:get_all")
27@v.validate_request_params(['type', 'plugin_name', 'hadoop_version'])
26def job_types_get(): 28def job_types_get():
27 # We want to use flat=False with to_dict() so that 29 # We want to use flat=False with to_dict() so that
28 # the value of each arg is given as a list. This supports 30 # the value of each arg is given as a list. This supports
diff --git a/sahara/api/v2/jobs.py b/sahara/api/v2/jobs.py
index 0e85b31..7db59c1 100644
--- a/sahara/api/v2/jobs.py
+++ b/sahara/api/v2/jobs.py
@@ -31,6 +31,7 @@ rest = u.RestV2('jobs', __name__)
31@v.check_exists(api.get_job_execution, 'marker') 31@v.check_exists(api.get_job_execution, 'marker')
32@v.validate(None, v.validate_pagination_limit, 32@v.validate(None, v.validate_pagination_limit,
33 v.validate_sorting_job_executions) 33 v.validate_sorting_job_executions)
34@v.validate_request_params(['status'])
34def jobs_list(): 35def jobs_list():
35 result = api.job_execution_list(**u.get_request_args().to_dict()) 36 result = api.job_execution_list(**u.get_request_args().to_dict())
36 # APIv2: renaming oozie_job_id -> engine_job_id 37 # APIv2: renaming oozie_job_id -> engine_job_id
@@ -45,6 +46,7 @@ def jobs_list():
45@rest.post('/jobs') 46@rest.post('/jobs')
46@acl.enforce("data-processing:jobs:execute") 47@acl.enforce("data-processing:jobs:execute")
47@v.validate(v_j_e_schema.JOB_EXEC_SCHEMA_V2, v_j_e.check_job_execution) 48@v.validate(v_j_e_schema.JOB_EXEC_SCHEMA_V2, v_j_e.check_job_execution)
49@v.validate_request_params([])
48def jobs_execute(data): 50def jobs_execute(data):
49 result = {'job': api.execute_job(data)} 51 result = {'job': api.execute_job(data)}
50 dict.update(result['job'], 52 dict.update(result['job'],
@@ -57,6 +59,7 @@ def jobs_execute(data):
57@rest.get('/jobs/<job_id>') 59@rest.get('/jobs/<job_id>')
58@acl.enforce("data-processing:job-executions:get") 60@acl.enforce("data-processing:job-executions:get")
59@v.check_exists(api.get_job_execution, id='job_id') 61@v.check_exists(api.get_job_execution, id='job_id')
62@v.validate_request_params([])
60def jobs_get(job_id): 63def jobs_get(job_id):
61 data = u.get_request_args() 64 data = u.get_request_args()
62 refresh_status = six.text_type( 65 refresh_status = six.text_type(
@@ -72,6 +75,7 @@ def jobs_get(job_id):
72@v.check_exists(api.get_job_execution, id='job_id') 75@v.check_exists(api.get_job_execution, id='job_id')
73@v.validate( 76@v.validate(
74 v_j_e_schema.JOB_EXEC_UPDATE_SCHEMA, v_j_e.check_job_execution_update) 77 v_j_e_schema.JOB_EXEC_UPDATE_SCHEMA, v_j_e.check_job_execution_update)
78@v.validate_request_params([])
75def jobs_update(job_id, data): 79def jobs_update(job_id, data):
76 result = {'job': api.update_job_execution(job_id, data)} 80 result = {'job': api.update_job_execution(job_id, data)}
77 result['job'].pop('oozie_job_id', force=True) 81 result['job'].pop('oozie_job_id', force=True)
@@ -83,6 +87,7 @@ def jobs_update(job_id, data):
83@acl.enforce("data-processing:job-executions:delete") 87@acl.enforce("data-processing:job-executions:delete")
84@v.check_exists(api.get_job_execution, id='job_id') 88@v.check_exists(api.get_job_execution, id='job_id')
85@v.validate(None, v_j_e.check_job_execution_delete) 89@v.validate(None, v_j_e.check_job_execution_delete)
90@v.validate_request_params([])
86def jobs_delete(job_id): 91def jobs_delete(job_id):
87 api.delete_job_execution(job_id) 92 api.delete_job_execution(job_id)
88 return u.render() 93 return u.render()
diff --git a/sahara/api/v2/node_group_templates.py b/sahara/api/v2/node_group_templates.py
index 494f289..00cc435 100644
--- a/sahara/api/v2/node_group_templates.py
+++ b/sahara/api/v2/node_group_templates.py
@@ -30,6 +30,7 @@ rest = u.RestV2('node-group-templates', __name__)
30@v.check_exists(api.get_node_group_template, 'marker') 30@v.check_exists(api.get_node_group_template, 'marker')
31@v.validate(None, v.validate_pagination_limit, 31@v.validate(None, v.validate_pagination_limit,
32 v.validate_sorting_node_group_templates) 32 v.validate_sorting_node_group_templates)
33@v.validate_request_params(['plugin_name', 'hadoop_version', 'name'])
33def node_group_templates_list(): 34def node_group_templates_list():
34 result = api.get_node_group_templates(**u.get_request_args().to_dict()) 35 result = api.get_node_group_templates(**u.get_request_args().to_dict())
35 for ngt in result: 36 for ngt in result:
@@ -42,6 +43,7 @@ def node_group_templates_list():
42@acl.enforce("data-processing:node-group-templates:create") 43@acl.enforce("data-processing:node-group-templates:create")
43@v.validate(ngt_schema.NODE_GROUP_TEMPLATE_SCHEMA_V2, 44@v.validate(ngt_schema.NODE_GROUP_TEMPLATE_SCHEMA_V2,
44 v_ngt.check_node_group_template_create) 45 v_ngt.check_node_group_template_create)
46@v.validate_request_params([])
45def node_group_templates_create(data): 47def node_group_templates_create(data):
46 # renaming hadoop_version -> plugin_version 48 # renaming hadoop_version -> plugin_version
47 # this can be removed once APIv1 is deprecated 49 # this can be removed once APIv1 is deprecated
@@ -56,6 +58,7 @@ def node_group_templates_create(data):
56@rest.get('/node-group-templates/<node_group_template_id>') 58@rest.get('/node-group-templates/<node_group_template_id>')
57@acl.enforce("data-processing:node-group-templates:get") 59@acl.enforce("data-processing:node-group-templates:get")
58@v.check_exists(api.get_node_group_template, 'node_group_template_id') 60@v.check_exists(api.get_node_group_template, 'node_group_template_id')
61@v.validate_request_params([])
59def node_group_templates_get(node_group_template_id): 62def node_group_templates_get(node_group_template_id):
60 result = u.to_wrapped_dict_no_render( 63 result = u.to_wrapped_dict_no_render(
61 api.get_node_group_template, node_group_template_id) 64 api.get_node_group_template, node_group_template_id)
@@ -69,6 +72,7 @@ def node_group_templates_get(node_group_template_id):
69@v.check_exists(api.get_node_group_template, 'node_group_template_id') 72@v.check_exists(api.get_node_group_template, 'node_group_template_id')
70@v.validate(ngt_schema.NODE_GROUP_TEMPLATE_UPDATE_SCHEMA_V2, 73@v.validate(ngt_schema.NODE_GROUP_TEMPLATE_UPDATE_SCHEMA_V2,
71 v_ngt.check_node_group_template_update) 74 v_ngt.check_node_group_template_update)
75@v.validate_request_params([])
72def node_group_templates_update(node_group_template_id, data): 76def node_group_templates_update(node_group_template_id, data):
73 if data.get('plugin_version', None): 77 if data.get('plugin_version', None):
74 data['hadoop_version'] = data['plugin_version'] 78 data['hadoop_version'] = data['plugin_version']
@@ -84,6 +88,7 @@ def node_group_templates_update(node_group_template_id, data):
84@acl.enforce("data-processing:node-group-templates:delete") 88@acl.enforce("data-processing:node-group-templates:delete")
85@v.check_exists(api.get_node_group_template, 'node_group_template_id') 89@v.check_exists(api.get_node_group_template, 'node_group_template_id')
86@v.validate(None, v_ngt.check_node_group_template_usage) 90@v.validate(None, v_ngt.check_node_group_template_usage)
91@v.validate_request_params([])
87def node_group_templates_delete(node_group_template_id): 92def node_group_templates_delete(node_group_template_id):
88 api.terminate_node_group_template(node_group_template_id) 93 api.terminate_node_group_template(node_group_template_id)
89 return u.render() 94 return u.render()
@@ -104,6 +109,7 @@ def _node_group_template_export_helper(template):
104@rest.get('/node-group-templates/<node_group_template_id>/export') 109@rest.get('/node-group-templates/<node_group_template_id>/export')
105@acl.enforce("data-processing:node-group-templates:get") 110@acl.enforce("data-processing:node-group-templates:get")
106@v.check_exists(api.get_node_group_template, 'node_group_template_id') 111@v.check_exists(api.get_node_group_template, 'node_group_template_id')
112@v.validate_request_params([])
107def node_group_template_export(node_group_template_id): 113def node_group_template_export(node_group_template_id):
108 content = u.to_wrapped_dict_no_render( 114 content = u.to_wrapped_dict_no_render(
109 api.export_node_group_template, node_group_template_id) 115 api.export_node_group_template, node_group_template_id)
diff --git a/sahara/api/v2/plugins.py b/sahara/api/v2/plugins.py
index f6f9434..e9ef4d8 100644
--- a/sahara/api/v2/plugins.py
+++ b/sahara/api/v2/plugins.py
@@ -25,6 +25,7 @@ rest = u.RestV2('plugins', __name__)
25 25
26@rest.get('/plugins') 26@rest.get('/plugins')
27@acl.enforce("data-processing:plugins:get_all") 27@acl.enforce("data-processing:plugins:get_all")
28@v.validate_request_params([])
28def plugins_list(): 29def plugins_list():
29 return u.render(plugins=[p.dict for p in api.get_plugins()]) 30 return u.render(plugins=[p.dict for p in api.get_plugins()])
30 31
@@ -32,6 +33,7 @@ def plugins_list():
32@rest.get('/plugins/<plugin_name>') 33@rest.get('/plugins/<plugin_name>')
33@acl.enforce("data-processing:plugins:get") 34@acl.enforce("data-processing:plugins:get")
34@v.check_exists(api.get_plugin, plugin_name='plugin_name') 35@v.check_exists(api.get_plugin, plugin_name='plugin_name')
36@v.validate_request_params([])
35def plugins_get(plugin_name): 37def plugins_get(plugin_name):
36 return u.render(api.get_plugin(plugin_name).wrapped_dict) 38 return u.render(api.get_plugin(plugin_name).wrapped_dict)
37 39
@@ -39,6 +41,7 @@ def plugins_get(plugin_name):
39@rest.get('/plugins/<plugin_name>/<version>') 41@rest.get('/plugins/<plugin_name>/<version>')
40@acl.enforce("data-processing:plugins:get_version") 42@acl.enforce("data-processing:plugins:get_version")
41@v.check_exists(api.get_plugin, plugin_name='plugin_name', version='version') 43@v.check_exists(api.get_plugin, plugin_name='plugin_name', version='version')
44@v.validate_request_params([])
42def plugins_get_version(plugin_name, version): 45def plugins_get_version(plugin_name, version):
43 return u.render(api.get_plugin(plugin_name, version).wrapped_dict) 46 return u.render(api.get_plugin(plugin_name, version).wrapped_dict)
44 47
@@ -47,5 +50,6 @@ def plugins_get_version(plugin_name, version):
47@acl.enforce("data-processing:plugins:patch") 50@acl.enforce("data-processing:plugins:patch")
48@v.check_exists(api.get_plugin, plugin_name='plugin_name') 51@v.check_exists(api.get_plugin, plugin_name='plugin_name')
49@v.validate(v_p.plugin_update_validation_jsonschema(), v_p.check_plugin_update) 52@v.validate(v_p.plugin_update_validation_jsonschema(), v_p.check_plugin_update)
53@v.validate_request_params([])
50def plugins_update(plugin_name, data): 54def plugins_update(plugin_name, data):
51 return u.render(api.update_plugin(plugin_name, data).wrapped_dict) 55 return u.render(api.update_plugin(plugin_name, data).wrapped_dict)
diff --git a/sahara/service/validation.py b/sahara/service/validation.py
index d0e9a10..038d60a 100644
--- a/sahara/service/validation.py
+++ b/sahara/service/validation.py
@@ -198,3 +198,22 @@ def check_exists(get_func, *id_prop, **get_args):
198 return handler 198 return handler
199 199
200 return decorator 200 return decorator
201
202
203def validate_request_params(supported_params):
204 def decorator(func):
205 @functools.wraps(func)
206 def handler(*args, **kwargs):
207 pagination_params = ['marker', 'limit', 'sort_by']
208 func_name = func.__name__
209 params = u.get_request_args()
210 for param in params.keys():
211 if (param not in supported_params and
212 param not in pagination_params):
213 return u.invalid_param_error(
214 400,
215 'The only valid params for %s are %s and %s' % (
216 func_name, supported_params, pagination_params))
217 return func(*args, **kwargs)
218 return handler
219 return decorator
diff --git a/sahara/utils/api.py b/sahara/utils/api.py
index 7065aed..ff738a0 100644
--- a/sahara/utils/api.py
+++ b/sahara/utils/api.py
@@ -289,6 +289,18 @@ def render_error_message(error_code, error_message, error_name):
289 return resp 289 return resp
290 290
291 291
292def invalid_param_error(status_code, descr, exc=None):
293 LOG.error("Request aborted with status code {code} and "
294 "message '{message}'".format(code=status_code, message=descr))
295
296 if exc is not None:
297 LOG.error(traceback.format_exc())
298
299 error_code = "INVALID_PARAMS_ON_REQUEST"
300
301 return render_error_message(status_code, descr, error_code)
302
303
292def internal_error(status_code, descr, exc=None): 304def internal_error(status_code, descr, exc=None):
293 LOG.error("Request aborted with status code {code} and " 305 LOG.error("Request aborted with status code {code} and "
294 "message '{message}'".format(code=status_code, message=descr)) 306 "message '{message}'".format(code=status_code, message=descr))