Class: Fog::Brightbox::Config
- Inherits:
-
Object
- Object
- Fog::Brightbox::Config
- 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
-
#account ⇒ String
The configured account identifier to scope API requests by.
-
#auth_url ⇒ URI::HTTPS
A URI object for the authentication endpoint.
- #cached_access_token ⇒ Object
- #cached_refresh_token ⇒ Object
-
#change_account(new_account) ⇒ String
This changes the scoped account from the originally configured one to another.
-
#client_id ⇒ String
The configured identifier of the API client or user application.
-
#client_secret ⇒ String
The configured secret to use to identify the client.
-
#compute_url ⇒ URI::HTTPS
(also: #api_url)
A URI object for the main API/compute service endpoint.
-
#config_service? ⇒ true
Can this be used to configure services? Yes, yes it can.
- #connection_options ⇒ Object
- #connection_persistent? ⇒ Boolean
- #credentials ⇒ OAuth2::CredentialSet
- #default_image_id ⇒ Object
-
#expire_tokens! ⇒ Object
Allows classes sharing to mark the tokens as invalid in response to API status codes.
-
#initialize(options = {}) ⇒ Config
constructor
Creates a new set of configuration settings based on the options provided.
- #latest_access_token ⇒ Object
-
#latest_refresh_token ⇒ Object
This is the current, most up to date refresh token.
- #latest_token ⇒ Object
- #managed_tokens? ⇒ Boolean
- #must_authenticate? ⇒ Boolean
- #one_time_password ⇒ Object
-
#password ⇒ String
The configured password to use to identify the user.
- #region ⇒ Object
-
#reset_account ⇒ String
Sets the scoped account back to originally configured one.
- #service_name ⇒ Object
- #service_type ⇒ Object
- #storage_connection_options ⇒ Object
-
#storage_management_url ⇒ URI?
The #storage_management_url is based on the #storage_url and the account details used when autheticating.
- #storage_management_url=(management_url) ⇒ Object
- #storage_temp_key ⇒ Object
- #storage_url ⇒ Object
- #tenant ⇒ Object
- #to_hash ⇒ Object
- #two_factor? ⇒ Boolean
- #update_tokens(access_token, refresh_token = nil, expires_in = nil) ⇒ Object
- #user_credentials? ⇒ Boolean
-
#username ⇒ String
The configured email or user identified to use when accessing the API.
Constructor Details
#initialize(options = {}) ⇒ Config
Creates a new set of configuration settings based on the options provided.
52 53 54 |
# File 'lib/fog/brightbox/config.rb', line 52 def initialize( = {}) @options = end |
Instance Method Details
#account ⇒ String
Returns The configured account identifier to scope API requests by.
136 137 138 |
# File 'lib/fog/brightbox/config.rb', line 136 def account @current_account ||= @options[:brightbox_account] end |
#auth_url ⇒ URI::HTTPS
Returns A URI object for the authentication endpoint.
82 83 84 |
# File 'lib/fog/brightbox/config.rb', line 82 def auth_url URI.parse(@options.fetch(:brightbox_auth_url, "https://api.gb1.brightbox.com")) end |
#cached_access_token ⇒ Object
163 164 165 |
# File 'lib/fog/brightbox/config.rb', line 163 def cached_access_token @options[:brightbox_access_token] end |
#cached_refresh_token ⇒ Object
171 172 173 |
# File 'lib/fog/brightbox/config.rb', line 171 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.
143 144 145 |
# File 'lib/fog/brightbox/config.rb', line 143 def change_account(new_account) @current_account = new_account end |
#client_id ⇒ String
Returns The configured identifier of the API client or user application.
116 117 118 |
# File 'lib/fog/brightbox/config.rb', line 116 def client_id @options[:brightbox_client_id] end |
#client_secret ⇒ String
Returns The configured secret to use to identify the client.
121 122 123 |
# File 'lib/fog/brightbox/config.rb', line 121 def client_secret @options[:brightbox_secret] end |
#compute_url ⇒ URI::HTTPS Also known as: api_url
Returns A URI object for the main API/compute service endpoint.
87 88 89 |
# File 'lib/fog/brightbox/config.rb', line 87 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.
73 74 75 |
# File 'lib/fog/brightbox/config.rb', line 73 def config_service? true end |
#connection_options ⇒ Object
154 155 156 157 |
# File 'lib/fog/brightbox/config.rb', line 154 def # These are pretty much passed through to the requests as is. @options.fetch(:connection_options, {}) end |
#connection_persistent? ⇒ Boolean
159 160 161 |
# File 'lib/fog/brightbox/config.rb', line 159 def connection_persistent? @options.fetch(:persistent, false) end |
#credentials ⇒ OAuth2::CredentialSet
57 58 59 60 61 62 63 |
# 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_id ⇒ Object
199 200 201 |
# File 'lib/fog/brightbox/config.rb', line 199 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.
185 186 187 |
# File 'lib/fog/brightbox/config.rb', line 185 def expire_tokens! update_tokens(nil) end |
#latest_access_token ⇒ Object
167 168 169 |
# File 'lib/fog/brightbox/config.rb', line 167 def latest_access_token credentials.access_token end |
#latest_refresh_token ⇒ Object
This is the current, most up to date refresh token.
176 177 178 |
# File 'lib/fog/brightbox/config.rb', line 176 def latest_refresh_token credentials.refresh_token end |
#latest_token ⇒ Object
203 204 205 |
# File 'lib/fog/brightbox/config.rb', line 203 def latest_token @options[:brightbox_access_token] end |
#managed_tokens? ⇒ Boolean
195 196 197 |
# File 'lib/fog/brightbox/config.rb', line 195 def managed_tokens? @options.fetch(:brightbox_token_management, true) end |
#must_authenticate? ⇒ Boolean
180 181 182 |
# File 'lib/fog/brightbox/config.rb', line 180 def must_authenticate? !credentials.access_token? end |
#one_time_password ⇒ Object
235 236 237 |
# File 'lib/fog/brightbox/config.rb', line 235 def one_time_password @options[:brightbox_one_time_password] end |
#password ⇒ String
Returns The configured password to use to identify the user.
131 132 133 |
# File 'lib/fog/brightbox/config.rb', line 131 def password @options[:brightbox_password] end |
#region ⇒ Object
215 216 217 |
# File 'lib/fog/brightbox/config.rb', line 215 def region @options[:brightbox_region] end |
#reset_account ⇒ String
Sets the scoped account back to originally configured one.
150 151 152 |
# File 'lib/fog/brightbox/config.rb', line 150 def reset_account @current_account = @options[:brightbox_account] end |
#service_name ⇒ Object
211 212 213 |
# File 'lib/fog/brightbox/config.rb', line 211 def service_name @options[:brightbox_service_name] end |
#service_type ⇒ Object
207 208 209 |
# File 'lib/fog/brightbox/config.rb', line 207 def service_type @options[:brightbox_service_type] || "object-store" end |
#storage_connection_options ⇒ Object
223 224 225 |
# File 'lib/fog/brightbox/config.rb', line 223 def @options[:connection_options] || {} end |
#storage_management_url ⇒ URI?
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
102 103 104 105 106 |
# File 'lib/fog/brightbox/config.rb', line 102 def storage_management_url @storage_management_url ||= if @options.key?(:brightbox_storage_management_url) URI.parse(@options[:brightbox_storage_management_url]) end end |
#storage_management_url=(management_url) ⇒ Object
110 111 112 113 |
# File 'lib/fog/brightbox/config.rb', line 110 def storage_management_url=(management_url) raise ArgumentError unless management_url.is_a?(URI) @storage_management_url = management_url end |
#storage_temp_key ⇒ Object
227 228 229 |
# File 'lib/fog/brightbox/config.rb', line 227 def storage_temp_key @options[:brightbox_temp_url_key] end |
#storage_url ⇒ Object
92 93 94 |
# File 'lib/fog/brightbox/config.rb', line 92 def storage_url URI.parse(@options[:brightbox_storage_url] || "https://orbit.brightbox.com") end |
#tenant ⇒ Object
219 220 221 |
# File 'lib/fog/brightbox/config.rb', line 219 def tenant @options[:brightbox_tenant] end |
#to_hash ⇒ Object
77 78 79 |
# File 'lib/fog/brightbox/config.rb', line 77 def to_hash @options end |
#two_factor? ⇒ Boolean
231 232 233 |
# File 'lib/fog/brightbox/config.rb', line 231 def two_factor? @options[:brightbox_support_two_factor] || false end |
#update_tokens(access_token, refresh_token = nil, expires_in = nil) ⇒ Object
191 192 193 |
# File 'lib/fog/brightbox/config.rb', line 191 def update_tokens(access_token, refresh_token = nil, expires_in = nil) credentials.update_tokens(access_token, refresh_token, expires_in) end |
#user_credentials? ⇒ Boolean
66 67 68 |
# File 'lib/fog/brightbox/config.rb', line 66 def user_credentials? credentials.user_details? end |
#username ⇒ String
Returns The configured email or user identified to use when accessing the API.
126 127 128 |
# File 'lib/fog/brightbox/config.rb', line 126 def username @options[:brightbox_username] end |