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.



41
42
43
44
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
# File 'lib/smplkit/audit/client.rb', line 41

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: record / list / get /
  # discovery all resolve their environment from the
  # +X-Smplkit-Environment+ request header (ADR-055). We stamp it once
  # at the client level from the SDK's configured runtime environment so
  # every generated call carries it. It is stamped before +extra_headers+
  # is applied so a caller-supplied entry of the same name wins (explicit
  # override).
  api_client.default_headers["X-Smplkit-Environment"] = environment unless environment.nil?
  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))
  @resource_types = ResourceTypes.new(SmplkitGeneratedClient::Audit::ResourceTypesApi.new(api_client))
  @event_types = EventTypes.new(SmplkitGeneratedClient::Audit::EventTypesApi.new(api_client))
  @categories = Categories.new(SmplkitGeneratedClient::Audit::CategoriesApi.new(api_client))
  @forwarders = ForwardersClient.new(SmplkitGeneratedClient::Audit::ForwardersApi.new(api_client))
end

Instance Attribute Details

#categoriesObject (readonly)

Returns the value of attribute categories.



37
38
39
# File 'lib/smplkit/audit/client.rb', line 37

def categories
  @categories
end

#event_typesObject (readonly)

Returns the value of attribute event_types.



37
38
39
# File 'lib/smplkit/audit/client.rb', line 37

def event_types
  @event_types
end

#eventsObject (readonly)

Returns the value of attribute events.



37
38
39
# File 'lib/smplkit/audit/client.rb', line 37

def events
  @events
end

#forwardersObject (readonly)

Returns the value of attribute forwarders.



37
38
39
# File 'lib/smplkit/audit/client.rb', line 37

def forwarders
  @forwarders
end

#resource_typesObject (readonly)

Returns the value of attribute resource_types.



37
38
39
# File 'lib/smplkit/audit/client.rb', line 37

def resource_types
  @resource_types
end

Instance Method Details

#_closeObject



85
86
87
# File 'lib/smplkit/audit/client.rb', line 85

def _close
  @events._close
end