Module: ChefAPI::Defaults

Defined in:
lib/chef-api/defaults.rb

Constant Summary collapse

ENDPOINT =

Default API endpoint

'https://api.opscode.com/'.freeze
USER_AGENT =

Default User Agent header string

"ChefAPI Ruby Gem #{ChefAPI::VERSION}".freeze

Class Method Summary collapse

Class Method Details

.clientString?

The name of the Chef API client. This is the equivalent of client_name in Chef terminology. In most cases, this is your Chef username.

Returns:

  • (String, nil)


76
77
78
# File 'lib/chef-api/defaults.rb', line 76

def client
  ENV['CHEF_API_CLIENT']
end

.endpointString

The endpoint where the Chef Server lives. This is equivalent to the chef_server_url in Chef terminology. If you are using Enterprise Hosted Chef or Enterprise Chef on premise, this endpoint should include your organization name. For example:

https://api.opscode.com/organizations/bacon

If you are running Open Source Chef Server or Chef Zero, this is the full URL to your Chef Server instance, including the server port and FQDN.

https://chef.server.local:4567/

Returns:

  • (String)

    (default: https://api.opscode.com/)



37
38
39
# File 'lib/chef-api/defaults.rb', line 37

def endpoint
  ENV['CHEF_API_ENDPOINT'] || ENDPOINT
end

.flavortrue, false

The flavor of the target Chef Server. There are two possible values:

- enterprise
- open_source

“Enterprise” covers both Hosted Chef and Enterprise Chef. “Open Source” covers both Chef Zero and Open Source Chef Server.

Returns:

  • (true, false)


52
53
54
55
56
57
58
# File 'lib/chef-api/defaults.rb', line 52

def flavor
  if ENV['CHEF_API_FLAVOR']
    ENV['CHEF_API_FLAVOR'].to_sym
  else
    endpoint.include?('/organizations') ? :enterprise : :open_source
  end
end

.keyString?

The private key to authentication against the Chef Server. This is equivalent to the client_key in Chef terminology. This value can be the client key in plain text or a path to the key on disk.

Returns:

  • (String, nil)


87
88
89
# File 'lib/chef-api/defaults.rb', line 87

def key
  ENV['CHEF_API_KEY']
end

.optionsHash

The list of calculated default options for the configuration.

Returns:

  • (Hash)


17
18
19
# File 'lib/chef-api/defaults.rb', line 17

def options
  Hash[Configurable.keys.map { |key| [key, send(key)] }]
end

.proxy_addressString?

The HTTP Proxy server address as a string

Returns:

  • (String, nil)


95
96
97
# File 'lib/chef-api/defaults.rb', line 95

def proxy_address
  ENV['CHEF_API_PROXY_ADDRESS']
end

.proxy_passwordString?

The HTTP Proxy user password as a string

Returns:

  • (String, nil)


104
105
106
# File 'lib/chef-api/defaults.rb', line 104

def proxy_password
  ENV['CHEF_API_PROXY_PASSWORD']
end

.proxy_portString?

The HTTP Proxy server port as a string

Returns:

  • (String, nil)


113
114
115
# File 'lib/chef-api/defaults.rb', line 113

def proxy_port
  ENV['CHEF_API_PROXY_PORT']
end

.proxy_usernameString?

The HTTP Proxy server username as a string

Returns:

  • (String, nil)


122
123
124
# File 'lib/chef-api/defaults.rb', line 122

def proxy_username
  ENV['CHEF_API_PROXY_USERNAME']
end

.ssl_pem_fileString?

The path to a pem file on disk for use with a custom SSL verification

Returns:

  • (String, nil)


131
132
133
# File 'lib/chef-api/defaults.rb', line 131

def ssl_pem_file
  ENV['CHEF_API_SSL_PEM_FILE']
end

.ssl_verifytrue, false

Verify SSL requests (default: true)

Returns:

  • (true, false)


140
141
142
143
144
145
146
# File 'lib/chef-api/defaults.rb', line 140

def ssl_verify
  if ENV['CHEF_API_SSL_VERIFY'].nil?
    true
  else
    %w[t y].include?(ENV['CHEF_API_SSL_VERIFY'].downcase[0])
  end
end

.user_agentString

The User Agent header to send along.

Returns:

  • (String)


65
66
67
# File 'lib/chef-api/defaults.rb', line 65

def user_agent
  ENV['CHEF_API_USER_AGENT'] || USER_AGENT
end