Browse Source

Merge "APIv2 - Fix 500 on malformed query string on"

tags/10.0.0.0b1
Zuul 5 months ago
parent
commit
78090dee69

+ 6
- 0
sahara/api/v2/cluster_templates.py View File

@@ -29,6 +29,7 @@ rest = u.RestV2('cluster-templates', __name__)
29 29
 @v.check_exists(api.get_cluster_template, 'marker')
30 30
 @v.validate(None, v.validate_pagination_limit,
31 31
             v.validate_sorting_cluster_templates)
32
+@v.validate_request_params(['plugin_name', 'hadoop_version', 'name'])
32 33
 def cluster_templates_list():
33 34
     result = api.get_cluster_templates(**u.get_request_args().to_dict())
34 35
     for ct in result:
@@ -41,6 +42,7 @@ def cluster_templates_list():
41 42
 @acl.enforce("data-processing:cluster-templates:create")
42 43
 @v.validate(ct_schema.CLUSTER_TEMPLATE_SCHEMA_V2,
43 44
             v_ct.check_cluster_template_create)
45
+@v.validate_request_params([])
44 46
 def cluster_templates_create(data):
45 47
     # renaming hadoop_version -> plugin_version
46 48
     # this can be removed once APIv1 is deprecated
@@ -55,6 +57,7 @@ def cluster_templates_create(data):
55 57
 @rest.get('/cluster-templates/<cluster_template_id>')
56 58
 @acl.enforce("data-processing:cluster-templates:get")
57 59
 @v.check_exists(api.get_cluster_template, 'cluster_template_id')
60
+@v.validate_request_params([])
58 61
 def cluster_templates_get(cluster_template_id):
59 62
     result = u.to_wrapped_dict_no_render(
60 63
         api.get_cluster_template, cluster_template_id)
@@ -68,6 +71,7 @@ def cluster_templates_get(cluster_template_id):
68 71
 @v.check_exists(api.get_cluster_template, 'cluster_template_id')
69 72
 @v.validate(ct_schema.CLUSTER_TEMPLATE_UPDATE_SCHEMA_V2,
70 73
             v_ct.check_cluster_template_update)
74
+@v.validate_request_params([])
71 75
 def cluster_templates_update(cluster_template_id, data):
72 76
     if data.get('plugin_version', None):
73 77
         data['hadoop_version'] = data['plugin_version']
@@ -83,6 +87,7 @@ def cluster_templates_update(cluster_template_id, data):
83 87
 @acl.enforce("data-processing:cluster-templates:delete")
84 88
 @v.check_exists(api.get_cluster_template, 'cluster_template_id')
85 89
 @v.validate(None, v_ct.check_cluster_template_usage)
90
+@v.validate_request_params([])
86 91
 def cluster_templates_delete(cluster_template_id):
87 92
     api.terminate_cluster_template(cluster_template_id)
88 93
     return u.render()
@@ -101,6 +106,7 @@ def _cluster_template_export_helper(template):
101 106
 @rest.get('/cluster-templates/<cluster_template_id>/export')
102 107
 @acl.enforce("data-processing:cluster-templates:get")
103 108
 @v.check_exists(api.get_cluster_template, 'cluster_template_id')
109
+@v.validate_request_params([])
104 110
 def cluster_template_export(cluster_template_id):
105 111
     content = u.to_wrapped_dict_no_render(
106 112
         api.export_cluster_template, cluster_template_id)

+ 6
- 0
sahara/api/v2/clusters.py View File

@@ -31,6 +31,7 @@ rest = u.RestV2('clusters', __name__)
31 31
 @acl.enforce("data-processing:clusters:get_all")
32 32
 @v.check_exists(api.get_cluster, 'marker')
33 33
 @v.validate(None, v.validate_pagination_limit)
34
+@v.validate_request_params(['plugin_name', 'hadoop_version', 'name'])
34 35
 def clusters_list():
35 36
     result = api.get_clusters(**u.get_request_args().to_dict())
36 37
     for c in result:
@@ -43,6 +44,7 @@ def clusters_list():
43 44
 @acl.enforce("data-processing:clusters:create")
44 45
 @v.validate(v_c_schema.CLUSTER_SCHEMA_V2,
45 46
             v_c.check_one_or_multiple_clusters_create)
47
+@v.validate_request_params([])
46 48
 def clusters_create(data):
47 49
     # renaming hadoop_version -> plugin_version
48 50
     # this can be removed once APIv1 is deprecated
