Included Modules

Class/Module Index [+]

Quicksearch

Fog::Compute::Brightbox::Shared

Public Class Methods

new(options) click to toggle source

Creates a new instance of the Brightbox Compute service

@note If you create service using just a refresh token when it

expires the service will no longer be able to authenticate.

@param [Hash] options @option options [String] :brightbox_api_url Override the default (or configured) API endpoint @option options [String] :brightbox_auth_url Override the default (or configured) API authentication endpoint @option options [String] :brightbox_client_id Client identifier to authenticate with (overrides configured) @option options [String] :brightbox_secret Client secret to authenticate with (overrides configured) @option options [String] :brightbox_username Email or user identifier for user based authentication @option options [String] :brightbox_password Password for user based authentication @option options [String] :brightbox_account Account identifier to scope this connection to @option options [String] :connection_options Settings to pass to underlying {Fog::Connection} @option options [Boolean] :persistent Sets a persistent HTTP {Fog::Connection} @option options [String] :brightbox_access_token Sets the OAuth access token to use rather than requesting a new token @option options [String] :brightbox_refresh_token Sets the refresh token to use when requesting a newer access token @option options [String] :brightbox_token_management Overide the existing behaviour to request access tokens if expired (default is `true`)

# File lib/fog/brightbox/compute.rb, line 160
def initialize(options)
  # Currently authentication and api endpoints are the same but may change
  @auth_url            = options[:brightbox_auth_url]  || Fog.credentials[:brightbox_auth_url] || API_URL
  @auth_connection     = Fog::Connection.new(@auth_url)

  @api_url             = options[:brightbox_api_url]   || Fog.credentials[:brightbox_api_url]  || API_URL
  @connection_options  = options[:connection_options]  || {}
  @persistent          = options[:persistent]          || false
  @connection          = Fog::Connection.new(@api_url, @persistent, @connection_options)

  # Authentication options
  client_id            = options[:brightbox_client_id] || Fog.credentials[:brightbox_client_id]
  client_secret        = options[:brightbox_secret]    || Fog.credentials[:brightbox_secret]

  username             = options[:brightbox_username]  || Fog.credentials[:brightbox_username]
  password             = options[:brightbox_password]  || Fog.credentials[:brightbox_password]
  @configured_account  = options[:brightbox_account]   || Fog.credentials[:brightbox_account]
  # Request account can be changed at anytime and changes behaviour of future requests
  @scoped_account      = @configured_account

  credential_options   = {:username => username, :password => password}
  @credentials         = CredentialSet.new(client_id, client_secret, credential_options)

  # If existing tokens have been cached, allow continued use of them in the service
  @credentials.update_tokens(options[:brightbox_access_token], options[:brightbox_refresh_token])

  @token_management    = options.fetch(:brightbox_token_management, true)
end

Public Instance Methods

access_token() click to toggle source

Returns the current access token or nil @return [String,nil]

# File lib/fog/brightbox/compute.rb, line 237
def access_token
  @credentials.access_token
end
access_token_available?() click to toggle source

Returns true if an access token is set @return [Boolean]

# File lib/fog/brightbox/compute.rb, line 231
def access_token_available?
  !! @credentials.access_token
end
account() click to toggle source

Returns the scoped account being used for requests

  • For API clients this is the owning account

  • For User applications this is the account specified by either account_id option on the service or the brightbox_account setting in your configuration

@return [Fog::Compute::Brightbox::Account]

# File lib/fog/brightbox/compute.rb, line 218
def account
  account_data = get_scoped_account.merge(:service => self)
  Fog::Compute::Brightbox::Account.new(account_data)
end
authenticating_as_user?() click to toggle source

Returns true if authentication is being performed as a user @return [Boolean]

# File lib/fog/brightbox/compute.rb, line 225
def authenticating_as_user?
  @credentials.user_details?
end
default_image() click to toggle source

Returns an identifier for the default image for use

Currently tries to find the latest version of Ubuntu (i686) from Brightbox.

Highly recommended that you actually select the image you want to run on your servers yourself!

@return [String] if image is found, returns the identifier @return [NilClass] if no image is found or an error occurs

# File lib/fog/brightbox/compute.rb, line 281
def default_image
  return @default_image_id unless @default_image_id.nil?
  @default_image_id = Fog.credentials[:brightbox_default_image] || select_default_image
end
get_access_token() click to toggle source

Requests a new access token

@return [String] New access token

# File lib/fog/brightbox/compute.rb, line 250
def get_access_token
  begin
    get_access_token!
  rescue Excon::Errors::Unauthorized, Excon::Errors::BadRequest
    @credentials.update_tokens(nil, nil)
  end
  @credentials.access_token
end
get_access_token!() click to toggle source

Requests a new access token and raises if there is a problem

@return [String] New access token @raise [Excon::Errors::BadRequest] The credentials are expired or incorrect

# File lib/fog/brightbox/compute.rb, line 264
def get_access_token!
  response = request_access_token(@auth_connection, @credentials)
  update_credentials_from_response(@credentials, response)
  @credentials.access_token
end
refresh_token() click to toggle source

Returns the current refresh token or nil @return [String,nil]

# File lib/fog/brightbox/compute.rb, line 243
def refresh_token
  @credentials.refresh_token
end
scoped_account(options_account = nil) click to toggle source

This returns the account identifier that the request should be scoped by based on the options passed to the request and current configuration

@param [String] options_account Any identifier passed into the request

@return [String, nil] The account identifier to scope the request to or nil

# File lib/fog/brightbox/compute.rb, line 201
def scoped_account(options_account = nil)
  [options_account, @scoped_account].compact.first
end
scoped_account=(scoped_account) click to toggle source

Sets the scoped account for future requests @param [String] scoped_account Identifier of the account to scope request to

# File lib/fog/brightbox/compute.rb, line 191
def scoped_account=(scoped_account)
  @scoped_account = scoped_account
end
scoped_account_reset() click to toggle source

Resets the scoped account back to intially configured one

# File lib/fog/brightbox/compute.rb, line 206
def scoped_account_reset
  @scoped_account = @configured_account
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.