Method: Ridley::Client#initialize

Defined in:
lib/ridley/client.rb

#initialize(options = {}) ⇒ Client

Returns a new instance of Client.

Parameters:

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :server_url (String)

    URL to the Chef API

  • :client_name (String)

    name of the client used to authenticate with the Chef API

  • :client_key (String)

    filepath to the client’s private key used to authenticate with the Chef API

  • :validator_client (String) — default: nil
  • :validator_path (String) — default: nil
  • :encrypted_data_bag_secret_path (String) — default: nil
  • :chef_version (String)

    the version of Chef to use when bootstrapping

  • :params (Hash)

    URI query unencoded key/value pairs

  • :headers (Hash)

    unencoded HTTP header key/value pairs

  • :request (Hash)

    request options

  • :ssl (Hash)
    • :verify (Boolean) [true] set to false to disable SSL verification

  • :proxy (URI, String, Hash)

    URI, String, or Hash of HTTP proxy options

  • :pool_size (Integer) — default: 4

    size of the connection pool

Raises:



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