Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _get_type(self, context):
return get_type_by_name(context, self.type, 'relationship_types')
def validator(field, presentation, context):
field.default_validate(presentation, context)
value = getattr(presentation, field.name)
if value is not None:
# Test for circular definitions
container_data_type = get_container_data_type(presentation)
if (container_data_type is not None) and (container_data_type._name == value):
context.validation.report(
u'type of property "{0}" creates a circular value hierarchy: {1}'
.format(presentation._fullname, safe_repr(value)),
locator=presentation._get_child_locator('type'), level=Issue.BETWEEN_TYPES)
# Can be a complex data type
if get_type_by_name(context, value, 'data_types') is not None:
return True
# Can be a primitive data type
if get_primitive_data_type(value) is None:
report_issue_for_unknown_type(context, presentation, type_name, field.name)
return False
def _get_node(self, context):
node = self.node
if node is not None:
node_template = context.presentation.get_from_dict('service_template',
'topology_template',
'node_templates', node)
if node_template is not None:
return node_template, 'node_template'
node_type = get_type_by_name(context, node, 'node_types')
if node_type is not None:
return node_type, 'node_type'
return None, None
def merge_raw_parameter_definition(context, presentation, raw_property_definition,
our_property_definition, field_name, property_name):
# Check if we changed the parameter type
type1_name = raw_property_definition.get('type')
type1 = get_type_by_name(context, type1_name, 'data_types')
if type1 is None:
type1 = get_primitive_data_type(type1_name)
our_property_definition._reset_method_cache()
type2 = our_property_definition._get_type(context)
if (type1 is not type2) and \
(not hasattr(type1, '_is_descendant') or not type1._is_descendant(context, type2)):
context.validation.report(
u'property definition type "{0}" is not a descendant of overridden '
u'property definition type "{1}"' \
.format(our_property_definition.type, type1_name),
locator=presentation._get_child_locator(field_name, property_name),
level=Issue.BETWEEN_TYPES)
merge(raw_property_definition, our_property_definition._raw)
Makes sure that the field refers to either a relationship template or a relationship type.
Used with the :func:`field_validator` decorator for the ``type`` field in
:class:`RelationshipAssignment`.
"""
field.default_validate(presentation, context)
value = getattr(presentation, field.name)
if value is not None:
relationship_templates = \
context.presentation.get('service_template', 'topology_template',
'relationship_templates') \
or {}
if (value not in relationship_templates) and \
(get_type_by_name(context, value, 'relationship_types') is None):
report_issue_for_unknown_type(context, presentation,
'relationship template or relationship type', field.name)
def _get_type(self, context):
return get_type_by_name(context, self.type, 'artifact_types')
def _get_type(self, context):
return get_type_by_name(context, self.node_type, 'node_types')
def _get_type(self, context):
return get_type_by_name(context, self.type, 'node_types')
def _get_type(self, context):
return get_type_by_name(context, self.type, 'group_types')
def list_node_type_or_group_type_validator(field, presentation, context):
"""
Makes sure that the field's elements refer to either node types or a group types.
Used with the :func:`field_validator` decorator for the ``targets`` field in
:class:`PolicyType`.
"""
field.default_validate(presentation, context)
values = getattr(presentation, field.name)
if values is not None:
for value in values:
if (get_type_by_name(context, value, 'node_types') is None) and \
(get_type_by_name(context, value, 'group_types') is None):
report_issue_for_unknown_type(context, presentation, 'node type or group type',
field.name, value)