Class: Ridley::Client
- Inherits:
-
Object
show all
- Extended by:
- Forwardable
- Includes:
- Celluloid, Logging
- Defined in:
- lib/ridley/client.rb
Defined Under Namespace
Classes: ConnectionSupervisor, ResourcesSupervisor
Constant Summary
collapse
- REQUIRED_OPTIONS =
[
:server_url,
:client_name,
:client_key
].freeze
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Logging
logger, #logger, set_logger
Constructor Details
#initialize(options = {}) ⇒ Client
Returns a new instance of Client.
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
|
# File 'lib/ridley/client.rb', line 120
def initialize(options = {})
@options = options.reverse_merge(
pool_size: 4
).deep_symbolize_keys
self.class.validate_options(@options)
@chef_version = @options[:chef_version]
@validator_client = @options[:validator_client]
if @options[:validator_path]
@validator_path = File.expand_path(@options[:validator_path])
end
@options[:encrypted_data_bag_secret] ||= begin
if @options[:encrypted_data_bag_secret_path]
@encrypted_data_bag_secret_path = File.expand_path(@options[:encrypted_data_bag_secret_path])
end
encrypted_data_bag_secret
end
unless verify_client_key(@options[:client_key])
@options[:client_key] = @options[:client_key].call if @options[:client_key].kind_of? Proc
@options[:client_key] = File.expand_path(@options[:client_key])
raise Errors::ClientKeyFileNotFoundOrInvalid, "client key is invalid or not found at: '#{@options[:client_key]}'" unless File.exist?(@options[:client_key]) && verify_client_key(::IO.read(@options[:client_key]))
end
@connection_registry = Celluloid::Registry.new
@resources_registry = Celluloid::Registry.new
@connection_supervisor = ConnectionSupervisor.new(@connection_registry, @options)
@resources_supervisor = ResourcesSupervisor.new(@resources_registry, @connection_registry, @options)
end
|
Instance Attribute Details
#chef_version ⇒ Object
Returns the value of attribute chef_version.
92
93
94
|
# File 'lib/ridley/client.rb', line 92
def chef_version
@chef_version
end
|
#encrypted_data_bag_secret_path ⇒ Object
Returns the value of attribute encrypted_data_bag_secret_path.
91
92
93
|
# File 'lib/ridley/client.rb', line 91
def encrypted_data_bag_secret_path
@encrypted_data_bag_secret_path
end
|
#options ⇒ Object
Returns the value of attribute options.
87
88
89
|
# File 'lib/ridley/client.rb', line 87
def options
@options
end
|
#validator_client ⇒ Object
Returns the value of attribute validator_client.
89
90
91
|
# File 'lib/ridley/client.rb', line 89
def validator_client
@validator_client
end
|
#validator_path ⇒ Object
Returns the value of attribute validator_path.
90
91
92
|
# File 'lib/ridley/client.rb', line 90
def validator_path
@validator_path
end
|
Class Method Details
.open(options = {}, &block) ⇒ Object
36
37
38
39
40
41
|
# File 'lib/ridley/client.rb', line 36
def open(options = {}, &block)
client = new(options)
yield client
ensure
client.terminate if client && client.alive?
end
|
.validate_options(options) ⇒ Boolean
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
# File 'lib/ridley/client.rb', line 46
def validate_options(options)
missing = (REQUIRED_OPTIONS - options.keys)
if missing.any?
missing.collect! { |opt| "'#{opt}'" }
raise ArgumentError, "Missing required option(s): #{missing.join(', ')}"
end
missing_values = options.slice(*REQUIRED_OPTIONS).select { |key, value| !value.present? }
if missing_values.any?
values = missing_values.keys.collect { |opt| "'#{opt}'" }
raise ArgumentError, "Missing value for required option(s): '#{values.join(', ')}'"
end
end
|
Instance Method Details
154
155
156
|
# File 'lib/ridley/client.rb', line 154
def client
@resources_registry[:client_resource]
end
|
159
160
161
|
# File 'lib/ridley/client.rb', line 159
def cookbook
@resources_registry[:cookbook_resource]
end
|
164
165
166
|
# File 'lib/ridley/client.rb', line 164
def data_bag
@resources_registry[:data_bag_resource]
end
|
#encrypted_data_bag_secret ⇒ String?
The encrypted data bag secret for this connection.
262
263
264
265
266
267
268
|
# File 'lib/ridley/client.rb', line 262
def encrypted_data_bag_secret
return nil if encrypted_data_bag_secret_path.nil?
::IO.read(encrypted_data_bag_secret_path).chomp
rescue Errno::ENOENT => e
raise Errors::EncryptedDataBagSecretNotFound, "Encrypted data bag secret provided but not found at '#{encrypted_data_bag_secret_path}'"
end
|
169
170
171
|
# File 'lib/ridley/client.rb', line 169
def environment
@resources_registry[:environment_resource]
end
|
174
175
176
|
# File 'lib/ridley/client.rb', line 174
def node
@resources_registry[:node_resource]
end
|
#partial_search(index, query = nil, attributes = [], options = {}) ⇒ Array<ChefObject>, Hash
Perform a partial search on the Chef Server. Partial objects or a smaller hash will be returned resulting in a faster response for larger response sets. Specify the attributes you want returned with the attributes parameter.
247
248
249
|
# File 'lib/ridley/client.rb', line 247
def partial_search(index, query = nil, attributes = [], options = {})
@resources_registry[:search_resource].partial(index, query, Array(attributes), @resources_registry, options)
end
|
179
180
181
|
# File 'lib/ridley/client.rb', line 179
def role
@resources_registry[:role_resource]
end
|
184
185
186
|
# File 'lib/ridley/client.rb', line 184
def sandbox
@resources_registry[:sandbox_resource]
end
|
#search(index, query = nil, options = {}) ⇒ Array<ChefObject>, Hash
Perform a search the Chef Server
206
207
208
|
# File 'lib/ridley/client.rb', line 206
def search(index, query = nil, options = {})
@resources_registry[:search_resource].run(index, query, @resources_registry, options)
end
|
#search_indexes ⇒ Array<Symbol, String>
Return an array of all possible search indexes for the including connection
218
219
220
|
# File 'lib/ridley/client.rb', line 218
def search_indexes
@resources_registry[:search_resource].indexes
end
|
#server_url ⇒ Object
270
271
272
|
# File 'lib/ridley/client.rb', line 270
def server_url
self.url_prefix.to_s
end
|
#universe ⇒ Object
251
252
253
254
255
|
# File 'lib/ridley/client.rb', line 251
def universe
connection.send(:get, "universe").body
rescue Errors::HTTPError, Errors::ClientError => ex
abort(ex)
end
|
189
190
191
|
# File 'lib/ridley/client.rb', line 189
def user
@resources_registry[:user_resource]
end
|