Ejemplo n.º 1
0
    def get_attribute_dict(self, add_hash=True) -> Dict[str, Any]:
        """
           :return: map of all the block's native attributes (from the source file),
           combined with the attributes generated by the module builder.
           If the attributes are not a primitive type, they are converted to strings.
           """
        base_attributes = self.get_base_attributes()
        self.get_origin_attributes(base_attributes)

        if self.changed_attributes:
            # add changed attributes only for calculating the hash
            base_attributes["changed_attributes"] = sorted(
                self.changed_attributes.keys())

        if self.breadcrumbs:
            sorted_breadcrumbs = dict(sorted(self.breadcrumbs.items()))
            base_attributes[
                CustomAttributes.RENDERING_BREADCRUMBS] = sorted_breadcrumbs

        if add_hash:
            base_attributes[CustomAttributes.HASH] = calculate_hash(
                base_attributes)

        if "changed_attributes" in base_attributes:
            # removed changed attributes if it was added previously for calculating hash.
            del base_attributes["changed_attributes"]

        return base_attributes
Ejemplo n.º 2
0
    def get_attribute_dict(self, add_hash=True) -> Dict[str, Any]:
        """
           :return: map of all the block's native attributes (from the source file),
           combined with the attributes generated by the module builder.
           If the attributes are not a primitive type, they are converted to strings.
           """
        base_attributes = self.get_base_attributes()
        self.get_origin_attributes(base_attributes)

        if hasattr(self, "module_dependency") and hasattr(self, "module_dependency_num"):
            base_attributes[CustomAttributes.MODULE_DEPENDENCY] = self.module_dependency
            base_attributes[CustomAttributes.MODULE_DEPENDENCY_NUM] = self.module_dependency_num

        if self.changed_attributes:
            # add changed attributes only for calculating the hash
            base_attributes["changed_attributes"] = sorted(self.changed_attributes.keys())

        if self.breadcrumbs:
            sorted_breadcrumbs = dict(sorted(self.breadcrumbs.items()))
            base_attributes[CustomAttributes.RENDERING_BREADCRUMBS] = sorted_breadcrumbs

        if add_hash:
            base_attributes[CustomAttributes.HASH] = calculate_hash(base_attributes)

        if self.block_type == BlockType.DATA:
            base_attributes[CustomAttributes.RESOURCE_TYPE] = f'data.{self.id.split(".")[0]}'

        if "changed_attributes" in base_attributes:
            # removed changed attributes if it was added previously for calculating hash.
            del base_attributes["changed_attributes"]

        return base_attributes
Ejemplo n.º 3
0
 def order_edges_by_hash_codes(self) -> Dict[str, Edge]:
     edges = {}
     for edge in self.edges:
         edge_data = {
             "edge_label": edge.label,
             "from_vertex_hash": self.get_vertex_hash_by_index(vertex_index=edge.origin),
             "to_vertex_hash": self.get_vertex_hash_by_index(vertex_index=edge.dest),
         }
         edge_hash = calculate_hash(edge_data)
         edges[edge_hash] = edge
     return edges
Ejemplo n.º 4
0
    def test_single_edge_with_same_label(self):
        resources_dir = os.path.realpath(
            os.path.join(TEST_DIRNAME, '../resources/k8_service'))

        graph_manager = TerraformGraphManager(NetworkxConnector())
        local_graph, _ = graph_manager.build_graph_from_source_directory(
            resources_dir, render_variables=True)
        edges_hash = []
        for e in local_graph.edges:
            edge_hash = calculate_hash({
                "origin": e.origin,
                "dest": e.dest,
                "label": e.label
            })
            if edge_hash in edges_hash:
                origin = local_graph.vertices[e.origin]
                dest = local_graph.vertices[e.dest]
                self.fail(
                    f'edge {e} == [{origin} - {e.label} -> {dest}] appears more than once in the graph'
                )
            else:
                edges_hash.append(edge_hash)