def index(self, req): filter_whitelist = { consts.CLUSTER_NAME: 'mixed', consts.CLUSTER_STATUS: 'mixed', } param_whitelist = { consts.PARAM_LIMIT: 'single', consts.PARAM_MARKER: 'single', consts.PARAM_SORT: 'single', consts.PARAM_GLOBAL_PROJECT: 'single', } for key in req.params.keys(): if (key not in param_whitelist.keys() and key not in filter_whitelist.keys()): raise exc.HTTPBadRequest(_('Invalid parameter %s') % key) params = util.get_allowed_params(req.params, param_whitelist) filters = util.get_allowed_params(req.params, filter_whitelist) key = consts.PARAM_GLOBAL_PROJECT if key in params: project_safe = not utils.parse_bool_param(key, params[key]) del params[key] params['project_safe'] = project_safe if not filters: filters = None clusters = self.rpc_client.cluster_list(req.context, filters=filters, **params) return {'clusters': clusters}
def index(self, req, cluster_id): filter_whitelist = { consts.CP_ENABLED: 'single', } param_whitelist = { consts.PARAM_SORT: 'single', } for key in req.params.keys(): if (key not in param_whitelist.keys() and key not in filter_whitelist.keys()): raise exc.HTTPBadRequest(_('Invalid parameter %s') % key) params = util.get_allowed_params(req.params, param_whitelist) filters = util.get_allowed_params(req.params, filter_whitelist) key = consts.CP_ENABLED if key in filters: filters[key] = utils.parse_bool_param(key, filters[key]) if not filters: filters = None policies = self.rpc_client.cluster_policy_list(req.context, cluster_id=cluster_id, filters=filters, **params) return {'cluster_policies': policies}
def index(self, req): filter_whitelist = { consts.CLUSTER_NAME: 'mixed', consts.CLUSTER_STATUS: 'mixed', } param_whitelist = { consts.PARAM_LIMIT: 'single', consts.PARAM_MARKER: 'single', consts.PARAM_SORT: 'single', consts.PARAM_GLOBAL_PROJECT: 'single', } for key in req.params.keys(): if (key not in param_whitelist.keys() and key not in filter_whitelist.keys()): raise exc.HTTPBadRequest(_('Invalid parameter %s') % key) params = util.get_allowed_params(req.params, param_whitelist) filters = util.get_allowed_params(req.params, filter_whitelist) key = consts.PARAM_GLOBAL_PROJECT if key in params: project_safe = not utils.parse_bool_param(key, params[key]) del params[key] params['project_safe'] = project_safe if not filters: filters = None clusters = self.rpc_client.cluster_list(req.context, filters=filters, **params) return {'clusters': clusters}
def index(self, req, cluster_id): filter_whitelist = { consts.CP_ENABLED: 'single', } param_whitelist = { consts.PARAM_SORT: 'single', } for key in req.params.keys(): if (key not in param_whitelist.keys() and key not in filter_whitelist.keys()): raise exc.HTTPBadRequest(_('Invalid parameter %s') % key) params = util.get_allowed_params(req.params, param_whitelist) filters = util.get_allowed_params(req.params, filter_whitelist) key = consts.CP_ENABLED if key in filters: filters[key] = utils.parse_bool_param(key, filters[key]) if not filters: filters = None policies = self.rpc_client.cluster_policy_list(req.context, cluster_id=cluster_id, filters=filters, **params) return {'cluster_policies': policies}
def index(self, req): whitelist = { consts.ACTION_NAME: 'mixed', consts.ACTION_TARGET: 'mixed', consts.ACTION_ACTION: 'mixed', consts.ACTION_STATUS: 'mixed', consts.PARAM_LIMIT: 'single', consts.PARAM_MARKER: 'single', consts.PARAM_SORT: 'single', consts.PARAM_GLOBAL_PROJECT: 'single', } for key in req.params.keys(): if key not in whitelist.keys(): raise exc.HTTPBadRequest(_('Invalid parameter %s') % key) params = util.get_allowed_params(req.params, whitelist) project_safe = not util.parse_bool_param( consts.PARAM_GLOBAL_PROJECT, params.pop(consts.PARAM_GLOBAL_PROJECT, False)) params['project_safe'] = project_safe obj = util.parse_request('ActionListRequest', req, params) actions = self.rpc_client.call(req.context, "action_list", obj) return {'actions': actions}
def index(self, req): whitelist = { consts.RECEIVER_NAME: 'mixed', consts.RECEIVER_TYPE: 'mixed', consts.RECEIVER_CLUSTER_ID: 'mixed', consts.RECEIVER_USER_ID: 'mixed', consts.RECEIVER_ACTION: 'mixed', consts.PARAM_LIMIT: 'single', consts.PARAM_MARKER: 'single', consts.PARAM_SORT: 'single', consts.PARAM_GLOBAL_PROJECT: 'single', } for key in req.params.keys(): if key not in whitelist.keys(): raise exc.HTTPBadRequest(_('Invalid parameter %s') % key) params = util.get_allowed_params(req.params, whitelist) project_safe = not util.parse_bool_param( consts.PARAM_GLOBAL_PROJECT, params.pop(consts.PARAM_GLOBAL_PROJECT, False)) params['project_safe'] = project_safe obj = util.parse_request('ReceiverListRequest', req, params) receivers = self.rpc_client.call(req.context, 'receiver_list', obj) return {'receivers': receivers}
def index(self, req): whitelist = { consts.NODE_CLUSTER_ID: 'single', consts.NODE_NAME: 'mixed', consts.NODE_STATUS: 'mixed', consts.PARAM_LIMIT: 'single', consts.PARAM_MARKER: 'single', consts.PARAM_SORT: 'single', consts.PARAM_GLOBAL_PROJECT: 'single' } for key in req.params.keys(): if key not in whitelist.keys(): raise exc.HTTPBadRequest(_('Invalid parameter %s') % key) params = util.get_allowed_params(req.params, whitelist) project_safe = not util.parse_bool_param( consts.PARAM_GLOBAL_PROJECT, params.pop(consts.PARAM_GLOBAL_PROJECT, False)) params['project_safe'] = project_safe obj = util.parse_request('NodeListRequest', req, params) nodes = self.rpc_client.call(req.context, 'node_list', obj) nodes = [self._remove_tainted(req, n) for n in nodes] return {'nodes': nodes}
def index(self, req): whitelist = { consts.EVENT_OBJ_NAME: 'mixed', consts.EVENT_OBJ_TYPE: 'mixed', consts.EVENT_OBJ_ID: 'mixed', consts.EVENT_CLUSTER_ID: 'mixed', consts.EVENT_ACTION: 'mixed', consts.EVENT_LEVEL: 'mixed', consts.PARAM_LIMIT: 'single', consts.PARAM_MARKER: 'single', consts.PARAM_SORT: 'single', consts.PARAM_GLOBAL_PROJECT: 'single', } for key in req.params.keys(): if key not in whitelist.keys(): raise exc.HTTPBadRequest(_('Invalid parameter %s') % key) params = util.get_allowed_params(req.params, whitelist) project_safe = not util.parse_bool_param( consts.PARAM_GLOBAL_PROJECT, params.pop(consts.PARAM_GLOBAL_PROJECT, False)) params['project_safe'] = project_safe obj = util.parse_request('EventListRequest', req, params) events = self.rpc_client.call2(req.context, "event_list2", obj) return {'events': events}
def test_handles_mixed_value_param_with_multiple_entries(self): self.whitelist = {'foo': 'mixed'} self.params.add('foo', 'foo value 2') result = util.get_allowed_params(self.params, self.whitelist) self.assertEqual(2, len(result['foo'])) self.assertIn('foo value', result['foo']) self.assertIn('foo value 2', result['foo'])
def test_handles_mixed_value_param_with_multiple_entries(self): self.whitelist = {'foo': 'mixed'} self.params.add('foo', 'foo value 2') result = util.get_allowed_params(self.params, self.whitelist) self.assertEqual(2, len(result['foo'])) self.assertIn('foo value', result['foo']) self.assertIn('foo value 2', result['foo'])
def index(self, req, cluster_id): filter_whitelist = { consts.CP_ENABLED: 'single', } param_whitelist = { consts.PARAM_SORT: 'single', } params = util.get_allowed_params(req.params, param_whitelist) filters = util.get_allowed_params(req.params, filter_whitelist) key = consts.CP_ENABLED if key in filters: filters[key] = utils.parse_bool_param(key, filters[key]) if not filters: filters = None policies = self.rpc_client.cluster_policy_list(req.context, cluster_id=cluster_id, filters=filters, **params) return {'cluster_policies': policies}
def index(self, req, cluster_id): filter_whitelist = { consts.CP_ENABLED: 'single', } param_whitelist = { consts.PARAM_SORT: 'single', } params = util.get_allowed_params(req.params, param_whitelist) filters = util.get_allowed_params(req.params, filter_whitelist) key = consts.CP_ENABLED if key in filters: filters[key] = utils.parse_bool_param(key, filters[key]) if not filters: filters = None policies = self.rpc_client.cluster_policy_list(req.context, cluster_id=cluster_id, filters=filters, **params) return {'cluster_policies': policies}
def index(self, req): filter_whitelist = { consts.EVENT_OBJ_NAME: 'mixed', consts.EVENT_OBJ_TYPE: 'mixed', consts.EVENT_OBJ_ID: 'mixed', consts.EVENT_CLUSTER_ID: 'mixed', consts.EVENT_ACTION: 'mixed', consts.EVENT_LEVEL: 'mixed', } param_whitelist = { consts.PARAM_LIMIT: 'single', consts.PARAM_MARKER: 'single', consts.PARAM_SORT: 'single', consts.PARAM_GLOBAL_PROJECT: 'single', } for key in req.params.keys(): if (key not in param_whitelist.keys() and key not in filter_whitelist.keys()): raise exc.HTTPBadRequest(_('Invalid parameter %s') % key) params = util.get_allowed_params(req.params, param_whitelist) filters = util.get_allowed_params(req.params, filter_whitelist) key = consts.PARAM_GLOBAL_PROJECT if key in params: global_project = utils.parse_bool_param(key, params[key]) params.pop(key) params['project_safe'] = not global_project key = consts.PARAM_LIMIT if key in params: params[key] = utils.parse_int_param(key, params[key]) if not filters: filters = None events = self.rpc_client.event_list(req.context, filters=filters, **params) return {'events': events}
def index(self, req): filter_whitelist = { consts.ACTION_NAME: 'mixed', consts.ACTION_TARGET: 'mixed', consts.ACTION_ACTION: 'mixed', consts.ACTION_STATUS: 'mixed', } param_whitelist = { consts.PARAM_LIMIT: 'single', consts.PARAM_MARKER: 'single', consts.PARAM_SORT: 'single', consts.PARAM_GLOBAL_PROJECT: 'single', } for key in req.params.keys(): if (key not in param_whitelist.keys() and key not in filter_whitelist.keys()): raise exc.HTTPBadRequest(_('Invalid parameter %s') % key) params = util.get_allowed_params(req.params, param_whitelist) filters = util.get_allowed_params(req.params, filter_whitelist) key = consts.PARAM_LIMIT if key in params: params[key] = utils.parse_int_param(key, params[key]) key = consts.PARAM_GLOBAL_PROJECT if key in params: global_project = utils.parse_bool_param(key, params[key]) params.pop(key) params['project_safe'] = not global_project if not filters: filters = None actions = self.rpc_client.action_list(req.context, filters=filters, **params) return {'actions': actions}
def index(self, req): filter_whitelist = { consts.RECEIVER_NAME: 'mixed', consts.RECEIVER_TYPE: 'mixed', consts.RECEIVER_CLUSTER_ID: 'mixed', consts.RECEIVER_ACTION: 'mixed', } param_whitelist = { consts.PARAM_LIMIT: 'single', consts.PARAM_MARKER: 'single', consts.PARAM_SORT: 'single', consts.PARAM_GLOBAL_PROJECT: 'single', } for key in req.params.keys(): if (key not in param_whitelist.keys() and key not in filter_whitelist.keys()): raise exc.HTTPBadRequest(_('Invalid parameter %s') % key) params = util.get_allowed_params(req.params, param_whitelist) filters = util.get_allowed_params(req.params, filter_whitelist) key = consts.PARAM_LIMIT if key in params: params[key] = utils.parse_int_param(key, params[key]) key = consts.PARAM_GLOBAL_PROJECT if key in params: show_global = utils.parse_bool_param(key, params[key]) del params[key] params['project_safe'] = not show_global if not filters: filters = None receivers = self.rpc_client.receiver_list(req.context, filters=filters, **params) return {'receivers': receivers}
def index(self, req): filter_whitelist = { consts.ACTION_NAME: 'mixed', consts.ACTION_TARGET: 'mixed', consts.ACTION_ACTION: 'mixed', consts.ACTION_STATUS: 'mixed', } param_whitelist = { consts.PARAM_LIMIT: 'single', consts.PARAM_MARKER: 'single', consts.PARAM_SORT: 'single', consts.PARAM_GLOBAL_PROJECT: 'single', } for key in req.params.keys(): if (key not in param_whitelist.keys() and key not in filter_whitelist.keys()): raise exc.HTTPBadRequest(_('Invalid parameter %s') % key) params = util.get_allowed_params(req.params, param_whitelist) filters = util.get_allowed_params(req.params, filter_whitelist) key = consts.PARAM_LIMIT if key in params: params[key] = utils.parse_int_param(key, params[key]) key = consts.PARAM_GLOBAL_PROJECT if key in params: global_project = utils.parse_bool_param(key, params[key]) params.pop(key) params['project_safe'] = not global_project if not filters: filters = None actions = self.rpc_client.action_list(req.context, filters=filters, **params) return {'actions': actions}
def index(self, req): filter_whitelist = { consts.RECEIVER_NAME: 'mixed', consts.RECEIVER_TYPE: 'mixed', consts.RECEIVER_CLUSTER_ID: 'mixed', consts.RECEIVER_ACTION: 'mixed', } param_whitelist = { consts.PARAM_LIMIT: 'single', consts.PARAM_MARKER: 'single', consts.PARAM_SORT: 'single', consts.PARAM_GLOBAL_PROJECT: 'single', } for key in req.params.keys(): if (key not in param_whitelist.keys() and key not in filter_whitelist.keys()): raise exc.HTTPBadRequest(_('Invalid parameter %s') % key) params = util.get_allowed_params(req.params, param_whitelist) filters = util.get_allowed_params(req.params, filter_whitelist) key = consts.PARAM_LIMIT if key in params: params[key] = utils.parse_int_param(key, params[key]) key = consts.PARAM_GLOBAL_PROJECT if key in params: show_global = utils.parse_bool_param(key, params[key]) del params[key] params['project_safe'] = not show_global if not filters: filters = None receivers = self.rpc_client.receiver_list(req.context, filters=filters, **params) return {'receivers': receivers}
def index(self, req): whitelist = { consts.POLICY_NAME: 'mixed', consts.POLICY_TYPE: 'mixed', consts.PARAM_LIMIT: 'single', consts.PARAM_MARKER: 'single', consts.PARAM_SORT: 'single', consts.PARAM_GLOBAL_PROJECT: 'single', } for key in req.params.keys(): if key not in whitelist: raise exc.HTTPBadRequest(_('Invalid parameter %s') % key) params = util.get_allowed_params(req.params, whitelist) is_global = params.pop(consts.PARAM_GLOBAL_PROJECT, False) unsafe = util.parse_bool_param(consts.PARAM_GLOBAL_PROJECT, is_global) params['project_safe'] = not unsafe obj = util.parse_request('PolicyListRequest', req, params) policies = self.rpc_client.call2(req.context, 'policy_list2', obj) return {'policies': policies}
def index(self, req, cluster_id): param_whitelist = { consts.CP_ENABLED: 'single', consts.CP_POLICY_NAME: 'single', consts.CP_POLICY_TYPE: 'single', consts.PARAM_SORT: 'single', } for key in req.params.keys(): if (key not in param_whitelist.keys()): raise exc.HTTPBadRequest(_('Invalid parameter %s') % key) params = util.get_allowed_params(req.params, param_whitelist) key = consts.CP_ENABLED if key in params: params[key] = util.parse_bool_param(key, params[key]) params['identity'] = cluster_id obj = util.parse_request('ClusterPolicyListRequest', req, params) policies = self.rpc_client.call2(req.context, 'cluster_policy_list2', obj) return {'cluster_policies': policies}
def index(self, req): whitelist = { consts.CLUSTER_NAME: 'mixed', consts.CLUSTER_STATUS: 'mixed', consts.PARAM_LIMIT: 'single', consts.PARAM_MARKER: 'single', consts.PARAM_SORT: 'single', consts.PARAM_GLOBAL_PROJECT: 'single', } for key in req.params.keys(): if key not in whitelist: raise exc.HTTPBadRequest(_("Invalid parameter '%s'") % key) params = util.get_allowed_params(req.params, whitelist) # Note: We have to do a boolean parsing here because 1) there is # a renaming, 2) the boolean is usually presented as a string. is_global = params.pop(consts.PARAM_GLOBAL_PROJECT, False) unsafe = util.parse_bool_param(consts.PARAM_GLOBAL_PROJECT, is_global) params['project_safe'] = not unsafe req_obj = util.parse_request('ClusterListRequest', req, params) clusters = self.rpc_client.call(req.context, 'cluster_list', req_obj) return {'clusters': clusters}
def index(self, req): whitelist = { consts.PROFILE_NAME: 'mixed', consts.PROFILE_TYPE: 'mixed', consts.PARAM_LIMIT: 'single', consts.PARAM_MARKER: 'single', consts.PARAM_SORT: 'single', consts.PARAM_GLOBAL_PROJECT: 'single', } for key in req.params.keys(): if key not in whitelist.keys(): raise exc.HTTPBadRequest(_('Invalid parameter %s') % key) params = util.get_allowed_params(req.params, whitelist) project_safe = not util.parse_bool_param( consts.PARAM_GLOBAL_PROJECT, params.pop(consts.PARAM_GLOBAL_PROJECT, False)) params['project_safe'] = project_safe obj = util.parse_request('ProfileListRequest', req, params) profiles = self.rpc_client.call(req.context, 'profile_list', obj) return {'profiles': profiles}
def test_returns_empty_dict(self): self.whitelist = {} result = util.get_allowed_params(self.params, self.whitelist) self.assertEqual({}, result)
def test_only_adds_whitelisted_params_if_param_exists(self): self.whitelist = {'foo': 'single'} self.params.clear() result = util.get_allowed_params(self.params, self.whitelist) self.assertNotIn('foo', result)
def test_ignores_bogus_whitelist_items(self): self.whitelist = {'foo': 'blah'} result = util.get_allowed_params(self.params, self.whitelist) self.assertNotIn('foo', result)
def test_handles_mixed_value_param_with_single_entry(self): self.whitelist = {'foo': 'mixed'} result = util.get_allowed_params(self.params, self.whitelist) self.assertEqual(['foo value'], result['foo'])
def test_handles_single_value_params(self): result = util.get_allowed_params(self.params, self.whitelist) self.assertEqual('foo value', result['foo'])
def test_returns_only_whitelisted_params(self): self.params.add('bar', 'bar value') result = util.get_allowed_params(self.params, self.whitelist) self.assertIn('foo', result) self.assertNotIn('bar', result)
def test_handles_single_value_params(self): result = util.get_allowed_params(self.params, self.whitelist) self.assertEqual('foo value', result['foo'])
def test_handles_mixed_value_param_with_single_entry(self): self.whitelist = {'foo': 'mixed'} result = util.get_allowed_params(self.params, self.whitelist) self.assertEqual('foo value', result['foo'])
def test_ignores_bogus_whitelist_items(self): self.whitelist = {'foo': 'blah'} result = util.get_allowed_params(self.params, self.whitelist) self.assertNotIn('foo', result)
def test_returns_empty_dict(self): self.whitelist = {} result = util.get_allowed_params(self.params, self.whitelist) self.assertEqual({}, result)
def test_only_adds_whitelisted_params_if_param_exists(self): self.whitelist = {'foo': 'single'} self.params.clear() result = util.get_allowed_params(self.params, self.whitelist) self.assertNotIn('foo', result)
def test_returns_only_whitelisted_params(self): self.params.add('bar', 'bar value') result = util.get_allowed_params(self.params, self.whitelist) self.assertIn('foo', result) self.assertNotIn('bar', result)