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
235 236 237 |
# File 'lib/fog/brightbox/compute.rb', line 235 def access_token @credentials.access_token end |
#access_token_available? ⇒ Boolean
Returns true if an access token is set
229 230 231 |
# File 'lib/fog/brightbox/compute.rb', line 229 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 the service or thebrightbox_account
setting in your configuration
216 217 218 219 |
# File 'lib/fog/brightbox/compute.rb', line 216 def account account_data = get_scoped_account.merge(:service => self) Fog::Compute::Brightbox::Account.new(account_data) end |
#authenticating_as_user? ⇒ Boolean
Returns true if authentication is being performed as a user
223 224 225 |
# File 'lib/fog/brightbox/compute.rb', line 223 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!
277 278 279 280 |
# File 'lib/fog/brightbox/compute.rb', line 277 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
248 249 250 251 252 253 254 255 |
# File 'lib/fog/brightbox/compute.rb', line 248 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
262 263 264 265 266 |
# File 'lib/fog/brightbox/compute.rb', line 262 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 create service 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
241 242 243 |
# File 'lib/fog/brightbox/compute.rb', line 241 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 |