本文整理汇总了Python中st2common.models.api.action.ActionAPI.validate方法的典型用法代码示例。如果您正苦于以下问题:Python ActionAPI.validate方法的具体用法?Python ActionAPI.validate怎么用?Python ActionAPI.validate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类st2common.models.api.action.ActionAPI
的用法示例。
在下文中一共展示了ActionAPI.validate方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _register_action
# 需要导入模块: from st2common.models.api.action import ActionAPI [as 别名]
# 或者: from st2common.models.api.action.ActionAPI import validate [as 别名]
def _register_action(self, pack, action):
content = self._meta_loader.load(action)
pack_field = content.get('pack', None)
if not pack_field:
content['pack'] = pack
pack_field = pack
if pack_field != pack:
raise Exception('Model is in pack "%s" but field "pack" is different: %s' %
(pack, pack_field))
action_api = ActionAPI(**content)
action_api.validate()
action_validator.validate_action(action_api)
model = ActionAPI.to_model(action_api)
action_ref = ResourceReference.to_string_reference(pack=pack, name=str(content['name']))
existing = action_utils.get_action_by_ref(action_ref)
if not existing:
LOG.debug('Action %s not found. Creating new one with: %s', action_ref, content)
else:
LOG.debug('Action %s found. Will be updated from: %s to: %s',
action_ref, existing, model)
model.id = existing.id
try:
model = Action.add_or_update(model)
extra = {'action_db': model}
LOG.audit('Action updated. Action %s from %s.', model, action, extra=extra)
except Exception:
LOG.exception('Failed to write action to db %s.', model.name)
raise
示例2: _register_action
# 需要导入模块: from st2common.models.api.action import ActionAPI [as 别名]
# 或者: from st2common.models.api.action.ActionAPI import validate [as 别名]
def _register_action(self, pack, action):
content = self._meta_loader.load(action)
pack_field = content.get('pack', None)
if not pack_field:
content['pack'] = pack
pack_field = pack
if pack_field != pack:
raise Exception('Model is in pack "%s" but field "pack" is different: %s' %
(pack, pack_field))
action_api = ActionAPI(**content)
try:
action_api.validate()
except jsonschema.ValidationError as e:
# We throw a more user-friendly exception on invalid parameter name
msg = str(e)
is_invalid_parameter_name = 'does not match any of the regexes: ' in msg
if is_invalid_parameter_name:
match = re.search('\'(.+?)\' does not match any of the regexes', msg)
if match:
parameter_name = match.groups()[0]
else:
parameter_name = 'unknown'
new_msg = ('Parameter name "%s" is invalid. Valid characters for parameter name '
'are [a-zA-Z0-0_].' % (parameter_name))
new_msg += '\n\n' + msg
raise jsonschema.ValidationError(new_msg)
raise e
action_validator.validate_action(action_api)
model = ActionAPI.to_model(action_api)
action_ref = ResourceReference.to_string_reference(pack=pack, name=str(content['name']))
existing = action_utils.get_action_by_ref(action_ref)
if not existing:
LOG.debug('Action %s not found. Creating new one with: %s', action_ref, content)
else:
LOG.debug('Action %s found. Will be updated from: %s to: %s',
action_ref, existing, model)
model.id = existing.id
try:
model = Action.add_or_update(model)
extra = {'action_db': model}
LOG.audit('Action updated. Action %s from %s.', model, action, extra=extra)
except Exception:
LOG.exception('Failed to write action to db %s.', model.name)
raise
示例3: _register_action
# 需要导入模块: from st2common.models.api.action import ActionAPI [as 别名]
# 或者: from st2common.models.api.action.ActionAPI import validate [as 别名]
def _register_action(self, pack, action):
content = self._meta_loader.load(action)
pack_field = content.get('pack', None)
if not pack_field:
content['pack'] = pack
pack_field = pack
if pack_field != pack:
raise Exception('Model is in pack "%s" but field "pack" is different: %s' %
(pack, pack_field))
# Add in "metadata_file" attribute which stores path to the pack metadata file relative to
# the pack directory
metadata_file = content_utils.get_relative_path_to_pack_file(pack_ref=pack,
file_path=action,
use_pack_cache=True)
content['metadata_file'] = metadata_file
action_api = ActionAPI(**content)
try:
action_api.validate()
except jsonschema.ValidationError as e:
# We throw a more user-friendly exception on invalid parameter name
msg = six.text_type(e)
is_invalid_parameter_name = 'does not match any of the regexes: ' in msg
if is_invalid_parameter_name:
match = re.search('\'(.+?)\' does not match any of the regexes', msg)
if match:
parameter_name = match.groups()[0]
else:
parameter_name = 'unknown'
new_msg = ('Parameter name "%s" is invalid. Valid characters for parameter name '
'are [a-zA-Z0-0_].' % (parameter_name))
new_msg += '\n\n' + msg
raise jsonschema.ValidationError(new_msg)
raise e
# Use in-memory cached RunnerTypeDB objects to reduce load on the database
if self._use_runners_cache:
runner_type_db = self._runner_type_db_cache.get(action_api.runner_type, None)
if not runner_type_db:
runner_type_db = action_validator.get_runner_model(action_api)
self._runner_type_db_cache[action_api.runner_type] = runner_type_db
else:
runner_type_db = None
action_validator.validate_action(action_api, runner_type_db=runner_type_db)
model = ActionAPI.to_model(action_api)
action_ref = ResourceReference.to_string_reference(pack=pack, name=str(content['name']))
existing = action_utils.get_action_by_ref(action_ref)
if not existing:
LOG.debug('Action %s not found. Creating new one with: %s', action_ref, content)
else:
LOG.debug('Action %s found. Will be updated from: %s to: %s',
action_ref, existing, model)
model.id = existing.id
try:
model = Action.add_or_update(model)
extra = {'action_db': model}
LOG.audit('Action updated. Action %s from %s.', model, action, extra=extra)
except Exception:
LOG.exception('Failed to write action to db %s.', model.name)
raise