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_support_two_factor (Boolean)

    Set to enable two factor authentication (2FA) for this configuration/user

  • :brightbox_one_time_password (String)

    Set to pass through the current one time password when using 2FA

  • :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



52
53
54
# File 'lib/fog/brightbox/config.rb', line 52

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.



139
140
141
# File 'lib/fog/brightbox/config.rb', line 139

def 
  @current_account ||= @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



83
84
85
# File 'lib/fog/brightbox/config.rb', line 83

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

#cached_access_tokenObject



166
167
168
# File 'lib/fog/brightbox/config.rb', line 166

def cached_access_token
  @options[:brightbox_access_token]
end

#cached_refresh_tokenObject



174
175
176
# File 'lib/fog/brightbox/config.rb', line 174

def cached_refresh_token
  @options[:brightbox_refresh_token]
end

#change_account(new_account) ⇒ String

This changes the scoped account from the originally configured one to another.

Returns:

  • (String)

    The new account identifier used to scope API requests by.



146
147
148
# File 'lib/fog/brightbox/config.rb', line 146

def ()
  @current_account = 
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.



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

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.



124
125
126
# File 'lib/fog/brightbox/config.rb', line 124

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



88
89
90
# File 'lib/fog/brightbox/config.rb', line 88

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)


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

def config_service?
  true
end

#connection_optionsObject



157
158
159
160
# File 'lib/fog/brightbox/config.rb', line 157

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

#connection_persistent?Boolean

Returns:

  • (Boolean)


162
163
164
# File 'lib/fog/brightbox/config.rb', line 162

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

#credentialsOAuth2::CredentialSet



57
58
59
60
61
62
63
64
# File 'lib/fog/brightbox/config.rb', line 57

def credentials
  @credentials ||= OAuth2::CredentialSet.new(client_id, client_secret,
                                             :username => username,
                                             :password => password,
                                             :access_token => cached_access_token,
                                             :refresh_token => cached_refresh_token
                                            )
end

#default_image_idObject



202
203
204
# File 'lib/fog/brightbox/config.rb', line 202

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

#expire_tokens!Object

Allows classes sharing to mark the tokens as invalid in response to API status codes.



188
189
190
# File 'lib/fog/brightbox/config.rb', line 188

def expire_tokens!
  update_tokens(nil)
end

#latest_access_tokenObject



170
171
172
# File 'lib/fog/brightbox/config.rb', line 170

def latest_access_token
  credentials.access_token
end

#latest_refresh_tokenObject

This is the current, most up to date refresh token.



179
180
181
# File 'lib/fog/brightbox/config.rb', line 179

def latest_refresh_token
  credentials.refresh_token
end

#latest_tokenObject



206
207
208
# File 'lib/fog/brightbox/config.rb', line 206

def latest_token
  @options[:brightbox_access_token]
end

#managed_tokens?Boolean

Returns:

  • (Boolean)


198
199
200
# File 'lib/fog/brightbox/config.rb', line 198

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

#must_authenticate?Boolean

Returns:

  • (Boolean)


183
184
185
# File 'lib/fog/brightbox/config.rb', line 183

def must_authenticate?
  !credentials.access_token?
end

#one_time_passwordObject



238
239
240
# File 'lib/fog/brightbox/config.rb', line 238

def one_time_password
  @options[:brightbox_one_time_password]
end

#passwordString

Returns The configured password to use to identify the user.

Returns:

  • (String)

    The configured password to use to identify the user.



134
135
136
# File 'lib/fog/brightbox/config.rb', line 134

def password
  @options[:brightbox_password]
end

#regionObject



218
219
220
# File 'lib/fog/brightbox/config.rb', line 218

def region
  @options[:brightbox_region]
end

#reset_accountString

Sets the scoped account back to originally configured one.

Returns:

  • (String)

    The configured account identifier to scope API requests by.



153
154
155
# File 'lib/fog/brightbox/config.rb', line 153

def 
  @current_account = @options[:brightbox_account]
end

#service_nameObject



214
215
216
# File 'lib/fog/brightbox/config.rb', line 214

def service_name
  @options[:brightbox_service_name]
end

#service_typeObject



210
211
212
# File 'lib/fog/brightbox/config.rb', line 210

def service_type
  @options[:brightbox_service_type] || "object-store"
end

#storage_connection_optionsObject



226
227
228
# File 'lib/fog/brightbox/config.rb', line 226

def storage_connection_options
  @options[:connection_options] || {}
end

#storage_management_urlURI?

The #storage_management_url is based on the #storage_url and the account details used when autheticating. This is normally automatically discovered within the servive but can be overridden in the Fog::Brightbox::Config

Returns:

  • (URI)

    if the URL is configured

  • (nil)

    if the URL is not configured



103
104
105
106
107
108
109
# File 'lib/fog/brightbox/config.rb', line 103

def storage_management_url
  @storage_management_url ||= if @options.key?(:brightbox_storage_management_url)
                                URI.parse(@options[:brightbox_storage_management_url])
                              else
                                nil
                              end
end

#storage_management_url=(management_url) ⇒ Object

Parameters:

  • management_url (URI)

    The URI to use for management requests.

Raises:

  • (ArgumentError)

    if non URI object passed



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

def storage_management_url=(management_url)
  raise ArgumentError unless management_url.kind_of?(URI)
  @storage_management_url = management_url
end

#storage_temp_keyObject



230
231
232
# File 'lib/fog/brightbox/config.rb', line 230

def storage_temp_key
  @options[:brightbox_temp_url_key]
end

#storage_urlObject



93
94
95
# File 'lib/fog/brightbox/config.rb', line 93

def storage_url
  URI.parse(@options[:brightbox_storage_url] || "https://orbit.brightbox.com")
end

#tenantObject



222
223
224
# File 'lib/fog/brightbox/config.rb', line 222

def tenant
  @options[:brightbox_tenant]
end

#to_hashObject



78
79
80
# File 'lib/fog/brightbox/config.rb', line 78

def to_hash
  @options
end

#two_factor?Boolean

Returns:

  • (Boolean)


234
235
236
# File 'lib/fog/brightbox/config.rb', line 234

def two_factor?
  @options[:brightbox_support_two_factor] || false
end

#update_tokens(access_token, refresh_token = nil, expires_in = nil) ⇒ Object

Parameters:

  • access_token (String)

    The new access token to use

  • refresh_token (String) (defaults to: nil)

    The new refresh token to use



194
195
196
# File 'lib/fog/brightbox/config.rb', line 194

def update_tokens(access_token, refresh_token = nil, expires_in = nil)
  credentials.update_tokens(access_token, refresh_token, expires_in)
end

#user_credentials?Boolean

Returns:

  • (Boolean)


67
68
69
# File 'lib/fog/brightbox/config.rb', line 67

def user_credentials?
  credentials.user_details?
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.



129
130
131
# File 'lib/fog/brightbox/config.rb', line 129

def username
  @options[:brightbox_username]
end