Class: Ridley::Client
- Inherits:
-
Object
- Object
- Ridley::Client
- 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
-
#chef_version ⇒ Object
Returns the value of attribute chef_version.
-
#encrypted_data_bag_secret_path ⇒ Object
Returns the value of attribute encrypted_data_bag_secret_path.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#validator_client ⇒ Object
Returns the value of attribute validator_client.
-
#validator_path ⇒ Object
Returns the value of attribute validator_path.
Class Method Summary collapse
Instance Method Summary collapse
- #client ⇒ Ridley::ClientResource
- #cookbook ⇒ Ridley::CookbookResource
- #data_bag ⇒ Ridley::DataBagResource
-
#encrypted_data_bag_secret ⇒ String?
The encrypted data bag secret for this connection.
- #environment ⇒ Ridley::EnvironmentResource
-
#initialize(options = {}) ⇒ Client
constructor
A new instance of Client.
- #node ⇒ Ridley::NodeResource
-
#partial_search(index, query = nil, attributes = [], options = {}) ⇒ Array<ChefObject>, Hash
Perform a partial search on the Chef Server.
- #role ⇒ Ridley::RoleResource
- #sandbox ⇒ Ridley::SandboxResource
-
#search(index, query = nil, options = {}) ⇒ Array<ChefObject>, Hash
Perform a search the Chef Server.
-
#search_indexes ⇒ Array<Symbol, String>
Return an array of all possible search indexes for the including connection.
- #server_url ⇒ Object
- #user ⇒ Ridley::UserResource
Methods included from Logging
Constructor Details
#initialize(options = {}) ⇒ Client
Returns a new instance of Client.
118 119 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 |
# File 'lib/ridley/client.rb', line 118 def initialize( = {}) @options = .reverse_merge( pool_size: 4 ).deep_symbolize_keys self.class.(@options) @chef_version = @options[:chef_version] @validator_client = @options[:validator_client] if @options[:validator_path] @validator_path = File.(@options[:validator_path]) end @options[:encrypted_data_bag_secret] ||= begin if @options[:encrypted_data_bag_secret_path] @encrypted_data_bag_secret_path = File.(@options[:encrypted_data_bag_secret_path]) end encrypted_data_bag_secret end unless verify_client_key(@options[:client_key]) @options[:client_key] = File.(@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.
90 91 92 |
# File 'lib/ridley/client.rb', line 90 def chef_version @chef_version end |
#encrypted_data_bag_secret_path ⇒ Object
Returns the value of attribute encrypted_data_bag_secret_path.
89 90 91 |
# File 'lib/ridley/client.rb', line 89 def encrypted_data_bag_secret_path @encrypted_data_bag_secret_path end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
85 86 87 |
# File 'lib/ridley/client.rb', line 85 def @options end |
#validator_client ⇒ Object
Returns the value of attribute validator_client.
87 88 89 |
# File 'lib/ridley/client.rb', line 87 def validator_client @validator_client end |
#validator_path ⇒ Object
Returns the value of attribute validator_path.
88 89 90 |
# File 'lib/ridley/client.rb', line 88 def validator_path @validator_path end |
Class Method Details
.open(options = {}, &block) ⇒ Object
34 35 36 37 38 39 |
# File 'lib/ridley/client.rb', line 34 def open( = {}, &block) client = new() yield client ensure client.terminate if client && client.alive? end |
.validate_options(options) ⇒ Boolean
44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/ridley/client.rb', line 44 def () missing = (REQUIRED_OPTIONS - .keys) if missing.any? missing.collect! { |opt| "'#{opt}'" } raise ArgumentError, "Missing required option(s): #{missing.join(', ')}" end missing_values = .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
#client ⇒ Ridley::ClientResource
151 152 153 |
# File 'lib/ridley/client.rb', line 151 def client @resources_registry[:client_resource] end |
#cookbook ⇒ Ridley::CookbookResource
156 157 158 |
# File 'lib/ridley/client.rb', line 156 def cookbook @resources_registry[:cookbook_resource] end |
#data_bag ⇒ Ridley::DataBagResource
161 162 163 |
# File 'lib/ridley/client.rb', line 161 def data_bag @resources_registry[:data_bag_resource] end |
#encrypted_data_bag_secret ⇒ String?
The encrypted data bag secret for this connection.
253 254 255 256 257 258 259 |
# File 'lib/ridley/client.rb', line 253 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 |
#environment ⇒ Ridley::EnvironmentResource
166 167 168 |
# File 'lib/ridley/client.rb', line 166 def environment @resources_registry[:environment_resource] end |
#node ⇒ Ridley::NodeResource
171 172 173 |
# File 'lib/ridley/client.rb', line 171 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.
244 245 246 |
# File 'lib/ridley/client.rb', line 244 def partial_search(index, query = nil, attributes = [], = {}) @resources_registry[:search_resource].partial(index, query, Array(attributes), @resources_registry, ) end |
#role ⇒ Ridley::RoleResource
176 177 178 |
# File 'lib/ridley/client.rb', line 176 def role @resources_registry[:role_resource] end |
#sandbox ⇒ Ridley::SandboxResource
181 182 183 |
# File 'lib/ridley/client.rb', line 181 def sandbox @resources_registry[:sandbox_resource] end |
#search(index, query = nil, options = {}) ⇒ Array<ChefObject>, Hash
Perform a search the Chef Server
203 204 205 |
# File 'lib/ridley/client.rb', line 203 def search(index, query = nil, = {}) @resources_registry[:search_resource].run(index, query, @resources_registry, ) end |
#search_indexes ⇒ Array<Symbol, String>
Return an array of all possible search indexes for the including connection
215 216 217 |
# File 'lib/ridley/client.rb', line 215 def search_indexes @resources_registry[:search_resource].indexes end |
#server_url ⇒ Object
261 262 263 |
# File 'lib/ridley/client.rb', line 261 def server_url self.url_prefix.to_s end |
#user ⇒ Ridley::UserResource
186 187 188 |
# File 'lib/ridley/client.rb', line 186 def user @resources_registry[:user_resource] end |