Module: Spice::Config

Included in:
Spice
Defined in:
lib/spice/config.rb

Constant Summary collapse

DEFAULT_SERVER_URL =

The default Chef server URL

"http://localhost:4000"
DEFAULT_CHEF_VERSION =

The default Chef version (changing this will enable disable certain features)

"0.10.10"
DEFAULT_USER_AGENT =

The default Spice User-Agent header

"Spice #{Spice::VERSION}"
DEFAULT_CONNECTION_OPTIONS =

Default connection options

{}
DEFAULT_CLIENT_NAME =

Default client name

""
DEFAULT_CLIENT_KEY =

Default key file

""
VALID_OPTIONS_KEYS =

An array of valid config options

[
  :server_url,
  :client_name,
  :client_key,
  :chef_version,
  :user_agent,
  :connection_options,
  :middleware
]
DEFAULT_MIDDLEWARE =

Default middleware stack

Proc.new do |builder|
  builder.use Spice::Response::ParseJSON
  builder.use Spice::Response::ClientError
  builder.adapter Faraday.default_adapter
end

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(base) ⇒ Object

Reset all config options to default when the module is extended


51
52
53
# File 'lib/spice/config.rb', line 51

def self.extended(base)
  base.reset
end

Instance Method Details

#optionsObject

Create an options hash from valid options keys


70
71
72
73
74
# File 'lib/spice/config.rb', line 70

def options
  options = {}
  VALID_OPTIONS_KEYS.each{|k| options[k] = send(k)}
  options
end

#resetObject

Reset all config options to their defaults


77
78
79
80
81
82
83
84
85
86
# File 'lib/spice/config.rb', line 77

def reset
  self.user_agent         = DEFAULT_USER_AGENT
  self.server_url         = DEFAULT_SERVER_URL
  self.chef_version       = DEFAULT_CHEF_VERSION
  self.client_name        = DEFAULT_CLIENT_NAME
  self.client_key         = DEFAULT_CLIENT_KEY
  self.connection_options = DEFAULT_CONNECTION_OPTIONS
  self.middleware         = DEFAULT_MIDDLEWARE
  self
end

#setup {|Spice| ... } ⇒ Object

Convenience method to configure Spice in a block

Examples:

Configuring spice

Spice.setup do |s|
  s.server_url  = "http://chef.example.com:4000"
  s.client_name = "admin"
  s.client_key    = Spice.read_key_file("/path/to/key_file.pem")
end

Yield Parameters:

  • Spice

Yield Returns:

  • Spice


64
65
66
67
# File 'lib/spice/config.rb', line 64

def setup
  yield self
  self
end