def check_property_set(self, property_set, path): """ Check a property set """ matches = [] properties = property_set.get('Object') keys = set() attributes = set() for attribute in properties.get('AttributeDefinitions', []): attribute_name = attribute.get('AttributeName') if isinstance(attribute_name, six.string_types): attributes.add(attribute.get('AttributeName')) else: self.logger.info('attribute definitions is not using just strings') return matches keys = keys.union( self._get_key_schema_attributes( properties.get_safe('KeySchema', list_node([], None, None), [], list) ) ) keys = keys.union(self._get_attribute_secondary( properties.get_safe('GlobalSecondaryIndexes', list_node([], None, None), path, list ))) # pylint: disable=bad-continuation keys = keys.union(self._get_attribute_secondary( properties.get_safe('LocalSecondaryIndexes', list_node([], None, None), path, list ))) # pylint: disable=bad-continuation if attributes != keys: message = 'The set of Attributes in AttributeDefinitions: {0} and KeySchemas: {1} must match at {2}' matches.append(RuleMatch( path, message.format(sorted(list(attributes)), sorted(list(keys)), '/'.join(map(str, path))) )) return matches
def construct_getatt(node): """ Reconstruct !GetAtt into a list """ if isinstance(node.value, (six.string_types)): return list_node(node.value.split('.'), node.start_mark, node.end_mark) if isinstance(node.value, list): return list_node([s.value for s in node.value], node.start_mark, node.end_mark) raise ValueError('Unexpected node type: {}'.format(type(node.value)))
def _get_attribute_secondary(self, property_sets): """ Get the key schemas from secondary indexes """ keys = set() for properties, _ in property_sets: for index in properties: keys = keys.union( self._get_key_schema_attributes( index.get_safe('KeySchema', list_node([], None, None), [], list))) return keys
def _correct_objects_loop(self, template): """ Looping for dynamic depths and types """ if isinstance(template, dict): if not isinstance(template, dict_node): template = dict_node(template, (0, 0), (0, 0)) for k, v in template.items(): template[k] = self._correct_objects_loop(v) elif isinstance(template, list): if not isinstance(template, list_node): template = list_node(template, (0, 0), (0, 0)) for i, v in enumerate(template): template[i] = self._correct_objects_loop(v) return template
def convert_dict(template, start_mark=(0, 0), end_mark=(0, 0)): """Convert dict to template""" if isinstance(template, dict): if not isinstance(template, dict_node): template = dict_node(template, start_mark, end_mark) for k, v in template.copy().items(): k_start_mark = start_mark k_end_mark = end_mark if isinstance(k, str_node): k_start_mark = k.start_mark k_end_mark = k.end_mark new_k = str_node(k, k_start_mark, k_end_mark) del template[k] template[new_k] = convert_dict(v, k_start_mark, k_end_mark) elif isinstance(template, list): if not isinstance(template, list_node): template = list_node(template, start_mark, end_mark) for i, v in enumerate(template): template[i] = convert_dict(v, start_mark, end_mark) return template
def construct_yaml_seq(self, node): obj, = SafeConstructor.construct_yaml_seq(self, node) assert isinstance(obj, list) return list_node(obj, node.start_mark, node.end_mark)
def JSONArray(self, s_and_end, scan_once, **kwargs): """ Convert JSON array to be a list_node object """ values, end = json.decoder.JSONArray(s_and_end, scan_once, **kwargs) s, start = s_and_end beg_mark, end_mark = get_beg_end_mark(s, start, end) return list_node(values, beg_mark, end_mark), end