Class: Smplkit::Management::ForwardersNamespace

Inherits:
Object
  • Object
show all
Defined in:
lib/smplkit/management/audit.rb

Overview

mgmt.audit.forwarders.* — manage the customer’s configured SIEM forwarders.

The active-record entry point is #new_forwarder: instantiate a draft, mutate fields, then call Audit::Forwarder#save. The namespace exposes #list, #get, and #delete directly; the _create_forwarder / _update_forwarder helpers are private and invoked by Audit::Forwarder#save.

Instance Method Summary collapse

Constructor Details

#initialize(api) ⇒ ForwardersNamespace

Returns a new instance of ForwardersNamespace.



30
31
32
# File 'lib/smplkit/management/audit.rb', line 30

def initialize(api)
  @api = api
end

Instance Method Details

#_create_forwarder(forwarder) ⇒ Object



134
135
136
137
138
139
140
141
# File 'lib/smplkit/management/audit.rb', line 134

def _create_forwarder(forwarder)
  if forwarder.id.nil? || forwarder.id.empty?
    raise ArgumentError, "Forwarder.id is required on create (caller-supplied key)"
  end

  resp = Smplkit::Audit.call_api { @api.create_forwarder(build_create_body(forwarder)) }
  Smplkit::Audit::Forwarder.from_resource(resp.data, client: self)
end

#_update_forwarder(forwarder) ⇒ Object

Header values must be re-supplied as plaintext; the GET path redacts them, so a PUT body containing “<redacted>” would persist that literal. Track real header values client-side and round-trip them.

Raises:

  • (ArgumentError)


150
151
152
153
154
155
# File 'lib/smplkit/management/audit.rb', line 150

def _update_forwarder(forwarder)
  raise ArgumentError, "cannot update a Forwarder with no id" if forwarder.id.nil?

  resp = Smplkit::Audit.call_api { @api.update_forwarder(forwarder.id, build_body(forwarder)) }
  Smplkit::Audit::Forwarder.from_resource(resp.data, client: self)
end

#delete(forwarder_id) ⇒ nil

Soft-delete a forwarder.

Parameters:

  • forwarder_id (String)

Returns:

  • (nil)


127
128
129
130
# File 'lib/smplkit/management/audit.rb', line 127

def delete(forwarder_id)
  Smplkit::Audit.call_api { @api.delete_forwarder(forwarder_id) }
  nil
end

#get(forwarder_id) ⇒ Smplkit::Audit::Forwarder

Fetch a single forwarder by id. The returned instance is bound to this namespace, so forwarder.save and forwarder.delete work.

Parameters:

  • forwarder_id (String)

Returns:



118
119
120
121
# File 'lib/smplkit/management/audit.rb', line 118

def get(forwarder_id)
  resp = Smplkit::Audit.call_api { @api.get_forwarder(forwarder_id) }
  Smplkit::Audit::Forwarder.from_resource(resp.data, client: self)
end

#list(forwarder_type: nil, page_number: nil, page_size: nil, meta_total: nil) ⇒ ForwarderListPage

List forwarders for the authenticated account.

Offset paginated per ADR-014: pass page_number (1-based) and page_size (default 1000, max 1000). Pass meta_total: true to populate total and total_pages in the returned pagination block (costs an extra COUNT query server-side).

Returns:



99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/smplkit/management/audit.rb', line 99

def list(forwarder_type: nil, page_number: nil, page_size: nil, meta_total: nil)
  opts = {}
  opts[:filter_forwarder_type] = Smplkit::Audit::ForwarderType.coerce(forwarder_type) if forwarder_type
  opts[:page_number] = page_number if page_number
  opts[:page_size] = page_size if page_size
  opts[:meta_total] = meta_total unless meta_total.nil?

  resp = Smplkit::Audit.call_api { @api.list_forwarders(opts) }
  forwarders = (resp.data || []).map do |r|
    Smplkit::Audit::Forwarder.from_resource(r, client: self)
  end
  ForwarderListPage.new(forwarders, Smplkit::Audit.extract_pagination(resp.meta))
end

#new_forwarder(id, forwarder_type:, configuration:, name: nil, environments: nil, description: nil, forward_smplkit_events: false, filter: nil, transform: nil, transform_type: nil) ⇒ Smplkit::Audit::Forwarder

Construct an unsaved Audit::Forwarder bound to this namespace. Call #save on the returned instance to persist.

Parameters:

  • name (String) (defaults to: nil)

    Display name.

  • forwarder_type (String)
  • configuration (Smplkit::Audit::HttpConfiguration)

    Destination request configuration. Headers carry credentials and are encrypted at rest server-side; reads return them redacted.

  • environments (Hash{String => Smplkit::Audit::ForwarderEnvironment, Hash}, nil) (defaults to: nil)

    Per-environment overrides keyed by environment key (e.g. “production”). A forwarder delivers in an environment only when that environment’s entry has enabled: true. Values may be Audit::ForwarderEnvironment instances or plain hashes (+{ enabled: true }+, optionally with a :configuration Audit::HttpConfiguration override). Omit to create a forwarder that delivers nowhere until enabled per environment.

  • description (String, nil) (defaults to: nil)

    Optional free-text description.

  • forward_smplkit_events (Boolean) (defaults to: false)

    When true, the forwarder also receives platform change events that smplkit records about the account’s own resources (flag, configuration, and similar changes), delivered through every environment the forwarder is enabled in. Defaults to false — omit to leave platform change events unforwarded.

  • filter (Hash, nil) (defaults to: nil)

    Optional JSON Logic filter; events that don’t match are recorded as filtered_out deliveries.

  • transform (Object, nil) (defaults to: nil)

    Optional template applied to each event before delivery. Free-form by default — the audit service passes the value verbatim to the engine named by transform_type. Must be paired with a non-nil transform_type; when transform_type is TransformType::JSONATA, transform must be a String (the JSONata expression).

  • transform_type (String, nil) (defaults to: nil)

    Engine that evaluates transform —one of Audit::TransformType::VALUES. Must be paired with a non-nil transform.

Returns:

Raises:

  • (ArgumentError)

    when transform and transform_type are not both nil or both set, or when transform_type is JSONATA and transform is not a String.



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/smplkit/management/audit.rb', line 71

def new_forwarder(id, forwarder_type:, configuration:, name: nil,
                  environments: nil, description: nil,
                  forward_smplkit_events: false,
                  filter: nil, transform: nil, transform_type: nil)
  Smplkit::Audit::Forwarder.send(:validate_transform_pair!, transform, transform_type)
  Smplkit::Audit::Forwarder.new(
    self,
    id: id,
    name: name || id,
    forwarder_type: forwarder_type,
    configuration: configuration,
    environments: normalize_environments(environments),
    description: description,
    forward_smplkit_events: forward_smplkit_events,
    filter: filter,
    transform: transform,
    transform_type: transform_type
  )
end