Class: Consul::Async::VaultEndpoint

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

Overview

Endpoint in vault (a path in Vault)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(conf, path, http_method = 'GET', enforce_json_200 = true, query_params = {}, default_value = '{}', post_data = {}, agent: nil) ⇒ VaultEndpoint

Returns a new instance of VaultEndpoint.



132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# File 'lib/consul/async/vault_endpoint.rb', line 132

def initialize(conf, path, http_method = 'GET', enforce_json_200 = true, query_params = {}, default_value = '{}', post_data = {}, agent: nil)
  @conf = conf.create(path, agent: agent)
  @default_value = default_value
  @path = path
  @http_method = http_method
  @queue = EM::Queue.new
  @x_consul_index = 0
  @s_callbacks = []
  @e_callbacks = []
  @enforce_json_200 = enforce_json_200
  @start_time = Time.now.utc
  @consecutive_errors = 0
  @query_params = query_params
  @post_data = post_data
  @stopping = false
  @stats = EndPointStats.new
  @last_result = VaultResult.new(VaultHttpResponse.new(nil, default_value), false, stats, 1)
  on_response { |result| @stats.on_response result }
  on_error { |http| @stats.on_error http }
  _enable_network_debug if conf.debug && conf.debug[:network]
  fetch
  queue.push 0
end

Instance Attribute Details

#confObject (readonly)

Returns the value of attribute conf.



130
131
132
# File 'lib/consul/async/vault_endpoint.rb', line 130

def conf
  @conf
end

#default_valueObject (readonly)

Returns the value of attribute default_value.



130
131
132
# File 'lib/consul/async/vault_endpoint.rb', line 130

def default_value
  @default_value
end

#enforce_json_200Object (readonly)

Returns the value of attribute enforce_json_200.



130
131
132
# File 'lib/consul/async/vault_endpoint.rb', line 130

def enforce_json_200
  @enforce_json_200
end

#http_methodObject (readonly)

Returns the value of attribute http_method.



130
131
132
# File 'lib/consul/async/vault_endpoint.rb', line 130

def http_method
  @http_method
end

#last_resultObject (readonly)

Returns the value of attribute last_result.



130
131
132
# File 'lib/consul/async/vault_endpoint.rb', line 130

def last_result
  @last_result
end

#pathObject (readonly)

Returns the value of attribute path.



130
131
132
# File 'lib/consul/async/vault_endpoint.rb', line 130

def path
  @path
end

#query_paramsObject (readonly)

Returns the value of attribute query_params.



130
131
132
# File 'lib/consul/async/vault_endpoint.rb', line 130

def query_params
  @query_params
end

#queueObject (readonly)

Returns the value of attribute queue.



130
131
132
# File 'lib/consul/async/vault_endpoint.rb', line 130

def queue
  @queue
end

#start_timeObject (readonly)

Returns the value of attribute start_time.



130
131
132
# File 'lib/consul/async/vault_endpoint.rb', line 130

def start_time
  @start_time
end

#statsObject (readonly)

Returns the value of attribute stats.



130
131
132
# File 'lib/consul/async/vault_endpoint.rb', line 130

def stats
  @stats
end

Instance Method Details

#_enable_network_debugObject



156
157
158
159
160
161
162
163
164
165
166
# File 'lib/consul/async/vault_endpoint.rb', line 156

def _enable_network_debug
  on_response do |result|
    state = result.x_consul_index.to_i < 1 ? '[WARN]' : '[ OK ]'
    stats = result.stats
    warn "[DBUG]#{state}#{result.modified? ? '[MODFIED]' : '[NO DIFF]'}" \
    "[s:#{stats.successes},err:#{stats.errors}]" \
    "[#{stats.body_bytes_human.ljust(8)}][#{stats.bytes_per_sec_human.ljust(9)}]"\
    " #{path.ljust(48)} idx:#{result.x_consul_index}, next in #{result.retry_in} s"
  end
  on_error { |http| ::Consul::Async::Debug.puts_error "#{path}: #{http.error}" }
end

#on_error(&block) ⇒ Object



172
173
174
# File 'lib/consul/async/vault_endpoint.rb', line 172

def on_error(&block)
  @e_callbacks << block
end

#on_response(&block) ⇒ Object



168
169
170
# File 'lib/consul/async/vault_endpoint.rb', line 168

def on_response(&block)
  @s_callbacks << block
end

#ready?Boolean

Returns:

  • (Boolean)


176
177
178
# File 'lib/consul/async/vault_endpoint.rb', line 176

def ready?
  @ready
end

#terminateObject



180
181
182
# File 'lib/consul/async/vault_endpoint.rb', line 180

def terminate
  @stopping = true
end