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.

Constant Summary collapse

SDK_OWNED_HEADERS =
%w[authorization content-type user-agent].freeze

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) ⇒ AuditClient

Returns a new instance of AuditClient.



45
46
47
48
49
50
51
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
# File 'lib/smplkit/audit/client.rb', line 45

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)
  # +base_url+/+api_key+ are used directly when both 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?
    resolved = ConfigResolution.resolve_client_config(
      profile: profile, api_key: api_key, base_domain: base_domain,
      scheme: scheme, 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?
    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)
  api_client.default_headers["User-Agent"] = "smplkit-ruby-sdk/#{Smplkit::VERSION}"
  # 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 plus any caller-supplied +extra_headers+ — no
  # environment header. Forwarder CRUD is environment-agnostic.
  extra_headers&.each do |k, v|
    api_client.default_headers[k] = v unless SDK_OWNED_HEADERS.include?(k.downcase)
  end
  @events = Events.new(SmplkitGeneratedClient::Audit::EventsApi.new(api_client), environment: environment)
  @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.



41
42
43
# File 'lib/smplkit/audit/client.rb', line 41

def categories
  @categories
end

#event_typesObject (readonly)

Returns the value of attribute event_types.



41
42
43
# File 'lib/smplkit/audit/client.rb', line 41

def event_types
  @event_types
end

#eventsObject (readonly)

Returns the value of attribute events.



41
42
43
# File 'lib/smplkit/audit/client.rb', line 41

def events
  @events
end

#forwardersObject (readonly)

Returns the value of attribute forwarders.



41
42
43
# File 'lib/smplkit/audit/client.rb', line 41

def forwarders
  @forwarders
end

#resource_typesObject (readonly)

Returns the value of attribute resource_types.



41
42
43
# File 'lib/smplkit/audit/client.rb', line 41

def resource_types
  @resource_types
end

Instance Method Details

#_closeObject



94
95
96
# File 'lib/smplkit/audit/client.rb', line 94

def _close
  @events._close
end