class ConfigKit::Client
Attributes
acl_token[R]
opts[R]
url[R]
Public Class Methods
new(url, acl_token)
click to toggle source
# File lib/config_kit/client.rb, line 114 def initialize(url, acl_token) @url = url @acl_token = acl_token @connection = ConsulConnection.new(@url, @acl_token) end
Public Instance Methods
atom_update(key,value)
click to toggle source
# File lib/config_kit/client.rb, line 131 def atom_update(key,value) begin retries ||= 0 modify_idx = @connection.get(key, modify_index: true) response = @connection.put!(key, value, cas: modify_idx) rescue ConfigKitUpdateError => e if (retries += 1) < 3 # # TODO: # 1. Need to log # 2. Need to delay and retry refactor # sleep(0.5) retry end end end
create(key,value)
click to toggle source
# File lib/config_kit/client.rb, line 120 def create(key,value) response = @connection.put(key, value, cas: 0) raise ConfigKitCreateError, "Config Kit create #{key} error" unless response response end
create_txn(data)
click to toggle source
# File lib/config_kit/client.rb, line 179 def create_txn(data) @connection.create_txn(data) end
delete(key)
click to toggle source
TODO: enhancement
# File lib/config_kit/client.rb, line 174 def delete(key) response = @connection.delete(url, recurse: true) response end
delete_txn(data)
click to toggle source
# File lib/config_kit/client.rb, line 191 def delete_txn(data) @connection.delete_txn(data) end
init_txn()
click to toggle source
# File lib/config_kit/client.rb, line 195 def init_txn @connection.init_txn end
perform_txn()
click to toggle source
# File lib/config_kit/client.rb, line 199 def perform_txn @connection.perform_txn end
read(key, convert_to_hash=true, recurse=true)
click to toggle source
TODO: enhancement
# File lib/config_kit/client.rb, line 152 def read(key, convert_to_hash=true, recurse=true) begin ConfigKit.logger.debug "getting key: #{key}" response = @connection.get(key, convert_to_hash: convert_to_hash, recurse: recurse) response rescue Diplomat::KeyNotFound => e return nil rescue Faraday::ConnectionFailed => e raise ConfigKitReadError, "config server #{@url} is not avaliable. #{e.message}" rescue Diplomat::UnknownStatus => e raise ConfigKitReadError, "Unknown error #{e.message}." rescue Exception => e ConfigKit.logger.debug e.backtrace.join("\n ") return nil end end
read_txn(data)
click to toggle source
# File lib/config_kit/client.rb, line 183 def read_txn(data) @connection.read_txn(data) end
update(key, value)
click to toggle source
# File lib/config_kit/client.rb, line 126 def update(key, value) response = @connection.put(key, value) raise ConfigKitUpdateError, "Config Kit update #{key} error" unless response end
update_txn(data)
click to toggle source
# File lib/config_kit/client.rb, line 187 def update_txn(data) @connection.update_txn(data) end