Class: CommandTower::Configuration::Registry::Audit::EventDefinition

Inherits:
Object
  • Object
show all
Includes:
ClassComposer::Generator
Defined in:
lib/command_tower/configuration/registry/audit/event_definition.rb

Constant Summary collapse

RETENTIONS =
%i[permanent ninety_days one_year].freeze
SUBJECT_TYPE =
/\A[A-Z][A-Za-z0-9_:]*\z/

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#ownerObject

Returns the value of attribute owner.



74
75
76
# File 'lib/command_tower/configuration/registry/audit/event_definition.rb', line 74

def owner
  @owner
end

Instance Method Details

#enabled?Boolean

Returns:

  • (Boolean)


76
77
78
# File 'lib/command_tower/configuration/registry/audit/event_definition.rb', line 76

def enabled?
  enabled == true
end

#enablement_configurable?Boolean

Returns:

  • (Boolean)


80
81
82
# File 'lib/command_tower/configuration/registry/audit/event_definition.rb', line 80

def enablement_configurable?
  enablement_configurable == true
end

#global_visible_in_host_scope?Boolean

Returns:

  • (Boolean)


84
85
86
# File 'lib/command_tower/configuration/registry/audit/event_definition.rb', line 84

def global_visible_in_host_scope?
  global_visible_in_host_scope == true
end

#normalize_field_list!(values, field:, name:) ⇒ Object



112
113
114
115
116
117
118
119
120
121
122
# File 'lib/command_tower/configuration/registry/audit/event_definition.rb', line 112

def normalize_field_list!(values, field:, name:)
  Array(values).map do |value|
    segment = value.to_s
    unless segment.match?(CommandTower::Events::SEGMENT)
      raise CommandTower::Audit::InvalidEventDefinitionError,
        "audit event #{name} #{field} contains invalid token #{value.inspect}"
    end

    segment.to_sym
  end
end

#normalize_subject_type!(value, name:) ⇒ Object



141
142
143
144
145
146
147
148
149
150
# File 'lib/command_tower/configuration/registry/audit/event_definition.rb', line 141

def normalize_subject_type!(value, name:)
  token = value.to_s.strip
  return "" if token.empty?
  unless SUBJECT_TYPE.match?(token)
    raise CommandTower::Audit::InvalidEventDefinitionError,
      "audit event #{name} subject_type is invalid #{value.inspect}"
  end

  token
end

#normalize_tags!(values, name:) ⇒ Object

Lowercase, stripped, unique, deterministic. Rejects blank / invalid tokens.



125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/command_tower/configuration/registry/audit/event_definition.rb', line 125

def normalize_tags!(values, name:)
  Array(values).filter_map do |value|
    tag = value.to_s.strip.downcase
    next if tag.empty?

    unless tag.match?(/\A[a-z0-9_]+\z/)
      raise CommandTower::Audit::InvalidEventDefinitionError,
        "audit event #{name} tags contains invalid token #{value.inspect}"
    end

    tag
  end.uniq.sort
end

#validate_policy!(name:) ⇒ Object



88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/command_tower/configuration/registry/audit/event_definition.rb', line 88

def validate_policy!(name:)
  unless RETENTIONS.include?(retention.to_sym)
    raise CommandTower::Audit::InvalidEventDefinitionError,
      "audit event #{name} has invalid retention #{retention.inspect} " \
      "(allowed: #{RETENTIONS.join(", ")})"
  end

  normalized_allowed = normalize_field_list!(allowed_changes, field: "allowed_changes", name:)
  normalized_sensitive = normalize_field_list!(sensitive_fields, field: "sensitive_fields", name:)
  extra_sensitive = normalized_sensitive - normalized_allowed
  if extra_sensitive.any?
    raise CommandTower::Audit::InvalidEventDefinitionError,
      "audit event #{name} sensitive_fields #{extra_sensitive.inspect} " \
      "must be included in allowed_changes"
  end

  self.allowed_changes = normalized_allowed
  self.sensitive_fields = normalized_sensitive
  self.tags = normalize_tags!(tags, name:)
  self.subject_type = normalize_subject_type!(subject_type, name:)
  self.retention = retention.to_sym
  self.owner = owner&.to_sym || :host
end