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.



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

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.



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

def conf
  @conf
end

#default_valueObject (readonly)

Returns the value of attribute default_value.



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

def default_value
  @default_value
end

#enforce_json_200Object (readonly)

Returns the value of attribute enforce_json_200.



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

def enforce_json_200
  @enforce_json_200
end

#http_methodObject (readonly)

Returns the value of attribute http_method.



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

def http_method
  @http_method
end

#last_resultObject (readonly)

Returns the value of attribute last_result.



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

def last_result
  @last_result
end

#pathObject (readonly)

Returns the value of attribute path.



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

def path
  @path
end

#query_paramsObject (readonly)

Returns the value of attribute query_params.



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

def query_params
  @query_params
end

#queueObject (readonly)

Returns the value of attribute queue.



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

def queue
  @queue
end

#start_timeObject (readonly)

Returns the value of attribute start_time.



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

def start_time
  @start_time
end

#statsObject (readonly)

Returns the value of attribute stats.



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

def stats
  @stats
end

Instance Method Details

#_enable_network_debugObject



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

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



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

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

#on_response(&block) ⇒ Object



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

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

#ready?Boolean

Returns:

  • (Boolean)


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

def ready?
  @ready
end

#terminateObject



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

def terminate
  @stopping = true
end