Class: Consul::Async::ConsulConfiguration

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

Overview

The class configuring Consul endpoints It allows to translate configuration options per specific endpoint/path

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(base_url: 'http://localhost:8500', debug: { network: false }, token: nil, retry_duration: 10, min_duration: 0.1, retry_on_non_diff: 5, wait_duration: 600, max_retry_duration: 600, missing_index_retry_time_on_diff: 15, missing_index_retry_time_on_unchanged: 60, enable_gzip_compression: true, paths: {}, max_consecutive_errors_on_endpoint: 10, fail_fast_errors: 1, tls_cert_chain: nil, tls_private_key: nil, tls_verify_peer: true) ⇒ ConsulConfiguration

Returns a new instance of ConsulConfiguration.



13
14
15
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
45
46
47
# File 'lib/consul/async/consul_endpoint.rb', line 13

def initialize(base_url: 'http://localhost:8500',
               debug: { network: false },
               token: nil,
               retry_duration: 10,
               min_duration: 0.1,
               retry_on_non_diff: 5,
               wait_duration: 600,
               max_retry_duration: 600,
               missing_index_retry_time_on_diff: 15,
               missing_index_retry_time_on_unchanged: 60,
               enable_gzip_compression: true,
               paths: {},
               max_consecutive_errors_on_endpoint: 10,
               fail_fast_errors: 1,
               tls_cert_chain: nil,
               tls_private_key: nil,
               tls_verify_peer: true)
  @base_url = base_url
  @token = token
  @debug = debug
  @enable_gzip_compression = enable_gzip_compression
  @retry_duration = retry_duration
  @min_duration = min_duration
  @wait_duration = wait_duration
  @max_retry_duration = max_retry_duration
  @retry_on_non_diff = retry_on_non_diff
  @missing_index_retry_time_on_diff = missing_index_retry_time_on_diff
  @missing_index_retry_time_on_unchanged = missing_index_retry_time_on_unchanged
  @paths = paths
  @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.



10
11
12
# File 'lib/consul/async/consul_endpoint.rb', line 10

def base_url
  @base_url
end

#debugObject (readonly)

Returns the value of attribute debug.



10
11
12
# File 'lib/consul/async/consul_endpoint.rb', line 10

def debug
  @debug
end

#enable_gzip_compressionObject (readonly)

Returns the value of attribute enable_gzip_compression.



10
11
12
# File 'lib/consul/async/consul_endpoint.rb', line 10

def enable_gzip_compression
  @enable_gzip_compression
end

#fail_fast_errorsObject (readonly)

Returns the value of attribute fail_fast_errors.



10
11
12
# File 'lib/consul/async/consul_endpoint.rb', line 10

def fail_fast_errors
  @fail_fast_errors
end

#max_consecutive_errors_on_endpointObject (readonly)

Returns the value of attribute max_consecutive_errors_on_endpoint.



10
11
12
# File 'lib/consul/async/consul_endpoint.rb', line 10

def max_consecutive_errors_on_endpoint
  @max_consecutive_errors_on_endpoint
end

#max_retry_durationObject (readonly)

Returns the value of attribute max_retry_duration.



10
11
12
# File 'lib/consul/async/consul_endpoint.rb', line 10

def max_retry_duration
  @max_retry_duration
end

#min_durationObject (readonly)

Returns the value of attribute min_duration.



10
11
12
# File 'lib/consul/async/consul_endpoint.rb', line 10

def min_duration
  @min_duration
end

#missing_index_retry_time_on_diffObject (readonly)

Returns the value of attribute missing_index_retry_time_on_diff.



10
11
12
# File 'lib/consul/async/consul_endpoint.rb', line 10

def missing_index_retry_time_on_diff
  @missing_index_retry_time_on_diff
end

#missing_index_retry_time_on_unchangedObject (readonly)

Returns the value of attribute missing_index_retry_time_on_unchanged.



10
11
12
# File 'lib/consul/async/consul_endpoint.rb', line 10

def missing_index_retry_time_on_unchanged
  @missing_index_retry_time_on_unchanged
end

#retry_durationObject (readonly)

Returns the value of attribute retry_duration.



10
11
12
# File 'lib/consul/async/consul_endpoint.rb', line 10

def retry_duration
  @retry_duration
end

#retry_on_non_diffObject (readonly)

Returns the value of attribute retry_on_non_diff.



10
11
12
# File 'lib/consul/async/consul_endpoint.rb', line 10

def retry_on_non_diff
  @retry_on_non_diff
end

#tls_cert_chainObject (readonly)

Returns the value of attribute tls_cert_chain.



10
11
12
# File 'lib/consul/async/consul_endpoint.rb', line 10

def tls_cert_chain
  @tls_cert_chain
end

#tls_private_keyObject (readonly)

Returns the value of attribute tls_private_key.



10
11
12
# File 'lib/consul/async/consul_endpoint.rb', line 10

def tls_private_key
  @tls_private_key
end

#tls_verify_peerObject (readonly)

Returns the value of attribute tls_verify_peer.



10
11
12
# File 'lib/consul/async/consul_endpoint.rb', line 10

def tls_verify_peer
  @tls_verify_peer
end

#tokenObject (readonly)

Returns the value of attribute token.



10
11
12
# File 'lib/consul/async/consul_endpoint.rb', line 10

def token
  @token
end

#wait_durationObject (readonly)

Returns the value of attribute wait_duration.



10
11
12
# File 'lib/consul/async/consul_endpoint.rb', line 10

def wait_duration
  @wait_duration
end

Instance Method Details

#ch(path, symbol) ⇒ Object



49
50
51
52
53
54
55
56
57
# File 'lib/consul/async/consul_endpoint.rb', line 49

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

#create(path, agent: nil) ⇒ Object



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
# File 'lib/consul/async/consul_endpoint.rb', line 59

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
  ConsulConfiguration.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),
                          retry_on_non_diff: ch(path, :retry_on_non_diff),
                          wait_duration: ch(path, :wait_duration),
                          max_retry_duration: ch(path, :max_retry_duration),
                          missing_index_retry_time_on_diff: ch(path, :missing_index_retry_time_on_diff),
                          missing_index_retry_time_on_unchanged: ch(path, :missing_index_retry_time_on_unchanged),
                          enable_gzip_compression: enable_gzip_compression,
                          paths: @paths,
                          max_consecutive_errors_on_endpoint: @max_consecutive_errors_on_endpoint,
                          fail_fast_errors: @fail_fast_errors,
                          tls_cert_chain: ch(path, :tls_cert_chain),
                          tls_private_key: ch(path, :tls_private_key),
                          tls_verify_peer: ch(path, :tls_verify_peer))
end