Module: Fog::Compute::Brightbox::Shared
Instance Method Summary collapse
-
#access_token ⇒ String?
Returns the current access token or nil.
-
#access_token_available? ⇒ Boolean
Returns true if an access token is set.
-
#account ⇒ Fog::Compute::Brightbox::Account
Returns the scoped account being used for requests.
-
#authenticating_as_user? ⇒ Boolean
Returns true if authentication is being performed as a user.
-
#default_image ⇒ String?
Returns an identifier for the default image for use.
-
#get_access_token ⇒ String
Requests a new access token.
-
#get_access_token! ⇒ String
Requests a new access token and raises if there is a problem.
-
#initialize(options) ⇒ Object
Creates a new instance of the Brightbox Compute service.
-
#refresh_token ⇒ String?
Returns the current refresh token or nil.
-
#scoped_account(options_account = nil) ⇒ String?
This returns the account identifier that the request should be scoped by based on the options passed to the request and current configuration.
-
#scoped_account=(scoped_account) ⇒ Object
Sets the scoped account for future requests.
-
#scoped_account_reset ⇒ Object
Resets the scoped account back to intially configured one.
Methods included from Brightbox::OAuth2
Instance Method Details
#access_token ⇒ String?
Returns the current access token or nil
237 238 239 |
# File 'lib/fog/brightbox/compute.rb', line 237 def access_token @credentials.access_token end |
#access_token_available? ⇒ Boolean
Returns true if an access token is set
231 232 233 |
# File 'lib/fog/brightbox/compute.rb', line 231 def access_token_available? !! @credentials.access_token end |
#account ⇒ Fog::Compute::Brightbox::Account
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 a connection or thebrightbox_account
setting in your configuration
216 217 218 219 220 221 |
# File 'lib/fog/brightbox/compute.rb', line 216 def account Fog::Compute::Brightbox::Account.new(get_scoped_account).tap do |acc| # Connection is more like the compute 'service' acc.connection = self end end |
#authenticating_as_user? ⇒ Boolean
Returns true if authentication is being performed as a user
225 226 227 |
# File 'lib/fog/brightbox/compute.rb', line 225 def authenticating_as_user? @credentials.user_details? end |
#default_image ⇒ String?
Returns an identifier for the default image for use
Currently tries to find the latest version Ubuntu LTS (i686) widening up to the latest, official version of Ubuntu available.
Highly recommended that you actually select the image you want to run on your servers yourself!
279 280 281 282 |
# File 'lib/fog/brightbox/compute.rb', line 279 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 ⇒ String
Requests a new access token
250 251 252 253 254 255 256 257 |
# 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! ⇒ String
Requests a new access token and raises if there is a problem
264 265 266 267 268 |
# 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 |
#initialize(options) ⇒ Object
If you open a connection using just a refresh token when it expires the service will no longer be able to authenticate.
Creates a new instance of the Brightbox Compute service
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 |
# File 'lib/fog/brightbox/compute.rb', line 158 def initialize() # Currently authentication and api endpoints are the same but may change @auth_url = [:brightbox_auth_url] || Fog.credentials[:brightbox_auth_url] || API_URL @auth_connection = Fog::Connection.new(@auth_url) @api_url = [:brightbox_api_url] || Fog.credentials[:brightbox_api_url] || API_URL @connection_options = [:connection_options] || {} @persistent = [:persistent] || false @connection = Fog::Connection.new(@api_url, @persistent, @connection_options) # Authentication options client_id = [:brightbox_client_id] || Fog.credentials[:brightbox_client_id] client_secret = [:brightbox_secret] || Fog.credentials[:brightbox_secret] username = [:brightbox_username] || Fog.credentials[:brightbox_username] password = [:brightbox_password] || Fog.credentials[:brightbox_password] @configured_account = [:brightbox_account] || Fog.credentials[:brightbox_account] # Request account can be changed at anytime and changes behaviour of future requests @scoped_account = @configured_account = {:username => username, :password => password} @credentials = CredentialSet.new(client_id, client_secret, ) # If existing tokens have been cached, allow continued use of them in the service @credentials.update_tokens([:brightbox_access_token], [:brightbox_refresh_token]) @token_management = .fetch(:brightbox_token_management, true) end |
#refresh_token ⇒ String?
Returns the current refresh token or nil
243 244 245 |
# File 'lib/fog/brightbox/compute.rb', line 243 def refresh_token @credentials.refresh_token end |
#scoped_account(options_account = nil) ⇒ String?
This returns the account identifier that the request should be scoped by based on the options passed to the request and current configuration
199 200 201 |
# File 'lib/fog/brightbox/compute.rb', line 199 def scoped_account( = nil) [, @scoped_account].compact.first end |
#scoped_account=(scoped_account) ⇒ Object
Sets the scoped account for future requests
189 190 191 |
# File 'lib/fog/brightbox/compute.rb', line 189 def scoped_account=(scoped_account) @scoped_account = scoped_account end |
#scoped_account_reset ⇒ Object
Resets the scoped account back to intially configured one
204 205 206 |
# File 'lib/fog/brightbox/compute.rb', line 204 def scoped_account_reset @scoped_account = @configured_account end |