Class: ConfigKit::Client
- Inherits:
-
Object
show all
- Defined in:
- lib/config_kit/client.rb
Defined Under Namespace
Classes: ConfigKitCreateError, ConfigKitReadError, ConfigKitTxnError, ConfigKitUpdateError, ConsulConnection
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(url, acl_token) ⇒ Client
Returns a new instance of Client.
114
115
116
117
118
|
# 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
|
Instance Attribute Details
#acl_token ⇒ Object
Returns the value of attribute acl_token.
9
10
11
|
# File 'lib/config_kit/client.rb', line 9
def acl_token
@acl_token
end
|
#opts ⇒ Object
Returns the value of attribute opts.
9
10
11
|
# File 'lib/config_kit/client.rb', line 9
def opts
@opts
end
|
#url ⇒ Object
Returns the value of attribute url.
9
10
11
|
# File 'lib/config_kit/client.rb', line 9
def url
@url
end
|
Instance Method Details
#atom_update(key, value) ⇒ Object
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
|
# 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
sleep(0.5)
retry
end
end
end
|
#create(key, value) ⇒ Object
120
121
122
123
124
|
# 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) ⇒ Object
179
180
181
|
# File 'lib/config_kit/client.rb', line 179
def create_txn(data)
@connection.create_txn(data)
end
|
#delete(key) ⇒ Object
174
175
176
177
|
# File 'lib/config_kit/client.rb', line 174
def delete(key)
response = @connection.delete(url, recurse: true)
response
end
|
#delete_txn(data) ⇒ Object
191
192
193
|
# File 'lib/config_kit/client.rb', line 191
def delete_txn(data)
@connection.delete_txn(data)
end
|
#init_txn ⇒ Object
195
196
197
|
# File 'lib/config_kit/client.rb', line 195
def init_txn
@connection.init_txn
end
|
199
200
201
|
# File 'lib/config_kit/client.rb', line 199
def perform_txn
@connection.perform_txn
end
|
#read(key, convert_to_hash = true, recurse = true) ⇒ Object
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
|
# 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) ⇒ Object
183
184
185
|
# File 'lib/config_kit/client.rb', line 183
def read_txn(data)
@connection.read_txn(data)
end
|
#update(key, value) ⇒ Object
126
127
128
129
|
# 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) ⇒ Object
187
188
189
|
# File 'lib/config_kit/client.rb', line 187
def update_txn(data)
@connection.update_txn(data)
end
|