本文整理汇总了Python中monasca_api.v2.reference.helpers.validate_authorization函数的典型用法代码示例。如果您正苦于以下问题:Python validate_authorization函数的具体用法?Python validate_authorization怎么用?Python validate_authorization使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了validate_authorization函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: on_delete
def on_delete(self, req, res, alarm_id):
helpers.validate_authorization(req, self._default_authorized_roles)
self._alarm_delete(req.project_id, alarm_id)
res.status = falcon.HTTP_204
开发者ID:artur-ba,项目名称:monasca-api,代码行数:7,代码来源:alarms.py
示例2: on_get
def on_get(self, req, res, alarm_id=None):
if alarm_id is None:
helpers.validate_authorization(req, self._get_alarms_authorized_roles)
start_timestamp = helpers.get_query_starttime_timestamp(req, False)
end_timestamp = helpers.get_query_endtime_timestamp(req, False)
offset = helpers.get_query_param(req, 'offset')
dimensions = helpers.get_query_dimensions(req)
helpers.validate_query_dimensions(dimensions)
result = self._alarm_history_list(req.project_id, start_timestamp,
end_timestamp, dimensions,
req.uri, offset, req.limit)
res.body = helpers.to_json(result)
res.status = falcon.HTTP_200
else:
helpers.validate_authorization(req, self._get_alarms_authorized_roles)
offset = helpers.get_query_param(req, 'offset')
result = self._alarm_history(req.project_id, alarm_id,
req.uri, offset,
req.limit)
res.body = helpers.to_json(result)
res.status = falcon.HTTP_200
开发者ID:jgrassler,项目名称:monasca-api,代码行数:27,代码来源:alarms.py
示例3: on_patch
def on_patch(self, req, res, alarm_id):
helpers.validate_authorization(req, self._default_authorized_roles)
tenant_id = helpers.get_tenant_id(req)
alarm = helpers.read_http_resource(req)
schema_alarm.validate(alarm)
old_alarm = self._alarms_repo.get_alarm(tenant_id, alarm_id)[0]
# if a field is not present or is None, replace it with the old value
if 'state' not in alarm or not alarm['state']:
alarm['state'] = old_alarm['state']
if 'lifecycle_state' not in alarm or alarm['lifecycle_state'] is None:
alarm['lifecycle_state'] = old_alarm['lifecycle_state']
if 'link' not in alarm or alarm['link'] is None:
alarm['link'] = old_alarm['link']
self._alarm_patch(tenant_id, alarm_id, alarm['state'],
alarm['lifecycle_state'], alarm['link'])
result = self._alarm_show(req.uri, tenant_id, alarm_id)
res.body = helpers.dumpit_utf8(result)
res.status = falcon.HTTP_200
开发者ID:Missxiaoguo,项目名称:monasca-api,代码行数:26,代码来源:alarms.py
示例4: on_get
def on_get(self, req, res, alarm_definition_id=None):
if alarm_definition_id is None:
helpers.validate_authorization(req, self._default_authorized_roles)
tenant_id = helpers.get_tenant_id(req)
name = helpers.get_query_name(req)
dimensions = helpers.get_query_dimensions(req)
offset = helpers.get_query_param(req, 'offset')
limit = helpers.get_limit(req)
result = self._alarm_definition_list(tenant_id, name, dimensions,
req.uri, offset, limit)
res.body = helpers.dumpit_utf8(result)
res.status = falcon.HTTP_200
else:
helpers.validate_authorization(req, self._default_authorized_roles)
tenant_id = helpers.get_tenant_id(req)
result = self._alarm_definition_show(tenant_id,
alarm_definition_id)
helpers.add_links_to_resource(result,
re.sub('/' + alarm_definition_id, '',
req.uri))
res.body = helpers.dumpit_utf8(result)
res.status = falcon.HTTP_200
开发者ID:nilwyh,项目名称:monasca-api,代码行数:27,代码来源:alarm_definitions.py
示例5: on_put
def on_put(self, req, res, alarm_id):
helpers.validate_authorization(req, ['api:alarms:put'])
alarm = helpers.from_json(req)
schema_alarm.validate(alarm)
# Validator makes state optional, so check it here
if 'state' not in alarm or not alarm['state']:
raise HTTPUnprocessableEntityError('Unprocessable Entity',
"Field 'state' is required")
if 'lifecycle_state' not in alarm or not alarm['lifecycle_state']:
raise HTTPUnprocessableEntityError('Unprocessable Entity',
"Field 'lifecycle_state' is required")
if 'link' not in alarm or not alarm['link']:
raise HTTPUnprocessableEntityError('Unprocessable Entity',
"Field 'link' is required")
self._alarm_update(req.project_id, alarm_id, alarm['state'],
alarm['lifecycle_state'], alarm['link'])
result = self._alarm_show(req.uri, req.project_id, alarm_id)
res.body = helpers.to_json(result)
res.status = falcon.HTTP_200
开发者ID:openstack,项目名称:monasca-api,代码行数:25,代码来源:alarms.py
示例6: on_get
def on_get(self, req, res, alarm_id=None):
helpers.validate_authorization(req, self._default_authorized_roles)
tenant_id = helpers.get_tenant_id(req)
if alarm_id is None:
query_parms = falcon.uri.parse_query_string(req.query_string)
# ensure metric_dimensions is a list
if 'metric_dimensions' in query_parms and isinstance(query_parms['metric_dimensions'], str):
query_parms['metric_dimensions'] = query_parms['metric_dimensions'].split(',')
offset = helpers.get_query_param(req, 'offset')
limit = helpers.get_limit(req)
result = self._alarm_list(req.uri, tenant_id, query_parms, offset,
limit)
res.body = helpers.dumpit_utf8(result)
res.status = falcon.HTTP_200
else:
result = self._alarm_show(req.uri, tenant_id, alarm_id)
res.body = helpers.dumpit_utf8(result)
res.status = falcon.HTTP_200
开发者ID:Rubab-Syed,项目名称:monasca-api,代码行数:26,代码来源:alarms.py
示例7: on_get
def on_get(self, req, res):
helpers.validate_authorization(req, ['api:alarms:count'])
query_parms = falcon.uri.parse_query_string(req.query_string)
if 'state' in query_parms:
validation.validate_alarm_state(query_parms['state'])
query_parms['state'] = query_parms['state'].upper()
if 'severity' in query_parms:
validation.validate_severity_query(query_parms['severity'])
query_parms['severity'] = query_parms['severity'].upper()
if 'group_by' in query_parms:
if not isinstance(query_parms['group_by'], list):
query_parms['group_by'] = query_parms['group_by'].split(',')
self._validate_group_by(query_parms['group_by'])
query_parms['metric_dimensions'] = helpers.get_query_dimensions(req, 'metric_dimensions')
helpers.validate_query_dimensions(query_parms['metric_dimensions'])
offset = helpers.get_query_param(req, 'offset')
if offset is not None:
try:
offset = int(offset)
except Exception:
raise HTTPUnprocessableEntityError(
"Unprocessable Entity",
"Offset must be a valid integer, was {}".format(offset))
result = self._alarms_count(req.uri, req.project_id, query_parms, offset, req.limit)
res.body = helpers.to_json(result)
res.status = falcon.HTTP_200
开发者ID:openstack,项目名称:monasca-api,代码行数:34,代码来源:alarms.py
示例8: on_delete
def on_delete(self, req, res, alarm_id):
helpers.validate_authorization(req, ['api:alarms:delete'])
self._alarm_delete(req.project_id, alarm_id)
res.status = falcon.HTTP_204
开发者ID:openstack,项目名称:monasca-api,代码行数:7,代码来源:alarms.py
示例9: on_put
def on_put(self, req, res, alarm_id):
helpers.validate_authorization(req, self._default_authorized_roles)
tenant_id = helpers.get_tenant_id(req)
alarm = helpers.read_http_resource(req)
schema_alarm.validate(alarm)
# Validator makes state optional, so check it here
if 'state' not in alarm or not alarm['state']:
raise falcon.HTTPBadRequest('Bad request',
"Field 'state' is required")
# Assume these fields are null if not provided
if 'lifecycle_state' not in alarm:
alarm['lifecycle_state'] = None
if 'link' not in alarm:
alarm['link'] = None
self._alarm_update(tenant_id, alarm_id, alarm['state'],
alarm['lifecycle_state'], alarm['link'])
result = self._alarm_show(req.uri, tenant_id, alarm_id)
res.body = helpers.dumpit_utf8(result)
res.status = falcon.HTTP_200
开发者ID:nilwyh,项目名称:monasca-api,代码行数:27,代码来源:alarms.py
示例10: on_get
def on_get(self, req, res):
helpers.validate_authorization(req, self._default_authorized_roles)
tenant_id = helpers.get_tenant_id(req)
query_parms = falcon.uri.parse_query_string(req.query_string)
if 'state' in query_parms:
validation.validate_alarm_state(query_parms['state'])
if 'severity' in query_parms:
validation.validate_alarm_definition_severity(query_parms['severity'])
if 'group_by' in query_parms:
if not isinstance(query_parms['group_by'], list):
query_parms['group_by'] = [query_parms['group_by']]
self._validate_group_by(query_parms['group_by'])
# ensure metric_dimensions is a list
if 'metric_dimensions' in query_parms and isinstance(query_parms['metric_dimensions'], str):
query_parms['metric_dimensions'] = query_parms['metric_dimensions'].split(',')
offset = helpers.get_query_param(req, 'offset')
if offset is not None:
try:
offset = int(offset)
except Exception:
raise HTTPUnprocessableEntityError("Unprocessable Entity",
"Offset must be a valid integer, was {}".format(offset))
limit = helpers.get_limit(req)
result = self._alarms_count(req.uri, tenant_id, query_parms, offset, limit)
res.body = helpers.dumpit_utf8(result)
res.status = falcon.HTTP_200
开发者ID:Missxiaoguo,项目名称:monasca-api,代码行数:35,代码来源:alarms.py
示例11: on_get
def on_get(self, req, res, version_id=None):
req_uri = req.uri.decode('utf8') if six.PY2 else req.uri
helpers.validate_authorization(req,
['api:versions'])
result = {
'links': [{
'rel': 'self',
'href': req_uri
}],
'elements': []
}
if version_id is None:
for version in VERSIONS:
VERSIONS[version]['links'][0]['href'] = (
req_uri + version)
result['elements'].append(VERSIONS[version])
res.body = helpers.to_json(result)
res.status = falcon.HTTP_200
else:
if version_id in VERSIONS:
VERSIONS[version_id]['links'][0]['href'] = req_uri
res.body = helpers.to_json(VERSIONS[version_id])
res.status = falcon.HTTP_200
else:
raise HTTPUnprocessableEntityError('Invalid version',
'No versions found matching ' + version_id)
开发者ID:openstack,项目名称:monasca-api,代码行数:26,代码来源:versions.py
示例12: on_get
def on_get(self, req, res):
helpers.validate_authorization(req, self._get_metrics_authorized_roles)
tenant_id = (
helpers.get_x_tenant_or_tenant_id(req,
self._delegate_authorized_roles))
name = helpers.get_query_name(req, True)
helpers.validate_query_name(name)
dimensions = helpers.get_query_dimensions(req)
helpers.validate_query_dimensions(dimensions)
start_timestamp = helpers.get_query_starttime_timestamp(req)
end_timestamp = helpers.get_query_endtime_timestamp(req, False)
helpers.validate_start_end_timestamps(start_timestamp, end_timestamp)
statistics = helpers.get_query_statistics(req)
period = helpers.get_query_period(req)
offset = helpers.get_query_param(req, 'offset')
merge_metrics_flag = get_merge_metrics_flag(req)
group_by = helpers.get_query_group_by(req)
result = self._metric_statistics(tenant_id, name, dimensions,
start_timestamp, end_timestamp,
statistics, period, req.uri,
offset, req.limit, merge_metrics_flag,
group_by)
res.body = helpers.dumpit_utf8(result)
res.status = falcon.HTTP_200
开发者ID:artur-ba,项目名称:monasca-api,代码行数:26,代码来源:metrics.py
示例13: on_post
def on_post(self, req, res):
helpers.validate_authorization(req, self._default_authorized_roles)
alarm_definition = helpers.read_json_msg_body(req)
self._validate_alarm_definition(alarm_definition)
tenant_id = helpers.get_tenant_id(req)
name = get_query_alarm_definition_name(alarm_definition)
expression = get_query_alarm_definition_expression(alarm_definition)
description = get_query_alarm_definition_description(alarm_definition)
severity = get_query_alarm_definition_severity(alarm_definition)
match_by = get_query_alarm_definition_match_by(alarm_definition)
alarm_actions = get_query_alarm_definition_alarm_actions(
alarm_definition)
undetermined_actions = get_query_alarm_definition_undetermined_actions(
alarm_definition)
ok_actions = get_query_ok_actions(alarm_definition)
result = self._alarm_definition_create(tenant_id, name, expression,
description, severity, match_by,
alarm_actions,
undetermined_actions,
ok_actions)
helpers.add_links_to_resource(result, req.uri)
res.body = helpers.dumpit_utf8(result)
res.status = falcon.HTTP_201
开发者ID:nilwyh,项目名称:monasca-api,代码行数:28,代码来源:alarm_definitions.py
示例14: on_get
def on_get(self, req, res, alarm_id=None):
if alarm_id is None:
helpers.validate_authorization(req, self._default_authorized_roles)
tenant_id = helpers.get_tenant_id(req)
query_parms = falcon.uri.parse_query_string(req.query_string)
offset = helpers.get_query_param(req, 'offset')
limit = helpers.get_limit(req)
result = self._alarm_list(req.uri, tenant_id, query_parms, offset,
limit)
res.body = helpers.dumpit_utf8(result)
res.status = falcon.HTTP_200
else:
helpers.validate_authorization(req, self._default_authorized_roles)
tenant_id = helpers.get_tenant_id(req)
result = self._alarm_show(req.uri, tenant_id, alarm_id)
res.body = helpers.dumpit_utf8(result)
res.status = falcon.HTTP_200
开发者ID:kamil-khamidullin,项目名称:monasca-api,代码行数:25,代码来源:alarms.py
示例15: on_get
def on_get(self, req, res, notification_method_id=None):
if notification_method_id is None:
helpers.validate_authorization(req, self._default_authorized_roles)
tenant_id = helpers.get_tenant_id(req)
sort_by = helpers.get_query_param(req, 'sort_by', default_val=None)
if sort_by is not None:
if isinstance(sort_by, basestring):
sort_by = sort_by.split(',')
allowed_sort_by = {'id', 'name', 'type', 'address',
'updated_at', 'created_at'}
validation.validate_sort_by(sort_by, allowed_sort_by)
offset = helpers.get_query_param(req, 'offset')
limit = helpers.get_limit(req)
result = self._list_notifications(tenant_id, req.uri, sort_by,
offset, limit)
res.body = helpers.dumpit_utf8(result)
res.status = falcon.HTTP_200
else:
helpers.validate_authorization(req,
self._default_authorized_roles)
tenant_id = helpers.get_tenant_id(req)
result = self._list_notification(tenant_id,
notification_method_id,
req.uri)
res.body = helpers.dumpit_utf8(result)
res.status = falcon.HTTP_200
开发者ID:bigluster,项目名称:monasca-api,代码行数:29,代码来源:notifications.py
示例16: on_get
def on_get(self, req, res, notification_method_id=None):
if notification_method_id is None:
helpers.validate_authorization(req,
self._get_notifications_authorized_roles)
sort_by = helpers.get_query_param(req, 'sort_by', default_val=None)
if sort_by is not None:
if isinstance(sort_by, basestring):
sort_by = sort_by.split(',')
allowed_sort_by = {'id', 'name', 'type', 'address',
'updated_at', 'created_at'}
validation.validate_sort_by(sort_by, allowed_sort_by)
offset = helpers.get_query_param(req, 'offset')
if offset is not None and not isinstance(offset, int):
try:
offset = int(offset)
except Exception:
raise HTTPUnprocessableEntityError('Unprocessable Entity',
'Offset value {} must be an integer'
.format(offset))
result = self._list_notifications(req.project_id, req.uri, sort_by,
offset, req.limit)
res.body = helpers.dumpit_utf8(result)
res.status = falcon.HTTP_200
else:
helpers.validate_authorization(req,
self._get_notifications_authorized_roles)
result = self._list_notification(req.project_id,
notification_method_id,
req.uri)
res.body = helpers.dumpit_utf8(result)
res.status = falcon.HTTP_200
开发者ID:jobrs,项目名称:monasca-api,代码行数:35,代码来源:notifications.py
示例17: on_put
def on_put(self, req, res, alarm_id):
helpers.validate_authorization(req, self._default_authorized_roles)
tenant_id = helpers.get_tenant_id(req)
alarm = helpers.read_http_resource(req)
schema_alarm.validate(alarm)
# Validator makes state optional, so check it here
if 'state' not in alarm or not alarm['state']:
raise HTTPUnprocessableEntityError('Unprocessable Entity',
"Field 'state' is required")
if 'lifecycle_state' not in alarm or not alarm['lifecycle_state']:
raise HTTPUnprocessableEntityError('Unprocessable Entity',
"Field 'lifecycle_state' is required")
if 'link' not in alarm or not alarm['link']:
raise HTTPUnprocessableEntityError('Unprocessable Entity',
"Field 'link' is required")
self._alarm_update(tenant_id, alarm_id, alarm['state'],
alarm['lifecycle_state'], alarm['link'])
result = self._alarm_show(req.uri, tenant_id, alarm_id)
res.body = helpers.dumpit_utf8(result)
res.status = falcon.HTTP_200
开发者ID:Missxiaoguo,项目名称:monasca-api,代码行数:27,代码来源:alarms.py
示例18: on_post
def on_post(self, req, res):
helpers.validate_authorization(req, ['api:alarms:definition:post'])
alarm_definition = helpers.from_json(req)
self._validate_alarm_definition(alarm_definition)
name = get_query_alarm_definition_name(alarm_definition)
expression = get_query_alarm_definition_expression(alarm_definition)
description = get_query_alarm_definition_description(alarm_definition)
severity = get_query_alarm_definition_severity(alarm_definition)
match_by = get_query_alarm_definition_match_by(alarm_definition)
alarm_actions = get_query_alarm_definition_alarm_actions(
alarm_definition)
undetermined_actions = get_query_alarm_definition_undetermined_actions(
alarm_definition)
ok_actions = get_query_ok_actions(alarm_definition)
result = self._alarm_definition_create(req.project_id, name, expression,
description, severity, match_by,
alarm_actions,
undetermined_actions,
ok_actions)
helpers.add_links_to_resource(result, req.uri)
res.body = helpers.to_json(result)
res.status = falcon.HTTP_201
开发者ID:openstack,项目名称:monasca-api,代码行数:27,代码来源:alarm_definitions.py
示例19: on_delete
def on_delete(self, req, res, alarm_definition_id=None):
if not alarm_definition_id:
raise HTTPBadRequestError('Bad Request', 'Alarm definition ID not provided')
helpers.validate_authorization(req, ['api:alarms:definition:delete'])
self._alarm_definition_delete(req.project_id, alarm_definition_id)
res.status = falcon.HTTP_204
开发者ID:openstack,项目名称:monasca-api,代码行数:8,代码来源:alarm_definitions.py
示例20: test_role_valid
def test_role_valid(self):
req_roles = 'role0,rOlE1'
authorized_roles = ['RolE1', 'Role2']
req = mock.Mock()
req.get_header.return_value = req_roles
helpers.validate_authorization(req, authorized_roles)
开发者ID:gongwayne,项目名称:Openstack,代码行数:8,代码来源:test_validation.py
注:本文中的monasca_api.v2.reference.helpers.validate_authorization函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论