Module: PuppetRestClient::DB::Config

Included in:
PuppetRestClient::DB
Defined in:
lib/puppet-rest/db/config.rb

Constant Summary collapse

DEFAULT_SERVER_URL =

The default Chef server URL

'http://localhost:8080'
DEFAULT_USER_AGENT =

The default Spice User-Agent header

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

Default connection options

{}
DEFAULT_CLIENT_NAME =

Default client name

''
DEFAULT_CLIENT_KEY =

Default key file

''
DEFAULT_API_VERSION =

Default puppetdb rest api version (e.g. v1, v2, v3, pdb/query/v4)

'v2'
VALID_OPTIONS_KEYS =

An array of valid config options

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

Default middleware stack

Proc.new do |builder|
  builder.use PuppetRestClient::Response::ParseJSON
  builder.use PuppetRestClient::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



45
46
47
# File 'lib/puppet-rest/db/config.rb', line 45

def self.extended(base)
  base.reset
end

Instance Method Details

#optionsObject

Create an options hash from valid options keys



64
65
66
67
68
# File 'lib/puppet-rest/db/config.rb', line 64

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

#resetObject

Reset all config options to their defaults



71
72
73
74
75
76
77
78
79
80
# File 'lib/puppet-rest/db/config.rb', line 71

def reset
  self.user_agent         = DEFAULT_USER_AGENT
  self.api_version        = DEFAULT_API_VERSION
  self.server_url         = DEFAULT_SERVER_URL
  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 {|PuppetRestClient| ... } ⇒ Object

Convenience method to configure PuppetRestClient in a block

Examples:

Configuring PuppetRestClient

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

Yield Parameters:

  • PuppetRestClient

Yield Returns:

  • PuppetRestClient



58
59
60
61
# File 'lib/puppet-rest/db/config.rb', line 58

def setup
  yield self
  self
end