google.cloud.forseti.scanner.audit.rules module

Rules-related classes.

class Rule(rule_name, rule_index, bindings, mode=None)[source]

Bases: object

Encapsulate Rule properties from the rule definition file.

The reason this is not a named tuple is that it needs to be hashable. The ResourceRules class has a set of Rules.

__eq__(other)[source]

Test whether Rule equals other Rule.

Parameters:other (object) – The other object to compare.
Returns:True if equals, otherwise False.
Return type:bool
__hash__()[source]

Make a hash of the rule index.

For now, this will suffice since the rule index is assigned automatically when the rules map is built, and the scanner only handles one rule file at a time. Later on, we’ll need to revisit this hash method when we process multiple rule files.

Returns:The hash of the rule index.
Return type:int
__ne__(other)[source]

Test whether Rule is not equal to another Rule.

Parameters:other (object) – The other object to compare.
Returns:True if not equals, otherwise False.
Return type:bool
__repr__()[source]

Returns the string representation of this Rule.

Returns:The representation of the Rule.
Return type:str
class RuleAppliesTo[source]

Bases: object

What the rule applies to. (Default: SELF)

CHILDREN = 'children'
SELF = 'self'
SELF_AND_CHILDREN = 'self_and_children'
apply_types = frozenset(['self', 'children', 'self_and_children'])
classmethod verify(applies_to)[source]

Verify whether the applies_to is valid.

Parameters:applies_to (str) – What the rule applies to.
Returns:The applies_to property.
Return type:str
Raises:InvalidRulesSchemaError if applies_to is not valid.
class RuleMode[source]

Bases: object

The rule mode.

BLACKLIST = 'blacklist'
MATCHES = 'matches'
REQUIRED = 'required'
WHITELIST = 'whitelist'
modes = frozenset(['blacklist', 'matches', 'whitelist', 'required'])
classmethod verify(mode)[source]

Verify whether the mode is valid.

Parameters:mode (str) – The rules mode.
Returns:The rules mode property.
Return type:str
Raises:InvalidRulesSchemaError if mode is not valid.
class RuleViolation(resource_type, resource_id, full_name, rule_name, rule_index, violation_type, role, members, resource_data)

Bases: tuple

__getnewargs__()

Return self as a plain tuple. Used by copy and pickle.

__getstate__()

Exclude the OrderedDict from pickling

__repr__()

Return a nicely formatted representation string

_asdict()

Return a new OrderedDict which maps field names to their values

_fields = ('resource_type', 'resource_id', 'full_name', 'rule_name', 'rule_index', 'violation_type', 'role', 'members', 'resource_data')
classmethod _make(iterable, new=<built-in method __new__ of type object>, len=<built-in function len>)

Make a new RuleViolation object from a sequence or iterable

_replace(**kwds)

Return a new RuleViolation object replacing specified fields with new values

full_name
members
resource_data
resource_id
resource_type
role
rule_index
rule_name
violation_type