Database access objects for Forseti Scanner.
ScannerIndex
(**kwargs)[source]¶Bases: sqlalchemy.ext.declarative.api.Base
Represents a scanner run.
__repr__
()[source]¶Object string representation.
Returns: | String representation of the object. |
---|---|
Return type: | str |
_sa_class_manager
= {'completed_at_datetime': <sqlalchemy.orm.attributes.InstrumentedAttribute object at 0x7f73d1d18048>, 'created_at_datetime': <sqlalchemy.orm.attributes.InstrumentedAttribute object at 0x7f73d21faf68>, 'id': <sqlalchemy.orm.attributes.InstrumentedAttribute object at 0x7f73d21fae08>, 'inventory_index_id': <sqlalchemy.orm.attributes.InstrumentedAttribute object at 0x7f73d21faeb8>, 'message': <sqlalchemy.orm.attributes.InstrumentedAttribute object at 0x7f73d1d183b8>, 'scanner_index_errors': <sqlalchemy.orm.attributes.InstrumentedAttribute object at 0x7f73d1d18308>, 'scanner_index_warnings': <sqlalchemy.orm.attributes.InstrumentedAttribute object at 0x7f73d1d18258>, 'scanner_status': <sqlalchemy.orm.attributes.InstrumentedAttribute object at 0x7f73d1d180f8>, 'schema_version': <sqlalchemy.orm.attributes.InstrumentedAttribute object at 0x7f73d1d181a8>}¶add_warning
(session, warning)[source]¶Add a warning to the scanner.
Parameters: |
|
---|
complete
(status='SUCCESS')[source]¶Mark the scanner as completed with a final scanner_status.
Parameters: | status (str) – Final scanner_status. |
---|
completed_at_datetime
¶create
(inv_index_id)[source]¶Create a new scanner index row.
Parameters: | inv_index_id (str) – Id of the inventory index. |
---|---|
Returns: | ScannerIndex row object. |
Return type: | object |
created_at_datetime
¶id
¶inventory_index_id
¶message
¶scanner_index_errors
¶scanner_index_warnings
¶scanner_status
¶schema_version
¶Violation
(**kwargs)[source]¶Bases: sqlalchemy.ext.declarative.api.Base
Row entry for a violation.
__repr__
()[source]¶String representation.
Returns: | string representation of the Violation row entry. |
---|---|
Return type: | str |
_sa_class_manager
= {'created_at_datetime': <sqlalchemy.orm.attributes.InstrumentedAttribute object at 0x7f73d1d18620>, 'full_name': <sqlalchemy.orm.attributes.InstrumentedAttribute object at 0x7f73d1d186d0>, 'id': <sqlalchemy.orm.attributes.InstrumentedAttribute object at 0x7f73d1d18518>, 'resource_data': <sqlalchemy.orm.attributes.InstrumentedAttribute object at 0x7f73d1d18780>, 'resource_id': <sqlalchemy.orm.attributes.InstrumentedAttribute object at 0x7f73d1d188e0>, 'resource_name': <sqlalchemy.orm.attributes.InstrumentedAttribute object at 0x7f73d1d18830>, 'resource_type': <sqlalchemy.orm.attributes.InstrumentedAttribute object at 0x7f73d1d18990>, 'rule_index': <sqlalchemy.orm.attributes.InstrumentedAttribute object at 0x7f73d1d18a40>, 'rule_name': <sqlalchemy.orm.attributes.InstrumentedAttribute object at 0x7f73d1d18af0>, 'scanner_index_id': <sqlalchemy.orm.attributes.InstrumentedAttribute object at 0x7f73d1d18ba0>, 'violation_data': <sqlalchemy.orm.attributes.InstrumentedAttribute object at 0x7f73d1d18c50>, 'violation_hash': <sqlalchemy.orm.attributes.InstrumentedAttribute object at 0x7f73d1d18d00>, 'violation_message': <sqlalchemy.orm.attributes.InstrumentedAttribute object at 0x7f73d1d18db0>, 'violation_type': <sqlalchemy.orm.attributes.InstrumentedAttribute object at 0x7f73d1d18e60>}¶created_at_datetime
¶full_name
¶get_schema_update_actions
()[source]¶Maintain all the schema changes for this table.
Returns: | A mapping of Action: Column. |
---|---|
Return type: | dict |
id
¶resource_data
¶resource_id
¶resource_name
¶resource_type
¶rule_index
¶rule_name
¶scanner_index_id
¶violation_data
¶violation_hash
¶violation_message
¶violation_type
¶ViolationAccess
(session)[source]¶Bases: object
Facade for violations, implement APIs against violations table.
create
(violations, scanner_index_id)[source]¶Save violations to the db table.
Parameters: |
|
---|
list
(inv_index_id=None, scanner_index_id=None)[source]¶List all violations from the db table.
NOTA BENE: do NOT call this method with both indices!
Parameters: |
|
---|---|
Returns: | List of Violation row entry objects. |
Return type: | list |
Raises: |
|
_create_violation_hash
(violation_full_name, resource_data, violation_data)[source]¶Create a hash of violation data.
Parameters: |
|
---|---|
Returns: | The resulting hex digest or ‘’ if we can’t successfully create a hash. |
Return type: | str |
convert_sqlalchemy_object_to_dict
(sqlalchemy_obj)[source]¶Convert a sqlalchemy row/record object to a dictionary.
Parameters: | sqlalchemy_obj (sqlalchemy_object) – A sqlalchemy row/record object |
---|---|
Returns: | A dict of sqlalchemy object’s attributes. |
Return type: | dict |
get_latest_scanner_index_id
(session, inv_index_id, index_state=None)[source]¶Return last ScannerIndex row with the given state or None.
Either return the latest ScannerIndex row where the scanner_status matches the given index_state parameter (if passed) or the latest row that represents a (partially) successful scanner run.
Parameters: |
|
---|---|
Returns: | the latest ScannerIndex row or None |
Return type: | sqlalchemy_object |
initialize
(engine)[source]¶Create all tables in the database if not existing.
Parameters: | engine (object) – Database engine to operate on. |
---|
map_by_resource
(violation_rows)[source]¶Create a map of violation types to violations of that resource.
Parameters: | violation_rows (list) – A list of dict of violation data. |
---|---|
Returns: |
|
Return type: | dict |