altimeter.core.graph package

Submodules

altimeter.core.graph.exceptions module

Exceptions related ton Graphing

exception DuplicateResourceIdsFoundException

Bases: altimeter.core.exceptions.AltimeterException

Duplicate resource ids were found

exception GraphSetOrphanedReferencesException

Bases: altimeter.core.exceptions.AltimeterException

A GraphSet contained orphaned references, for instance a ResourceLink referring to an id not present in the GraphSet.

exception LinkParseException

Bases: altimeter.core.exceptions.AltimeterException

Error parsing Links from JSON.

exception ListFieldSourceKeyNotFoundException

Bases: altimeter.core.exceptions.AltimeterException

The source_key of a ListField was not found

exception ListFieldValueNotAListException

Bases: altimeter.core.exceptions.AltimeterException

A ListField does not contain a list

exception SchemaParseException

Bases: altimeter.core.exceptions.AltimeterException

Schema.parse error

exception UnmergableDuplicateResourceIdsFoundException

Bases: altimeter.core.exceptions.AltimeterException

Duplicate unmergable resource ids were found

exception UnmergableGraphSetsException

Bases: altimeter.core.exceptions.AltimeterException

GraphSets are unable to be merged.

altimeter.core.graph.graph_set module

A GraphSet represents the contents of a Graph.

class GraphSet(**data)

Bases: altimeter.core.base_model.BaseImmutableModel

A GraphSet represents the contents of a Graph. It contains a list of Resource objects, a graph name and version and a few metadata fields describing the scan. Generally GraphSets are created by running GraphSpec.scan.

Parameters
  • name – graph name

  • version – graph version

  • start_time – epoch scan start time

  • end_time – epoch scan end time

  • resources – Resource objects

  • errors – Errors encountered during scan

end_time: int
errors: List[str]
classmethod from_graph_sets(graph_sets)

Create a new GraphSet from a list of GraphSets

Return type

GraphSet

classmethod from_json_file(path)
Return type

GraphSet

name: str
resources: Tuple[altimeter.core.resource.resource.Resource, ]
start_time: int
version: str
class ValidatedGraphSet(**data)

Bases: altimeter.core.graph.graph_set.GraphSet

A GraphSet which has been validated - duplicate resources have been merged and required resource links have been verified

classmethod dedupe_and_validate_resources(resources)
Return type

Tuple[Resource, …]

end_time: int
errors: List[str]
classmethod from_graph_set(graph_set)

Create a ValidatedGraphSet from a GraphSet

Return type

ValidatedGraphSet

name: str
resources: Tuple[altimeter.core.resource.resource.Resource, ]
start_time: int
to_neptune_lpg(scan_id)
Return type

Dict

to_rdf()

Generate an rdflib.Graph from this ValidatedGraphSet.

Return type

Graph

Returns

rdf.Graph object representing this ValidatedGraphSet.

version: str
dedupe_resources(resources)

Resolve any duplicate resource ids. In general duplicate resource ids can have their Resource objects merged if they are of the same type and all fields are identical or additive only across the resources or if one of the Resources allows a special merge via its ResourceSpec class’ allow_clobber attribute.

Return type

Tuple[Resource, …]

validate_resources(resources)

Validate that all inter-resource relationships in a tuple of Resources are valid and that there are no duplicate resource ids.

Raises
  • GraphSetOrphanedReferencesException if references to Resources are found in – the graph which do not exist. For example, if an EC2 instance has a VPC and references it as a ResourceLinkField if that VPC is not found as a Resource in the graph this exception is raised.

  • DuplicateResourceIdsFoundException if duplicate resource ids are found

Return type

None

altimeter.core.graph.graph_spec module

A GraphSpec contains a specification to scan and create a graph.

class GraphSpec(name, version, resource_spec_classes, scan_accessor)

Bases: object

A GraphSpec contains a specification to scan and create a graph. It contains a set of ResourceSpec classes defining what to scan and a scan_accessor object defining how to scan.

Parameters
  • name (str) – graph name

  • version (str) – graph version

  • resource_spec_classes (Tuple[Type[ResourceSpec], …]) – tuple of ResourceSpec classes

  • scan_accessor (Any) – object which is passed to ResourceSpec.scan for each ResourceSpec in resource_spec_classes. It should provide methods which ResourceSpec.scan can use to access whatever API the ResourceSpec needs to access.

scan()

Perform a scan on all of the resource classes in this GraphSpec and return a list of Resource objects.

Return type

List[Resource]

Returns

List of Resource objects

altimeter.core.graph.node_cache module

A NodeCache is a simple cache for graph nodes.

class NodeCache

Bases: dict

A NodeCache is a simple cache for graph nodes. Unlike a standard dict it does not allow overwriting entries.

altimeter.core.graph.schema module

A Schema consists of a list of Fields which define how to parse an arbitrary dictionary into a list of Links.

class Schema(*fields)

Bases: object

A Schema consists of a list of Fields which define how to parse an arbitrary dictionary into a altimeter.core.graph.links.LinkCollection.

Parameters

fields (Field) – fields for this Schema.

parse(data, context)

Parse this schema into a list of Links

Parameters
  • data (Dict[str, Any]) – raw data to parse

  • context (Dict[str, Any]) – contains auxiliary information which can be passed through the parse process.

Return type

LinkCollection

Returns

LinkCollection

Module contents