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.
-
#ssh ⇒ Object
Returns the value of attribute ssh.
-
#validator_client ⇒ Object
Returns the value of attribute validator_client.
-
#validator_path ⇒ Object
Returns the value of attribute validator_path.
-
#winrm ⇒ Object
Returns the value of attribute winrm.
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
- #role ⇒ Ridley::RoleResource
- #sandbox ⇒ Ridley::SandboxResource
-
#search(index, query = nil, options = {}) ⇒ Hash
Perform a search the Chef Server.
-
#search_indexes ⇒ Array<Symbol, String>
Return the array of all possible search indexes for the including connection.
- #server_url ⇒ Object
Methods included from Logging
Constructor Details
#initialize(options = {}) ⇒ Client
Returns a new instance of Client.
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'lib/ridley/client.rb', line 129 def initialize( = {}) @options = .reverse_merge( ssh: Hash.new, winrm: Hash.new, pool_size: 4 ).deep_symbolize_keys self.class.(@options) @ssh = @options[:ssh] @winrm = @options[:winrm] @chef_version = @options[:chef_version] @validator_client = @options[:validator_client] @options[:client_key] = File.(@options[:client_key]) if @options[:validator_path] @validator_path = File.(@options[:validator_path]) end if @options[:encrypted_data_bag_secret_path] @encrypted_data_bag_secret_path = File.(@options[:encrypted_data_bag_secret_path]) end @options[:encrypted_data_bag_secret] = encrypted_data_bag_secret unless @options[:client_key].present? && File.exist?(@options[:client_key]) raise Errors::ClientKeyFileNotFound, "client key not found at: '#{@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.
91 92 93 |
# File 'lib/ridley/client.rb', line 91 def chef_version @chef_version end |
#encrypted_data_bag_secret_path ⇒ Object
Returns the value of attribute encrypted_data_bag_secret_path.
88 89 90 |
# File 'lib/ridley/client.rb', line 88 def encrypted_data_bag_secret_path @encrypted_data_bag_secret_path end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
84 85 86 |
# File 'lib/ridley/client.rb', line 84 def @options end |
#ssh ⇒ Object
Returns the value of attribute ssh.
89 90 91 |
# File 'lib/ridley/client.rb', line 89 def ssh @ssh end |
#validator_client ⇒ Object
Returns the value of attribute validator_client.
86 87 88 |
# File 'lib/ridley/client.rb', line 86 def validator_client @validator_client end |
#validator_path ⇒ Object
Returns the value of attribute validator_path.
87 88 89 |
# File 'lib/ridley/client.rb', line 87 def validator_path @validator_path end |
#winrm ⇒ Object
Returns the value of attribute winrm.
90 91 92 |
# File 'lib/ridley/client.rb', line 90 def winrm @winrm end |
Class Method Details
.open(options = {}, &block) ⇒ Object
33 34 35 36 37 38 |
# File 'lib/ridley/client.rb', line 33 def open( = {}, &block) client = new() yield client ensure client.terminate if client && client.alive? end |
.validate_options(options) ⇒ Boolean
43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/ridley/client.rb', line 43 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
165 166 167 |
# File 'lib/ridley/client.rb', line 165 def client @resources_registry[:client_resource] end |
#cookbook ⇒ Ridley::CookbookResource
170 171 172 |
# File 'lib/ridley/client.rb', line 170 def cookbook @resources_registry[:cookbook_resource] end |
#data_bag ⇒ Ridley::DataBagResource
175 176 177 |
# File 'lib/ridley/client.rb', line 175 def data_bag @resources_registry[:data_bag_resource] end |
#encrypted_data_bag_secret ⇒ String?
The encrypted data bag secret for this connection.
233 234 235 236 237 238 239 |
# File 'lib/ridley/client.rb', line 233 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
180 181 182 |
# File 'lib/ridley/client.rb', line 180 def environment @resources_registry[:environment_resource] end |
#node ⇒ Ridley::NodeResource
185 186 187 |
# File 'lib/ridley/client.rb', line 185 def node @resources_registry[:node_resource] end |
#role ⇒ Ridley::RoleResource
190 191 192 |
# File 'lib/ridley/client.rb', line 190 def role @resources_registry[:role_resource] end |
#sandbox ⇒ Ridley::SandboxResource
195 196 197 |
# File 'lib/ridley/client.rb', line 195 def sandbox @resources_registry[:sandbox_resource] end |
#search(index, query = nil, options = {}) ⇒ Hash
Perform a search the Chef Server
212 213 214 |
# File 'lib/ridley/client.rb', line 212 def search(index, query = nil, = {}) @resources_registry[:search_resource].run(index, query, @resources_registry, ) end |
#search_indexes ⇒ Array<Symbol, String>
Return the array of all possible search indexes for the including connection
224 225 226 |
# File 'lib/ridley/client.rb', line 224 def search_indexes @resources_registry[:search_resource].indexes end |
#server_url ⇒ Object
241 242 243 |
# File 'lib/ridley/client.rb', line 241 def server_url self.url_prefix.to_s end |