Parent

Class/Module Index [+]

Quicksearch

Fog::Brightbox::Config

The {Fog::Brightbox::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.

Public Class Methods

new(options = {}) click to toggle source

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

@param [Hash] options The configuration settings @option options [String] :brightbox_access_token

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

@option options [String] :brightbox_account

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.

@option options [String] :brightbox_api_url (api.gb1.brightbox.com)

Set an alternative API endpoint to send requests to.

@option options [String] :brightbox_auth_url (api.gb1.brightbox.com)

Set an alternative OAuth authentication endpoint to send requests to.

@option options [String] :brightbox_client_id

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

@option options [String] :brightbox_default_image

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

@option options [String] :brightbox_password

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

@option options [String] :brightbox_refresh_token

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

@option options [String] :brightbox_secret

Set to specify the client secret to use for requests.

@option options [String] :brightbox_token_management (true)

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

@option options [String] :brightbox_username

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

@option options [String] :connection_options ({})

Set to pass options through to the HTTP connection.

@option options [Boolean] :persistent (false)

Set to specify if the HTTP connection be persistent

@example Use Fog.credentials

# Assuming credentials are setup to return Brightbox settings and not other providers!
@config = Fog::Brightbox::Config.new(Fog.credentials)
# File lib/fog/brightbox/config.rb, line 50
def initialize(options = {})
  @options = options
end

Public Instance Methods

account() click to toggle source

@return [String] The configured account identifier to scope API requests by.

# File lib/fog/brightbox/config.rb, line 129
def account
  @current_account ||= @options[:brightbox_account]
end
api_url() click to toggle source
Alias for: compute_url
auth_url() click to toggle source

@return [URI::HTTPS] A URI object for the authentication endpoint

# File lib/fog/brightbox/config.rb, line 81
def auth_url
  URI.parse(@options.fetch(:brightbox_auth_url, "https://api.gb1.brightbox.com"))
end
cached_access_token() click to toggle source
# File lib/fog/brightbox/config.rb, line 156
def cached_access_token
  @options[:brightbox_access_token]
end
cached_refresh_token() click to toggle source
# File lib/fog/brightbox/config.rb, line 164
def cached_refresh_token
  @options[:brightbox_refresh_token]
end
change_account(new_account) click to toggle source

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

@return [String] The new account identifier used to scope API requests by.

# File lib/fog/brightbox/config.rb, line 136
def change_account(new_account)
  @current_account = new_account
end
client_id() click to toggle source

@return [String] The configured identifier of the API client or user application.

# File lib/fog/brightbox/config.rb, line 109
def client_id
  @options[:brightbox_client_id]
end
client_secret() click to toggle source

@return [String] The configured secret to use to identify the client.

# File lib/fog/brightbox/config.rb, line 114
def client_secret
  @options[:brightbox_secret]
end
compute_url() click to toggle source

@return [URI::HTTPS] A URI object for the main API/compute service endpoint

# File lib/fog/brightbox/config.rb, line 86
def compute_url
  URI.parse(@options.fetch(:brightbox_api_url, "https://api.gb1.brightbox.com"))
end
Also aliased as: api_url
config_service?() click to toggle source

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

@return [true]

# File lib/fog/brightbox/config.rb, line 72
def config_service?
  true
end
connection_options() click to toggle source
# File lib/fog/brightbox/config.rb, line 147
def connection_options
  # These are pretty much passed through to the requests as is.
  @options.fetch(:connection_options, {})
end
connection_persistent?() click to toggle source
# File lib/fog/brightbox/config.rb, line 152
def connection_persistent?
  @options.fetch(:persistent, false)
end
credentials() click to toggle source

@return [OAuth2::CredentialSet]

# File lib/fog/brightbox/config.rb, line 55
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_id() click to toggle source
# File lib/fog/brightbox/config.rb, line 192
def default_image_id
  @options.fetch(:brightbox_default_image, nil)
end
expire_tokens!() click to toggle source

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

# File lib/fog/brightbox/config.rb, line 178
def expire_tokens!
  update_tokens(nil)
end
latest_access_token() click to toggle source
# File lib/fog/brightbox/config.rb, line 160
def latest_access_token
  credentials.access_token
end
latest_refresh_token() click to toggle source

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

# File lib/fog/brightbox/config.rb, line 169
def latest_refresh_token
  credentials.refresh_token
end
latest_token() click to toggle source
# File lib/fog/brightbox/config.rb, line 196
def latest_token
  @options[:brightbox_access_token]
end
managed_tokens?() click to toggle source
# File lib/fog/brightbox/config.rb, line 188
def managed_tokens?
  @options.fetch(:brightbox_token_management, true)
end
must_authenticate?() click to toggle source
# File lib/fog/brightbox/config.rb, line 173
def must_authenticate?
  !credentials.access_token?
end
password() click to toggle source

@return [String] The configured password to use to identify the user.

# File lib/fog/brightbox/config.rb, line 124
def password
  @options[:brightbox_password]
end
region() click to toggle source
# File lib/fog/brightbox/config.rb, line 208
def region
  @options[:brightbox_region]
end
reset_account() click to toggle source

Sets the scoped account back to originally configured one.

@return [String] The configured account identifier to scope API requests by.

# File lib/fog/brightbox/config.rb, line 143
def reset_account
  @current_account = @options[:brightbox_account]
end
service_name() click to toggle source
# File lib/fog/brightbox/config.rb, line 204
def service_name
  @options[:brightbox_service_name]
end
service_type() click to toggle source
# File lib/fog/brightbox/config.rb, line 200
def service_type
  @options[:brightbox_service_type] || "object-store"
end
storage_connection_options() click to toggle source
# File lib/fog/brightbox/config.rb, line 216
def storage_connection_options
  @options[:connection_options] || {}
end
storage_management_url() click to toggle source
# File lib/fog/brightbox/config.rb, line 95
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) click to toggle source

@param [URI] management_url The URI to use for management requests.

# File lib/fog/brightbox/config.rb, line 104
def storage_management_url=(management_url)
  @storage_management_url = management_url
end
storage_temp_key() click to toggle source
# File lib/fog/brightbox/config.rb, line 220
def storage_temp_key
  @options[:brightbox_temp_url_key]
end
storage_url() click to toggle source
# File lib/fog/brightbox/config.rb, line 91
def storage_url
  URI.parse(@options[:brightbox_storage_url] || "https://orbit.brightbox.com")
end
tenant() click to toggle source
# File lib/fog/brightbox/config.rb, line 212
def tenant
  @options[:brightbox_tenant]
end
to_hash() click to toggle source
# File lib/fog/brightbox/config.rb, line 76
def to_hash
  @options
end
update_tokens(access_token, refresh_token = nil, expires_in = nil) click to toggle source

@param [String] access_token The new access token to use @param [String] refresh_token The new refresh token to use

# File lib/fog/brightbox/config.rb, line 184
def update_tokens(access_token, refresh_token = nil, expires_in = nil)
  credentials.update_tokens(access_token, refresh_token, expires_in)
end
user_credentials?() click to toggle source

@return [Boolean]

# File lib/fog/brightbox/config.rb, line 65
def user_credentials?
  credentials.user_details?
end
username() click to toggle source

@return [String] The configured email or user identified to use when accessing the API.

# File lib/fog/brightbox/config.rb, line 119
def username
  @options[:brightbox_username]
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.