Class: Smplkit::Audit::ForwardersClient

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

Overview

Surface for client.audit.forwarders.* — manage the customer’s configured SIEM forwarders.

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

Instance Method Summary collapse

Constructor Details

#initialize(api) ⇒ ForwardersClient

Returns a new instance of ForwardersClient.



24
25
26
# File 'lib/smplkit/audit/forwarders.rb', line 24

def initialize(api)
  @api = api
end

Instance Method Details

#_create_forwarder(forwarder) ⇒ Object



127
128
129
130
131
132
133
134
# File 'lib/smplkit/audit/forwarders.rb', line 127

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

  resp = Audit.call_api { @api.create_forwarder(build_create_body(forwarder)) }
  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)


142
143
144
145
146
147
# File 'lib/smplkit/audit/forwarders.rb', line 142

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

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

#delete(forwarder_id) ⇒ nil

Soft-delete a forwarder.

Parameters:

  • forwarder_id (String)

Returns:

  • (nil)


120
121
122
123
# File 'lib/smplkit/audit/forwarders.rb', line 120

def delete(forwarder_id)
  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 client, so forwarder.save and forwarder.delete work.

Parameters:

  • forwarder_id (String)

Returns:



111
112
113
114
# File 'lib/smplkit/audit/forwarders.rb', line 111

def get(forwarder_id)
  resp = Audit.call_api { @api.get_forwarder(forwarder_id) }
  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:



94
95
96
97
98
99
100
101
102
103
104
# File 'lib/smplkit/audit/forwarders.rb', line 94

def list(forwarder_type: nil, page_number: nil, page_size: nil, meta_total: nil)
  opts = {}
  opts[:filter_forwarder_type] = 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 = Audit.call_api { @api.list_forwarders(opts) }
  forwarders = (resp.data || []).map { |r| Forwarder.from_resource(r, client: self) }
  ForwarderListPage.new(forwarders, Audit.extract_pagination(resp.meta))
end

#new(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 Smplkit::Audit::Forwarder bound to this client. Call #save on the returned instance to persist.

Parameters:

  • id (String)

    Caller-supplied unique identifier (the forwarder’s key). Unique within the account; immutable. The audit service returns 409 if another live forwarder already uses this id.

  • name (String) (defaults to: nil)

    Display name. Defaults to id when not supplied.

  • 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 Smplkit::Audit::ForwarderEnvironment instances or plain hashes (+{ enabled: true }+, optionally with a :configuration 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. 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 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.



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/smplkit/audit/forwarders.rb', line 66

def new(id, forwarder_type:, configuration:, name: nil,
        environments: nil, description: nil,
        forward_smplkit_events: false,
        filter: nil, transform: nil, transform_type: nil)
  Forwarder.send(:validate_transform_pair!, transform, transform_type)
  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