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



138
139
140
141
142
143
144
145
# File 'lib/smplkit/audit/forwarders.rb', line 138

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 come back in plaintext on the GET path, so a fetched forwarder round-trips through this full-replace PUT with its header values intact — no need to re-enter secrets.

Raises:

  • (ArgumentError)


153
154
155
156
157
158
# File 'lib/smplkit/audit/forwarders.rb', line 153

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

Delete a forwarder.

Parameters:

  • forwarder_id (String)

Returns:

  • (nil)


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

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. Header values come back in plaintext, so mutating the returned forwarder and calling save preserves them without re-entering secrets.

Parameters:

  • forwarder_id (String)

    The forwarder’s id (key).

Returns:

Raises:



122
123
124
125
# File 'lib/smplkit/audit/forwarders.rb', line 122

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: pass page_number (1-based) and page_size (default 1000, max 1000).

Parameters:

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

    Restrict the listing to forwarders of this Smplkit::Audit::ForwarderType. Omit to list every type.

  • page_number (Integer, nil) (defaults to: nil)

    1-based page index. Omit for the first page.

  • page_size (Integer, nil) (defaults to: nil)

    Maximum number of forwarders to return in this page (default 1000, max 1000).

  • meta_total (Boolean, nil) (defaults to: nil)

    When true, populate total and total_pages in the returned page’s pagination block (costs an extra count server-side). Omit to skip it.

Returns:



102
103
104
105
106
107
108
109
110
111
112
# File 'lib/smplkit/audit/forwarders.rb', line 102

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. Header values often carry credentials and are returned in plaintext on reads, so a get-mutate-put round-trip preserves them without re-entering secrets.

  • 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.



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

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