Class: Consul::Async::VaultConfiguration

Inherits:
Object
  • Object
show all
Defined in:
lib/consul/async/vault_endpoint.rb

Overview

Configuration for Vault Endpoints

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(base_url: 'http://localhost:8200', debug: { network: false }, token: nil, token_renew: true, retry_duration: 10, min_duration: 0.1, lease_duration_factor: 0.5, max_retry_duration: 600, paths: {}, max_consecutive_errors_on_endpoint: 10, fail_fast_errors: false, tls_cert_chain: nil, tls_private_key: nil, tls_verify_peer: true) ⇒ VaultConfiguration

Returns a new instance of VaultConfiguration.



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/consul/async/vault_endpoint.rb', line 16

def initialize(base_url: 'http://localhost:8200',
               debug: { network: false },
               token: nil,
               token_renew: true,
               retry_duration: 10,
               min_duration: 0.1,
               lease_duration_factor: 0.5,
               max_retry_duration: 600,
               paths: {},
               max_consecutive_errors_on_endpoint: 10,
               fail_fast_errors: false,
               tls_cert_chain: nil,
               tls_private_key: nil,
               tls_verify_peer: true)
  @base_url = base_url
  @token_renew = token_renew
  @debug = debug
  @retry_duration = retry_duration
  @min_duration = min_duration
  @max_retry_duration = max_retry_duration
  @lease_duration_factor = lease_duration_factor
  @paths = paths
  @token = token
  @max_consecutive_errors_on_endpoint = max_consecutive_errors_on_endpoint
  @fail_fast_errors = fail_fast_errors
  @tls_cert_chain = tls_cert_chain
  @tls_private_key = tls_private_key
  @tls_verify_peer = tls_verify_peer
end

Instance Attribute Details

#base_urlObject (readonly)

Returns the value of attribute base_url.



12
13
14
# File 'lib/consul/async/vault_endpoint.rb', line 12

def base_url
  @base_url
end

#debugObject (readonly)

Returns the value of attribute debug.



12
13
14
# File 'lib/consul/async/vault_endpoint.rb', line 12

def debug
  @debug
end

#fail_fast_errorsObject (readonly)

Returns the value of attribute fail_fast_errors.



12
13
14
# File 'lib/consul/async/vault_endpoint.rb', line 12

def fail_fast_errors
  @fail_fast_errors
end

#lease_duration_factorObject (readonly)

Returns the value of attribute lease_duration_factor.



12
13
14
# File 'lib/consul/async/vault_endpoint.rb', line 12

def lease_duration_factor
  @lease_duration_factor
end

#max_consecutive_errors_on_endpointObject (readonly)

Returns the value of attribute max_consecutive_errors_on_endpoint.



12
13
14
# File 'lib/consul/async/vault_endpoint.rb', line 12

def max_consecutive_errors_on_endpoint
  @max_consecutive_errors_on_endpoint
end

#max_retry_durationObject (readonly)

Returns the value of attribute max_retry_duration.



12
13
14
# File 'lib/consul/async/vault_endpoint.rb', line 12

def max_retry_duration
  @max_retry_duration
end

#min_durationObject (readonly)

Returns the value of attribute min_duration.



12
13
14
# File 'lib/consul/async/vault_endpoint.rb', line 12

def min_duration
  @min_duration
end

#retry_durationObject (readonly)

Returns the value of attribute retry_duration.



12
13
14
# File 'lib/consul/async/vault_endpoint.rb', line 12

def retry_duration
  @retry_duration
end

#retry_on_non_diffObject (readonly)

Returns the value of attribute retry_on_non_diff.



12
13
14
# File 'lib/consul/async/vault_endpoint.rb', line 12

def retry_on_non_diff
  @retry_on_non_diff
end

#tls_cert_chainObject (readonly)

Returns the value of attribute tls_cert_chain.



12
13
14
# File 'lib/consul/async/vault_endpoint.rb', line 12

def tls_cert_chain
  @tls_cert_chain
end

#tls_private_keyObject (readonly)

Returns the value of attribute tls_private_key.



12
13
14
# File 'lib/consul/async/vault_endpoint.rb', line 12

def tls_private_key
  @tls_private_key
end

#tls_verify_peerObject (readonly)

Returns the value of attribute tls_verify_peer.



12
13
14
# File 'lib/consul/async/vault_endpoint.rb', line 12

def tls_verify_peer
  @tls_verify_peer
end

#tokenObject (readonly)

Returns the value of attribute token.



12
13
14
# File 'lib/consul/async/vault_endpoint.rb', line 12

def token
  @token
end

#token_renewObject (readonly)

Returns the value of attribute token_renew.



12
13
14
# File 'lib/consul/async/vault_endpoint.rb', line 12

def token_renew
  @token_renew
end

#wait_durationObject (readonly)

Returns the value of attribute wait_duration.



12
13
14
# File 'lib/consul/async/vault_endpoint.rb', line 12

def wait_duration
  @wait_duration
end

Instance Method Details

#ch(path, symbol) ⇒ Object



46
47
48
49
50
51
52
53
54
# File 'lib/consul/async/vault_endpoint.rb', line 46

def ch(path, symbol)
  sub = @paths[path.to_sym]
  if sub && sub[symbol]
    ::Consul::Async::Debug.puts_info "Overriding #{symbol}:=#{sub[symbol]} for #{path}"
    sub[symbol]
  else
    method(symbol).call
  end
end

#create(path, agent: nil) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/consul/async/vault_endpoint.rb', line 56

def create(path, agent: nil)
  return self unless @paths[path.to_sym]

  base_url = ch(path, :base_url)
  if agent
    agent = "http://#{agent}" unless agent.start_with? 'http', 'https'
    base_url = agent
  end
  VaultConfiguration.new(base_url: base_url,
                         debug: ch(path, :debug),
                         token: ch(path, :token),
                         retry_duration: ch(path, :retry_duration),
                         min_duration: ch(path, :min_duration),
                         max_retry_duration: ch(path, :max_retry_duration),
                         lease_duration_factor: ch(path, :lease_duration_factor),
                         paths: @paths,
                         max_consecutive_errors_on_endpoint: @max_consecutive_errors_on_endpoint,
                         fail_fast_errors: @fail_fast_errors)
end