Module: Smplkit::Audit

Defined in:
lib/smplkit/audit/buffer.rb,
lib/smplkit/audit/client.rb,
lib/smplkit/audit/events.rb,
lib/smplkit/audit/models.rb,
lib/smplkit/audit/categories.rb,
lib/smplkit/audit/event_types.rb,
lib/smplkit/audit/resource_types.rb

Defined Under Namespace

Modules: ForwarderType, HttpMethod, TransformType Classes: AuditClient, AuditEvent, Categories, Category, CategoryListPage, EventBuffer, EventType, EventTypeListPage, EventTypes, Events, Forwarder, ForwarderEnvironment, HttpConfiguration, HttpHeader, ListEventsPage, ResourceType, ResourceTypeListPage, ResourceTypes

Class Method Summary collapse

Class Method Details

.call_apiObject

Wrap a generated-audit-API call and translate ApiError into the Smplkit::Error hierarchy. Connection-level failures (no response code) become ConnectionError; status-coded failures route through Errors.raise_for_status, which emits PaymentRequiredError / NotFoundError / ConflictError / ValidationError / Error depending on the JSON:API body.



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/smplkit/audit/models.rb', line 11

def self.call_api
  yield
rescue SmplkitGeneratedClient::Audit::ApiError => e
  raise Smplkit::ConnectionError, e.message.to_s if e.code.nil? || e.code.zero?

  Smplkit::Errors.raise_for_status(e.code, e.response_body.to_s)
  # raise_for_status only returns on 2xx; if we get here the
  # generated layer raised on a 2xx (shouldn't happen) — re-raise
  # the original so the caller can inspect.
  raise
end

.extract_pagination(meta) ⇒ Object

Pull the offset-pagination block out of a JSON:API meta envelope. Returns a hash with :page/:size (and :total/:total_pages when the request opted into meta=true). Always returns a hash so callers don’t have to nil-check before reading individual keys.



42
43
44
45
46
47
48
49
50
# File 'lib/smplkit/audit/models.rb', line 42

def self.extract_pagination(meta)
  pagination = meta&.pagination
  return {} if pagination.nil?

  out = { page: pagination.page, size: pagination.size }
  out[:total] = pagination.total unless pagination.total.nil?
  out[:total_pages] = pagination.total_pages unless pagination.total_pages.nil?
  out
end

.join_environments(environments) ⇒ Object

Coerce a caller-supplied environments value into the comma-separated string the audit read endpoints expect for filter[environment], or nil when no filter should be sent.

The audit read endpoints (events list, the resource_type / event_type / category discovery lists) accept an optional comma-separated filter[environment] of real environment keys and/or the reserved “smplkit” control-plane bucket (ADR-055). The wrapper takes an array of keys for an ergonomic surface and joins it here.

nil or an empty array (or one whose entries are all blank) returns nil so the caller omits the query param entirely and behaves exactly as before — existing callers are byte-for-byte unchanged on the wire. “smplkit” is passed through like any other key; it carries no special handling in the SDK.



67
68
69
70
71
72
# File 'lib/smplkit/audit/models.rb', line 67

def self.join_environments(environments)
  return nil if environments.nil?

  values = Array(environments).map { |e| e.to_s.strip }.reject(&:empty?)
  values.empty? ? nil : values.join(",")
end

.next_cursor(link) ⇒ Object

Parse the page[after] cursor out of a JSON:API links.next URL. Returns nil for non-string input or when the link carries no cursor parameter; trims trailing query params at the next ampersand so they don’t leak into the token.



27
28
29
30
31
32
33
34
35
36
# File 'lib/smplkit/audit/models.rb', line 27

def self.next_cursor(link)
  return nil unless link.is_a?(String)

  idx = link.index("page[after]=")
  return nil if idx.nil?

  token = link[(idx + "page[after]=".length)..]
  amp = token.index("&")
  amp ? token[0...amp] : token
end