Class: HermesAgent::Client::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/hermes_agent/client/configuration.rb

Overview

Connection settings for a HermesAgent::Client.

Holds the server location and credentials shared by all requests. An instance is created when a client is constructed and may be customized either via keyword arguments or by yielding the configuration to a block.

Constant Summary collapse

DEFAULT_BASE_URL =

The default server root URL.

Returns:

  • (String)
"http://127.0.0.1:8642"
DEFAULT_KEEP_ALIVE_TIMEOUT =

The default keep-alive timeout, in seconds.

Returns:

  • (Numeric)
5

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(base_url: DEFAULT_BASE_URL, api_key: ::ENV.fetch("HERMES_API_KEY", nil), read_timeout: nil, open_timeout: nil, write_timeout: nil, keep_alive_timeout: DEFAULT_KEEP_ALIVE_TIMEOUT) ⇒ Configuration

Create a configuration.

Parameters:

  • base_url (String) (defaults to: DEFAULT_BASE_URL)

    The server root URL, without a path prefix such as /v1. Defaults to DEFAULT_BASE_URL.

  • api_key (String, nil) (defaults to: ::ENV.fetch("HERMES_API_KEY", nil))

    The bearer token sent on every request, or nil to send no Authorization header. Defaults to the HERMES_API_KEY environment variable.

  • read_timeout (Numeric, nil) (defaults to: nil)

    The read timeout in seconds, or nil for no client-side limit.

  • open_timeout (Numeric, nil) (defaults to: nil)

    The connection-open timeout in seconds, or nil for no client-side limit.

  • write_timeout (Numeric, nil) (defaults to: nil)

    The timeout in seconds for writing a request, or nil for no client-side limit.

  • keep_alive_timeout (Numeric) (defaults to: DEFAULT_KEEP_ALIVE_TIMEOUT)

    How long, in seconds, an idle persistent connection may be reused before it is considered stale and reopened on the next request. Defaults to DEFAULT_KEEP_ALIVE_TIMEOUT.



44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/hermes_agent/client/configuration.rb', line 44

def initialize(base_url: DEFAULT_BASE_URL,
               api_key: ::ENV.fetch("HERMES_API_KEY", nil),
               read_timeout: nil,
               open_timeout: nil,
               write_timeout: nil,
               keep_alive_timeout: DEFAULT_KEEP_ALIVE_TIMEOUT)
  @base_url = base_url
  @api_key = api_key
  @read_timeout = read_timeout
  @open_timeout = open_timeout
  @write_timeout = write_timeout
  @keep_alive_timeout = keep_alive_timeout
end

Instance Attribute Details

#api_keyString?

The bearer token sent on every request, or nil for none.

Returns:

  • (String, nil)


68
69
70
# File 'lib/hermes_agent/client/configuration.rb', line 68

def api_key
  @api_key
end

#base_urlString

The server root URL, without a path prefix.

Returns:

  • (String)


62
63
64
# File 'lib/hermes_agent/client/configuration.rb', line 62

def base_url
  @base_url
end

#keep_alive_timeoutNumeric

How long, in seconds, an idle persistent connection may be reused before it is considered stale and reopened on the next request.

Returns:

  • (Numeric)


95
96
97
# File 'lib/hermes_agent/client/configuration.rb', line 95

def keep_alive_timeout
  @keep_alive_timeout
end

#open_timeoutNumeric?

The connection-open timeout in seconds, or nil for no client-side limit.

Returns:

  • (Numeric, nil)


81
82
83
# File 'lib/hermes_agent/client/configuration.rb', line 81

def open_timeout
  @open_timeout
end

#read_timeoutNumeric?

The read timeout in seconds, or nil for no client-side limit.

Returns:

  • (Numeric, nil)


74
75
76
# File 'lib/hermes_agent/client/configuration.rb', line 74

def read_timeout
  @read_timeout
end

#write_timeoutNumeric?

The request-write timeout in seconds, or nil for no client-side limit.

Returns:

  • (Numeric, nil)


88
89
90
# File 'lib/hermes_agent/client/configuration.rb', line 88

def write_timeout
  @write_timeout
end