Class: Smplkit::Audit::AuditClient

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

Overview

The Smpl Audit client — accessed via client.audit.

One client exposes the full surface — event recording and reads, distinct-value discovery, and SIEM forwarder CRUD. Owns fire-and-forget #events.record, plus the audit-log list / get and the distinct-value listings (+resource_types+, event_types, categories), plus SIEM forwarder CRUD on #forwarders.

Reachable as client.audit (+Smplkit::Client+) or constructed directly — AuditClient.new resolves credentials from ~/.smplkit / env vars and derives the audit base URL from +base_domain+/+scheme+ when base_url is omitted.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_key: nil, base_url: nil, environment: nil, profile: nil, base_domain: nil, scheme: nil, debug: nil, timeout: 10.0, extra_headers: nil, buffered: true) ⇒ AuditClient

Returns a new instance of AuditClient.



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/smplkit/audit/client.rb', line 52

def initialize(api_key: nil, base_url: nil, environment: nil, profile: nil,
               base_domain: nil, scheme: nil, debug: nil, timeout: 10.0,
               extra_headers: nil, buffered: true)
  # +api_key+/+base_url+/+environment+ are used directly when all three
  # are supplied (the path the top-level client takes after it has
  # already resolved them); otherwise the config resolver fills in
  # whatever is missing (+~/.smplkit+ / env vars / defaults) and the
  # audit base URL is derived from +base_domain+/+scheme+ via
  # +service_url+.
  if api_key.nil? || base_url.nil? || environment.nil?
    resolved = ConfigResolution.resolve_client_config(
      profile: profile, api_key: api_key, base_domain: base_domain,
      scheme: scheme, environment: environment, debug: debug
    )
    api_key = resolved.api_key if api_key.nil?
    base_url = ConfigResolution.service_url(resolved.scheme, "audit", resolved.base_domain) if base_url.nil?
    environment = resolved.environment if environment.nil?
    debug = resolved.debug if debug.nil?
  end
  cfg = SmplkitGeneratedClient::Audit::Configuration.new
  cfg.host = URI.parse(base_url).host
  cfg.scheme = URI.parse(base_url).scheme
  cfg.access_token = api_key
  cfg.timeout = timeout
  cfg.debugging = debug unless debug.nil?
  HttpPool.configure(cfg)
  api_client = SmplkitGeneratedClient::Audit::ApiClient.new(cfg)
  # Runtime audit ops are environment-scoped, but the scoping is
  # body-driven (ADR-055): +events.record+ stamps the configured
  # environment onto the event request body, and the read surfaces
  # (events list plus the resource_type / event_type / category discovery
  # lists) default +filter[environment]+ to it. The transport therefore
  # carries only auth, the default User-Agent, and any caller-supplied
  # +extra_headers+ — no environment header. Forwarder CRUD is
  # environment-agnostic.
  Transport.apply_headers(api_client, extra_headers)
  @events = Events.new(
    SmplkitGeneratedClient::Audit::EventsApi.new(api_client),
    environment: environment, buffered: buffered
  )
  @resource_types = ResourceTypes.new(
    SmplkitGeneratedClient::Audit::ResourceTypesApi.new(api_client), environment: environment
  )
  @event_types = EventTypes.new(
    SmplkitGeneratedClient::Audit::EventTypesApi.new(api_client), environment: environment
  )
  @categories = Categories.new(
    SmplkitGeneratedClient::Audit::CategoriesApi.new(api_client), environment: environment
  )
  @forwarders = ForwardersClient.new(SmplkitGeneratedClient::Audit::ForwardersApi.new(api_client))
end

Instance Attribute Details

#categoriesObject (readonly)

Returns the value of attribute categories.



50
51
52
# File 'lib/smplkit/audit/client.rb', line 50

def categories
  @categories
end

#event_typesObject (readonly)

Returns the value of attribute event_types.



50
51
52
# File 'lib/smplkit/audit/client.rb', line 50

def event_types
  @event_types
end

#eventsObject (readonly)

Returns the value of attribute events.



50
51
52
# File 'lib/smplkit/audit/client.rb', line 50

def events
  @events
end

#forwardersObject (readonly)

Returns the value of attribute forwarders.



50
51
52
# File 'lib/smplkit/audit/client.rb', line 50

def forwarders
  @forwarders
end

#resource_typesObject (readonly)

Returns the value of attribute resource_types.



50
51
52
# File 'lib/smplkit/audit/client.rb', line 50

def resource_types
  @resource_types
end

Instance Method Details

#_closeObject



104
105
106
# File 'lib/smplkit/audit/client.rb', line 104

def _close
  @events._close
end