@@ -65,6 +67,7 @@ def clusters_create(data):
65 67
 @acl.enforce("data-processing:clusters:scale")
66 68
 @v.check_exists(api.get_cluster, 'cluster_id')
67 69
 @v.validate(v_c_schema.CLUSTER_SCALING_SCHEMA_V2, v_c_s.check_cluster_scaling)
70
+@v.validate_request_params([])
68 71
 def clusters_scale(cluster_id, data):
69 72
     result = u.to_wrapped_dict_no_render(
70 73
         api.scale_cluster, cluster_id, data)
@@ -76,6 +79,7 @@ def clusters_scale(cluster_id, data):
76 79
 @rest.get('/clusters/<cluster_id>')
77 80
 @acl.enforce("data-processing:clusters:get")
78 81
 @v.check_exists(api.get_cluster, 'cluster_id')
82
+@v.validate_request_params([])
79 83
 def clusters_get(cluster_id):
80 84
     data = u.get_request_args()
81 85
     show_events = six.text_type(
@@ -91,6 +95,7 @@ def clusters_get(cluster_id):
91 95
 @acl.enforce("data-processing:clusters:modify")
92 96
 @v.check_exists(api.get_cluster, 'cluster_id')
93 97
 @v.validate(v_c_schema.CLUSTER_UPDATE_SCHEMA, v_c.check_cluster_update)
98
+@v.validate_request_params([])
94 99
 def clusters_update(cluster_id, data):
95 100
     result = u.to_wrapped_dict_no_render(
96 101
         api.update_cluster, cluster_id, data)
@@ -103,6 +108,7 @@ def clusters_update(cluster_id, data):
103 108
 @acl.enforce("data-processing:clusters:delete")
104 109
 @v.check_exists(api.get_cluster, 'cluster_id')
105 110
 @v.validate(v_c_schema.CLUSTER_DELETE_SCHEMA_V2, v_c.check_cluster_delete)
111
+@v.validate_request_params([])
106 112
 def clusters_delete(cluster_id):
107 113
     data = u.request_data()
108 114
     force = data.get('force', False)

+ 5
- 0
sahara/api/v2/data_sources.py View File

@@ -29,6 +29,7 @@ rest = u.RestV2('data-sources', __name__)
29 29
 @v.check_exists(api.get_data_source, 'marker')
30 30
 @v.validate(None, v.validate_pagination_limit,
31 31
             v.validate_sorting_data_sources)
32
+@v.validate_request_params(['type'])
32 33
 def data_sources_list():
33 34
     result = api.get_data_sources(**u.get_request_args().to_dict())
34 35
     for ds in result:
@@ -39,6 +40,7 @@ def data_sources_list():
39 40
 @rest.post('/data-sources')
40 41
 @acl.enforce("data-processing:data-sources:register")
41 42
 @v.validate(v_d_s_schema.DATA_SOURCE_SCHEMA, v_d_s.check_data_source_create)
43
+@v.validate_request_params([])
42 44
 def data_source_register(data):
43 45
     result = api.register_data_source(data).to_wrapped_dict()
44 46
     u._replace_tenant_id_project_id(result['data_source'])
@@ -48,6 +50,7 @@ def data_source_register(data):
48 50
 @rest.get('/data-sources/<data_source_id>')
49 51
 @acl.enforce("data-processing:data-sources:get")
50 52
 @v.check_exists(api.get_data_source, 'data_source_id')
53
+@v.validate_request_params([])
51 54
 def data_source_get(data_source_id):
52 55
     result = u.to_wrapped_dict(api.get_data_source, data_source_id)
53 56
     u._replace_tenant_id_project_id(result['data_source'])
@@ -57,6 +60,7 @@ def data_source_get(data_source_id):
57 60
 @rest.delete('/data-sources/<data_source_id>')
58 61
 @acl.enforce("data-processing:data-sources:delete")
59 62
 @v.check_exists(api.get_data_source, 'data_source_id')
63
+@v.validate_request_params([])
60 64
 def data_source_delete(data_source_id):
61 65
     api.delete_data_source(data_source_id)
62 66
     return u.render()
@@ -66,6 +70,7 @@ def data_source_delete(data_source_id):
66 70
 @acl.enforce("data-processing:data-sources:modify")
67 71
 @v.check_exists(api.get_data_source, 'data_source_id')
68 72
 @v.validate(v_d_s_schema.DATA_SOURCE_UPDATE_SCHEMA)
73
+@v.validate_request_params([])
69 74
 def data_source_update(data_source_id, data):
70 75
     result = u.to_wrapped_dict(api.data_source_update, data_source_id, data)
71 76
     u._replace_tenant_id_project_id(result['data_source'])

+ 7
- 0
sahara/api/v2/images.py View File

@@ -25,6 +25,7 @@ rest = u.RestV2('images', __name__)
25 25
 
26 26
 @rest.get('/images')
27 27
 @acl.enforce("data-processing:images:get_all")
28
+@v.validate_request_params(['name', 'tags', 'username'])
28 29
 def images_list():
29 30
     tags = u.get_request_args().getlist('tags')
30 31
     name = u.get_request_args().get('name', None)
@@ -34,6 +35,7 @@ def images_list():
34 35
 @rest.get('/images/<image_id>')
35 36
 @acl.enforce("data-processing:images:get")
36 37
 @v.check_exists(api.get_image, id='image_id')
38
+@v.validate_request_params([])
37 39
 def images_get(image_id):
38 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 44
 @acl.enforce("data-processing:images:register")
43 45
 @v.check_exists(api.get_image, id='image_id')
44 46
 @v.validate(v_images.image_register_schema, v_images.check_image_register)
47
+@v.validate_request_params([])
45 48
 def images_set(image_id, data):
46 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 52
 @rest.delete('/images/<image_id>')
50 53
 @acl.enforce("data-processing:images:unregister")
51 54
 @v.check_exists(api.get_image, id='image_id')
55
+@v.validate_request_params([])
52 56
 def images_unset(image_id):
53 57
     api.unregister_image(image_id)
54 58
     return u.render()
@@ -57,6 +61,7 @@ def images_unset(image_id):
57 61
 @rest.get('/images/<image_id>/tags')
58 62
 @acl.enforce("data-processing:images:get_tags")
59 63
 @v.check_exists(api.get_image, id='image_id')
64
+@v.validate_request_params([])
60 65
 def image_tags_get(image_id):
61 66
     return u.render(api.get_image_tags(image_id))
62 67
 
@@ -65,6 +70,7 @@ def image_tags_get(image_id):
65 70
 @acl.enforce("data-processing:images:set_tags")
66 71
 @v.check_exists(api.get_image, id='image_id')
67 72
 @v.validate(v_images.image_tags_schema, v_images.check_tags)
73
+@v.validate_request_params([])
68 74
 def image_tags_update(image_id, data):
69 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 78
 @rest.delete('/images/<image_id>/tags')
73 79
 @acl.enforce("data-processing:images:remove_tags")
74 80
 @v.check_exists(api.get_image, id='image_id')
81
+@v.validate_request_params([])
75 82
 def image_tags_delete(image_id):
76 83
     api.remove_image_tags(image_id)
77 84
     return u.render()

+ 6
- 0
sahara/api/v2/job_binaries.py View File

@@ -27,6 +27,7 @@ rest = u.RestV2('job-binaries', __name__)
27 27
 @rest.post('/job-binaries')
28 28
 @acl.enforce("data-processing:job-binaries:create")
29 29
 @v.validate(v_j_b_schema.JOB_BINARY_SCHEMA, v_j_b.check_job_binary)
30
+@v.validate_request_params([])
30 31
 def job_binary_create(data):
31 32
     result = api.create_job_binary(data).to_wrapped_dict()
32 33
     u._replace_tenant_id_project_id(result['job_binary'])
@@ -38,6 +39,7 @@ def job_binary_create(data):
38 39
 @v.check_exists(api.get_job_binary, 'marker')
39 40
 @v.validate(None, v.validate_pagination_limit,
40 41
             v.validate_sorting_job_binaries)
42
+@v.validate_request_params(['name'])
41 43
 def job_binary_list():
42 44
     result = api.get_job_binaries(**u.get_request_args().to_dict())
43 45
     for jb in result:
@@ -48,6 +50,7 @@ def job_binary_list():
48 50
 @rest.get('/job-binaries/<job_binary_id>')
49 51
 @acl.enforce("data-processing:job-binaries:get")
50 52
 @v.check_exists(api.get_job_binary, 'job_binary_id')
53
+@v.validate_request_params([])
51 54
 def job_binary_get(job_binary_id):
52 55
     result = api.get_job_binary(job_binary_id).to_wrapped_dict()
53 56
     u._replace_tenant_id_project_id(result['job_binary'])
@@ -57,6 +60,7 @@ def job_binary_get(job_binary_id):
57 60
 @rest.delete('/job-binaries/<job_binary_id>')
58 61
 @acl.enforce("data-processing:job-binaries:delete")
59 62
 @v.check_exists(api.get_job_binary, id='job_binary_id')
63
+@v.validate_request_params([])
60 64
 def job_binary_delete(job_binary_id):
61 65
     api.delete_job_binary(job_binary_id)
62 66
     return u.render()
@@ -65,6 +69,7 @@ def job_binary_delete(job_binary_id):
65 69
 @rest.get('/job-binaries/<job_binary_id>/data')
66 70
 @acl.enforce("data-processing:job-binaries:get_data")
67 71
 @v.check_exists(api.get_job_binary, 'job_binary_id')
72
+@v.validate_request_params([])
68 73
 def job_binary_data(job_binary_id):
69 74
     data = api.get_job_binary_data(job_binary_id)
70 75
     if type(data) == dict:
@@ -75,6 +80,7 @@ def job_binary_data(job_binary_id):
75 80
 @rest.patch('/job-binaries/<job_binary_id>')
76 81
 @acl.enforce("data-processing:job-binaries:modify")
77 82
 @v.validate(v_j_b_schema.JOB_BINARY_UPDATE_SCHEMA, v_j_b.check_job_binary)
83
+@v.validate_request_params([])
78 84
 def job_binary_update(job_binary_id, data):
79 85
     result = api.update_job_binary(job_binary_id, data).to_wrapped_dict()
80 86
     u._replace_tenant_id_project_id(result['job_binary'])

+ 6
- 0
sahara/api/v2/job_templates.py View File

@@ -29,6 +29,7 @@ rest = u.RestV2('job-templates', __name__)
29 29
 @v.check_exists(api.get_job_templates, 'marker')
30 30
 @v.validate(None, v.validate_pagination_limit,
31 31
             v.validate_sorting_jobs)
32
+@v.validate_request_params(['type', 'name'])
32 33
 def job_templates_list():
33 34
     result = api.get_job_templates(**u.get_request_args().to_dict())
34 35
     for jt in result:
@@ -39,6 +40,7 @@ def job_templates_list():
39 40
 @rest.post('/job-templates')
40 41
 @acl.enforce("data-processing:job-templates:create")
41 42
 @v.validate(v_j_schema.JOB_SCHEMA, v_j.check_mains_libs, v_j.check_interface)
43
+@v.validate_request_params([])
42 44
 def job_templates_create(data):
43 45
     result = {'job_template': api.create_job_template(data).to_dict()}
44 46
     u._replace_tenant_id_project_id(result['job_template'])
@@ -48,6 +50,7 @@ def job_templates_create(data):
48 50
 @rest.get('/job-templates/<job_templates_id>')
49 51
 @acl.enforce("data-processing:job-templates:get")
50 52
 @v.check_exists(api.get_job_templates, id='job_templates_id')
53
+@v.validate_request_params([])
51 54
 def job_templates_get(job_templates_id):
52 55
     result = {'job_template': api.get_job_template(
53 56
         job_templates_id).to_dict()}
@@ -59,6 +62,7 @@ def job_templates_get(job_templates_id):
59 62
 @acl.enforce("data-processing:jobs:modify")
60 63
 @v.check_exists(api.get_job_templates, id='job_templates_id')
61 64
 @v.validate(v_j_schema.JOB_UPDATE_SCHEMA)
65
+@v.validate_request_params([])
62 66
 def job_templates_update(job_templates_id, data):
63 67
     result = {'job_template': api.update_job_template(
64 68
         job_templates_id, data).to_dict()}
@@ -69,6 +73,7 @@ def job_templates_update(job_templates_id, data):
69 73
 @rest.delete('/job-templates/<job_templates_id>')
70 74
 @acl.enforce("data-processing:jobs:delete")
71 75
 @v.check_exists(api.get_job_templates, id='job_templates_id')
76
+@v.validate_request_params([])
72 77
 def job_templates_delete(job_templates_id):
73 78
     api.delete_job_template(job_templates_id)
74 79
     return u.render()
@@ -77,5 +82,6 @@ def job_templates_delete(job_templates_id):
77 82
 @rest.get('/job-templates/config-hints/<job_type>')
78 83
 @acl.enforce("data-processing:jobs:get_config_hints")
79 84
 @v.check_exists(api.get_job_config_hints, job_type='job_type')
85
+@v.validate_request_params([])
80 86
 def job_config_hints_get(job_type):
81 87
     return u.render(api.get_job_config_hints(job_type))

+ 2
- 0
sahara/api/v2/job_types.py View File

@@ -15,6 +15,7 @@
15 15
 
16 16
 from sahara.api import acl
17 17
 from sahara.service.api.v2 import job_types as api
18
+from sahara.service import validation as v
18 19
 import sahara.utils.api as u
19 20
 
20 21
 
@@ -23,6 +24,7 @@ rest = u.RestV2('job-types', __name__)
23 24
 
24 25
 @rest.get('/job-types')
25 26
 @acl.enforce("data-processing:job-types:get_all")
27
+@v.validate_request_params(['type', 'plugin_name', 'hadoop_version'])
26 28
 def job_types_get():
27 29
     # We want to use flat=False with to_dict() so that
28 30
     # the value of each arg is given as a list. This supports

+ 5
- 0
sahara/api/v2/jobs.py View File

@@ -31,6 +31,7 @@ rest = u.RestV2('jobs', __name__)
31 31
 @v.check_exists(api.get_job_execution, 'marker')
32 32
 @v.validate(None, v.validate_pagination_limit,
33 33
             v.validate_sorting_job_executions)
34
+@v.validate_request_params(['status'])
34 35
 def jobs_list():
35 36
     result = api.job_execution_list(**u.get_request_args().to_dict())
36 37
     # APIv2: renaming oozie_job_id -> engine_job_id
@@ -45,6 +46,7 @@ def jobs_list():
45 46
 @rest.post('/jobs')
46 47
 @acl.enforce("data-processing:jobs:execute")
47 48
 @v.validate(v_j_e_schema.JOB_EXEC_SCHEMA_V2, v_j_e.check_job_execution)
49
+@v.validate_request_params([])
48 50
 def jobs_execute(data):
49 51
     result = {'job': api.execute_job(data)}
50 52
     dict.update(result['job'],
@@ -57,6 +59,7 @@ def jobs_execute(data):
57 59
 @rest.get('/jobs/<job_id>')
58 60
 @acl.enforce("data-processing:job-executions:get")
59 61
 @v.check_exists(api.get_job_execution, id='job_id')
62
+@v.validate_request_params([])
60 63
 def jobs_get(job_id):
61 64
     data = u.get_request_args()
62 65
     refresh_status = six.text_type(
@@ -72,6 +75,7 @@ def jobs_get(job_id):
72 75
 @v.check_exists(api.get_job_execution, id='job_id')
73 76
 @v.validate(
74 77
     v_j_e_schema.JOB_EXEC_UPDATE_SCHEMA, v_j_e.check_job_execution_update)
78
+@v.validate_request_params([])
75 79
 def jobs_update(job_id, data):
76 80
     result = {'job': api.update_job_execution(job_id, data)}
77 81
     result['job'].pop('oozie_job_id', force=True)
@@ -83,6 +87,7 @@ def jobs_update(job_id, data):
83 87
 @acl.enforce("data-processing:job-executions:delete")
84 88
 @v.check_exists(api.get_job_execution, id='job_id')
85 89
 @v.validate(None, v_j_e.check_job_execution_delete)
90
+@v.validate_request_params([])
86 91
 def jobs_delete(job_id):
87 92
     api.delete_job_execution(job_id)
88 93
     return u.render()

+ 6
- 0
sahara/api/v2/node_group_templates.py View File

@@ -30,6 +30,7 @@ rest = u.RestV2('node-group-templates', __name__)
30 30
 @v.check_exists(api.get_node_group_template, 'marker')
31 31
 @v.validate(None, v.validate_pagination_limit,
32 32
             v.validate_sorting_node_group_templates)
33
+@v.validate_request_params(['plugin_name', 'hadoop_version', 'name'])
33 34
 def node_group_templates_list():
34 35
     result = api.get_node_group_templates(**u.get_request_args().to_dict())
35 36
     for ngt in result:
@@ -42,6 +43,7 @@ def node_group_templates_list():
42 43
 @acl.enforce("data-processing:node-group-templates:create")
43 44
 @v.validate(ngt_schema.NODE_GROUP_TEMPLATE_SCHEMA_V2,
44 45
             v_ngt.check_node_group_template_create)
46
+@v.validate_request_params([])
45 47
 def node_group_templates_create(data):
46 48
     # renaming hadoop_version -> plugin_version
47 49
     # this can be removed once APIv1 is deprecated
@@ -56,6 +58,7 @@ def node_group_templates_create(data):
56 58
 @rest.get('/node-group-templates/<node_group_template_id>')
57 59
 @acl.enforce("data-processing:node-group-templates:get")
58 60
 @v.check_exists(api.get_node_group_template, 'node_group_template_id')
61
+@v.validate_request_params([])
59 62
 def node_group_templates_get(node_group_template_id):
60 63
     result = u.to_wrapped_dict_no_render(
61 64
         api.get_node_group_template, node_group_template_id)
@@ -69,6 +72,7 @@ def node_group_templates_get(node_group_template_id):
69 72
 @v.check_exists(api.get_node_group_template, 'node_group_template_id')
70 73
 @v.validate(ngt_schema.NODE_GROUP_TEMPLATE_UPDATE_SCHEMA_V2,
71 74
             v_ngt.check_node_group_template_update)
75
+@v.validate_request_params([])
72 76
 def node_group_templates_update(node_group_template_id, data):
73 77
     if data.get('plugin_version', None):
74 78
         data['hadoop_version'] = data['plugin_version']
@@ -84,6 +88,7 @@ def node_group_templates_update(node_group_template_id, data):
84 88
 @acl.enforce("data-processing:node-group-templates:delete")
85 89
 @v.check_exists(api.get_node_group_template, 'node_group_template_id')
86 90
 @v.validate(None, v_ngt.check_node_group_template_usage)
91
+@v.validate_request_params([])
87 92
 def node_group_templates_delete(node_group_template_id):
88 93
     api.terminate_node_group_template(node_group_template_id)
89 94
     return u.render()
@@ -104,6 +109,7 @@ def _node_group_template_export_helper(template):
104 109
 @rest.get('/node-group-templates/<node_group_template_id>/export')
105 110
 @acl.enforce("data-processing:node-group-templates:get")
106 111
 @v.check_exists(api.get_node_group_template, 'node_group_template_id')
112
+@v.validate_request_params([])
107 113
 def node_group_template_export(node_group_template_id):
108 114
     content = u.to_wrapped_dict_no_render(
109 115
         api.export_node_group_template, node_group_template_id)

+ 4
- 0
sahara/api/v2/plugins.py View File

@@ -25,6 +25,7 @@ rest = u.RestV2('plugins', __name__)
25 25
 
26 26
 @rest.get('/plugins')
27 27
 @acl.enforce("data-processing:plugins:get_all")
28
+@v.validate_request_params([])
28 29
 def plugins_list():
29 30
     return u.render(plugins=[p.dict for p in api.get_plugins()])
30 31
 
@@ -32,6 +33,7 @@ def plugins_list():
32 33
 @rest.get('/plugins/<plugin_name>')
33 34
 @acl.enforce("data-processing:plugins:get")
34 35
 @v.check_exists(api.get_plugin, plugin_name='plugin_name')
36
+@v.validate_request_params([])
35 37
 def plugins_get(plugin_name):
36 38
     return u.render(api.get_plugin(plugin_name).wrapped_dict)
37 39
 
@@ -39,6 +41,7 @@ def plugins_get(plugin_name):
39 41
 @rest.get('/plugins/<plugin_name>/<version>')
40 42
 @acl.enforce("data-processing:plugins:get_version")
41 43
 @v.check_exists(api.get_plugin, plugin_name='plugin_name', version='version')
44
+@v.validate_request_params([])
42 45
 def plugins_get_version(plugin_name, version):
43 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 50
 @acl.enforce("data-processing:plugins:patch")
48 51
 @v.check_exists(api.get_plugin, plugin_name='plugin_name')
49 52
 @v.validate(v_p.plugin_update_validation_jsonschema(), v_p.check_plugin_update)
53
+@v.validate_request_params([])
50 54
 def plugins_update(plugin_name, data):
51 55
     return u.render(api.update_plugin(plugin_name, data).wrapped_dict)

+ 19
- 0
sahara/service/validation.py View File

@@ -198,3 +198,22 @@ def check_exists(get_func, *id_prop, **get_args):
198 198
         return handler
199 199
 
200 200
     return decorator
201
+
202
+
203
+def 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

+ 12
- 0
sahara/utils/api.py View File

@@ -289,6 +289,18 @@ def render_error_message(error_code, error_message, error_name):
289 289
     return resp
290 290
 
291 291
 
292
+def 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
+
292 304
 def internal_error(status_code, descr, exc=None):
293 305
     LOG.error("Request aborted with status code {code} and "
294 306
               "message '{message}'".format(code=status_code, message=descr))

Loading…
Cancel
Save