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/forwarders.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, ForwarderListPage, ForwardersClient, HttpConfiguration, HttpHeader, ListEventsPage, ResourceType, ResourceTypeListPage, ResourceTypes

Class Method Summary collapse

Class Method Details

.call_apiObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

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.



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

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

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

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.



48
49
50
51
52
53
54
55
56
# File 'lib/smplkit/audit/models.rb', line 48

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

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

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



75
76
77
78
79
80
# File 'lib/smplkit/audit/models.rb', line 75

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

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

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.



31
32
33
34
35
36
37
38
39
40
# File 'lib/smplkit/audit/models.rb', line 31

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

.resolve_environment_filter(environments, default) ⇒ String?

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Resolve the filter[environment] value for a read surface.

An explicit, non-empty environments list always wins and is comma-joined via join_environments. Otherwise the client’s configured default environment scopes the read — the body-driven replacement for the old per-request X-Smplkit-Environment header (ADR-055), which previously scoped every read to the client’s environment. A client with no configured environment and no explicit list returns nil so the caller omits the query param and the credential’s own scoping applies server-side.

Parameters:

  • environments (Array<String>, String, nil)

    Explicit per-call environment filter; an empty/blank value falls through to default.

  • default (String, nil)

    The client’s configured environment.

Returns:

  • (String, nil)

    The filter[environment] value, or nil to omit it.



97
98
99
100
101
102
# File 'lib/smplkit/audit/models.rb', line 97

def self.resolve_environment_filter(environments, default)
  joined = join_environments(environments)
  return joined unless joined.nil?

  default
end