Class: Fog::Brightbox::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/fog/brightbox/config.rb

Overview

The Config class is designed to encapsulate a group of settings for reuse between Brightbox services. The same config can be used for any service.

The config also holds the latest set of access tokens which when shared means when one service is told a token has expired then another will not retry it.

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Config

Creates a new set of configuration settings based on the options provided.

Examples:

Use Fog.credentials

# Assuming credentials are setup to return Brightbox settings and not other providers!
@config = Fog::Brightbox::Config.new(Fog.credentials)

Parameters:

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

    The configuration settings

Options Hash (options):

  • :brightbox_access_token (String)

    Set to use a cached OAuth access token to avoid having to request new access rights.

  • :brightbox_account (String)

    Set to specify the account to scope requests to if relevant. API clients are limited to their owning accounts but users can access any account they collaborate on.

  • :brightbox_api_url (String) — default: https://api.gb1.brightbox.com

    Set an alternative API endpoint to send requests to.

  • :brightbox_auth_url (String) — default: https://api.gb1.brightbox.com

    Set an alternative OAuth authentication endpoint to send requests to.

  • :brightbox_client_id (String)

    Set to specify the client identifier to use for requests. Either cli-12345 or app-12345 are suitable settings.

  • :brightbox_default_image (String)

    Set to specify a preferred image to use by default in the Compute service.

  • :brightbox_password (String)

    Set to specify your user’s password to authenticate yourself. This is independent of the client used to access the API.

  • :brightbox_refresh_token (String)

    Set to use a cached OAuth refresh token to avoid having to request new access rights.

  • :brightbox_secret (String)

    Set to specify the client secret to use for requests.

  • :brightbox_token_management (String) — default: true

    Set to specify if the service should handle expired tokens or raise an error instead.

  • :brightbox_username (String)

    Set to specify your user account. Either user identifier (usr-12345) or email address may be used.

  • :connection_options (String) — default: {}

    Set to pass options through to the HTTP connection.

  • :persistent (Boolean) — default: false

    Set to specify if the HTTP connection be persistent



48
49
50
# File 'lib/fog/brightbox/config.rb', line 48

def initialize(options = {})
  @options = options
end

Instance Method Details

#accountString

Returns The configured account identifier to scope API requests by.

Returns:

  • (String)

    The configured account identifier to scope API requests by.



95
96
97
# File 'lib/fog/brightbox/config.rb', line 95

def 
  @options[:brightbox_account]
end

#auth_urlURI::HTTPS

Returns A URI object for the authentication endpoint.

Returns:

  • (URI::HTTPS)

    A URI object for the authentication endpoint



64
65
66
# File 'lib/fog/brightbox/config.rb', line 64

def auth_url
  URI.parse(@options.fetch(:brightbox_auth_url, "https://api.gb1.brightbox.com"))
end

#cached_access_tokenObject



108
109
110
# File 'lib/fog/brightbox/config.rb', line 108

def cached_access_token
  @options[:brightbox_access_token]
end

#cached_refresh_tokenObject



112
113
114
# File 'lib/fog/brightbox/config.rb', line 112

def cached_refresh_token
  @options[:brightbox_refresh_token]
end

#client_idString

Returns The configured identifier of the API client or user application.

Returns:

  • (String)

    The configured identifier of the API client or user application.



75
76
77
# File 'lib/fog/brightbox/config.rb', line 75

def client_id
  @options[:brightbox_client_id]
end

#client_secretString

Returns The configured secret to use to identify the client.

Returns:

  • (String)

    The configured secret to use to identify the client.



80
81
82
# File 'lib/fog/brightbox/config.rb', line 80

def client_secret
  @options[:brightbox_secret]
end

#compute_urlURI::HTTPS Also known as: api_url

Returns A URI object for the main API/compute service endpoint.

Returns:

  • (URI::HTTPS)

    A URI object for the main API/compute service endpoint



69
70
71
# File 'lib/fog/brightbox/config.rb', line 69

def compute_url
  URI.parse(@options.fetch(:brightbox_api_url, "https://api.gb1.brightbox.com"))
end

#config_service?true

Can this be used to configure services? Yes, yes it can.

Returns:

  • (true)


55
56
57
# File 'lib/fog/brightbox/config.rb', line 55

def config_service?
  true
end

#connection_optionsObject



99
100
101
102
# File 'lib/fog/brightbox/config.rb', line 99

def connection_options
  # These are pretty much passed through to the requests as is.
  @options.fetch(:connection_options, {})
end

#connection_persistent?Boolean

Returns:

  • (Boolean)


104
105
106
# File 'lib/fog/brightbox/config.rb', line 104

def connection_persistent?
  @options.fetch(:persistent, false)
end

#default_image_idObject



120
121
122
# File 'lib/fog/brightbox/config.rb', line 120

def default_image_id
  @options.fetch(:brightbox_default_image, nil)
end

#managed_tokens?Boolean

Returns:

  • (Boolean)


116
117
118
# File 'lib/fog/brightbox/config.rb', line 116

def managed_tokens?
  @options.fetch(:brightbox_token_management, true)
end

#passwordString

Returns The configured password to use to identify the user.

Returns:

  • (String)

    The configured password to use to identify the user.



90
91
92
# File 'lib/fog/brightbox/config.rb', line 90

def password
  @options[:brightbox_password]
end

#to_hashObject



59
60
61
# File 'lib/fog/brightbox/config.rb', line 59

def to_hash
  @options
end

#usernameString

Returns The configured email or user identified to use when accessing the API.

Returns:

  • (String)

    The configured email or user identified to use when accessing the API.



85
86
87
# File 'lib/fog/brightbox/config.rb', line 85

def username
  @options[:brightbox_username]
end