Class: ShellDataReportingApIs::Configuration
- Inherits:
-
CoreLibrary::HttpClientConfiguration
- Object
- CoreLibrary::HttpClientConfiguration
- ShellDataReportingApIs::Configuration
- Defined in:
- lib/shell_data_reporting_ap_is/configuration.rb
Overview
All configuration including auth info and base URI for the API access are configured in this class.
Constant Summary collapse
- ENVIRONMENTS =
All the environments the SDK can run in.
{ Environment::SIT => { Server::OAUTH_SERVER => 'https://api-test.shell.com', Server::SHELL => 'https://api-test.shell.com/test' }, Environment::PRODUCTION => { Server::OAUTH_SERVER => 'https://api.shell.com', Server::SHELL => 'https://api.shell.com' } }.freeze
Class Attribute Summary collapse
-
.environments ⇒ Object
readonly
Returns the value of attribute environments.
Instance Attribute Summary collapse
-
#client_credentials_auth_credentials ⇒ Object
readonly
The attribute readers for properties.
-
#environment ⇒ Object
readonly
The attribute readers for properties.
Class Method Summary collapse
-
.build_default_config_from_env ⇒ Object
Builds a Configuration instance using environment variables.
Instance Method Summary collapse
- #clone_with(connection: nil, adapter: nil, timeout: nil, max_retries: nil, retry_interval: nil, backoff_factor: nil, retry_statuses: nil, retry_methods: nil, http_callback: nil, proxy_settings: nil, environment: nil, o_auth_client_id: nil, o_auth_client_secret: nil, o_auth_token: nil, client_credentials_auth_credentials: nil) ⇒ Object
- #create_auth_credentials_object(o_auth_client_id, o_auth_client_secret, o_auth_token, client_credentials_auth_credentials) ⇒ Object
-
#get_base_uri(server = Server::SHELL) ⇒ String
Generates the appropriate base URI for the environment and the server.
-
#initialize(connection: nil, adapter: :net_http_persistent, timeout: 60, max_retries: 0, retry_interval: 1, backoff_factor: 2, retry_statuses: [408, 413, 429, 500, 502, 503, 504, 521, 522, 524], retry_methods: %i[get put],, http_callback: nil, proxy_settings: nil, environment: Environment::SIT, o_auth_client_id: nil, o_auth_client_secret: nil, o_auth_token: nil, client_credentials_auth_credentials: nil) ⇒ Configuration
constructor
A new instance of Configuration.
- #o_auth_client_id ⇒ Object
- #o_auth_client_secret ⇒ Object
- #o_auth_token ⇒ Object
Constructor Details
#initialize(connection: nil, adapter: :net_http_persistent, timeout: 60, max_retries: 0, retry_interval: 1, backoff_factor: 2, retry_statuses: [408, 413, 429, 500, 502, 503, 504, 521, 522, 524], retry_methods: %i[get put],, http_callback: nil, proxy_settings: nil, environment: Environment::SIT, o_auth_client_id: nil, o_auth_client_secret: nil, o_auth_token: nil, client_credentials_auth_credentials: nil) ⇒ Configuration
Returns a new instance of Configuration.
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/shell_data_reporting_ap_is/configuration.rb', line 75 def initialize( connection: nil, adapter: :net_http_persistent, timeout: 60, max_retries: 0, retry_interval: 1, backoff_factor: 2, retry_statuses: [408, 413, 429, 500, 502, 503, 504, 521, 522, 524], retry_methods: %i[get put], http_callback: nil, proxy_settings: nil, environment: Environment::SIT, o_auth_client_id: nil, o_auth_client_secret: nil, o_auth_token: nil, client_credentials_auth_credentials: nil ) super connection: connection, adapter: adapter, timeout: timeout, max_retries: max_retries, retry_interval: retry_interval, backoff_factor: backoff_factor, retry_statuses: retry_statuses, retry_methods: retry_methods, http_callback: http_callback, proxy_settings: proxy_settings # Current API environment @environment = String(environment) # OAuth 2 Client ID @o_auth_client_id = o_auth_client_id # OAuth 2 Client Secret @o_auth_client_secret = o_auth_client_secret # Object for storing information about the OAuth token @o_auth_token = if o_auth_token.is_a? OAuthToken OAuthToken.from_hash o_auth_token.to_hash else o_auth_token end # Initializing OAuth 2 Client Credentials Grant credentials with the provided auth parameters @client_credentials_auth_credentials = create_auth_credentials_object( o_auth_client_id, o_auth_client_secret, o_auth_token, client_credentials_auth_credentials ) # The Http Client to use for making requests. set_http_client CoreLibrary::FaradayClient.new(self) end |
Class Attribute Details
.environments ⇒ Object (readonly)
Returns the value of attribute environments.
72 73 74 |
# File 'lib/shell_data_reporting_ap_is/configuration.rb', line 72 def environments @environments end |
Instance Attribute Details
#client_credentials_auth_credentials ⇒ Object (readonly)
The attribute readers for properties.
69 70 71 |
# File 'lib/shell_data_reporting_ap_is/configuration.rb', line 69 def client_credentials_auth_credentials @client_credentials_auth_credentials end |
#environment ⇒ Object (readonly)
The attribute readers for properties.
69 70 71 |
# File 'lib/shell_data_reporting_ap_is/configuration.rb', line 69 def environment @environment end |
Class Method Details
.build_default_config_from_env ⇒ Object
Builds a Configuration instance using environment variables.
194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 |
# File 'lib/shell_data_reporting_ap_is/configuration.rb', line 194 def self.build_default_config_from_env # === Core environment === environment = Environment.from_value(ENV.fetch('ENVIRONMENT', 'sit')) timeout = (ENV['TIMEOUT'] || 60).to_f max_retries = (ENV['MAX_RETRIES'] || 0).to_i retry_interval = (ENV['RETRY_INTERVAL'] || 1).to_f backoff_factor = (ENV['BACKOFF_FACTOR'] || 2).to_f retry_statuses = ENV.fetch('RETRY_STATUSES', '[408, 413, 429, 500, 502, 503, 504, 521, 522, 524]').gsub(/[\[\]]/, '') .split(',') .map(&:strip) .map do |item| item.match?(/\A\d+\z/) ? item.to_i : item.downcase end retry_methods = ENV.fetch('RETRY_METHODS', '%i[get put]').gsub(/[\[\]]/, '') .split(',') .map(&:strip) .map do |item| item.match?(/\A\d+\z/) ? item.to_i : item.downcase end # === Authentication credentials === client_credentials_auth_credentials = ClientCredentialsAuthCredentials.from_env # === Proxy settings === proxy_settings = ProxySettings.from_env Configuration.new( environment: environment, timeout: timeout, max_retries: max_retries, retry_interval: retry_interval, backoff_factor: backoff_factor, retry_statuses: retry_statuses, retry_methods: retry_methods, client_credentials_auth_credentials: client_credentials_auth_credentials, proxy_settings: proxy_settings ) end |
Instance Method Details
#clone_with(connection: nil, adapter: nil, timeout: nil, max_retries: nil, retry_interval: nil, backoff_factor: nil, retry_statuses: nil, retry_methods: nil, http_callback: nil, proxy_settings: nil, environment: nil, o_auth_client_id: nil, o_auth_client_secret: nil, o_auth_token: nil, client_credentials_auth_credentials: nil) ⇒ Object
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/shell_data_reporting_ap_is/configuration.rb', line 116 def clone_with(connection: nil, adapter: nil, timeout: nil, max_retries: nil, retry_interval: nil, backoff_factor: nil, retry_statuses: nil, retry_methods: nil, http_callback: nil, proxy_settings: nil, environment: nil, o_auth_client_id: nil, o_auth_client_secret: nil, o_auth_token: nil, client_credentials_auth_credentials: nil) connection ||= self.connection adapter ||= self.adapter timeout ||= self.timeout max_retries ||= self.max_retries retry_interval ||= self.retry_interval backoff_factor ||= self.backoff_factor retry_statuses ||= self.retry_statuses retry_methods ||= self.retry_methods http_callback ||= self.http_callback proxy_settings ||= self.proxy_settings environment ||= self.environment client_credentials_auth_credentials = create_auth_credentials_object( o_auth_client_id, o_auth_client_secret, o_auth_token, client_credentials_auth_credentials || self.client_credentials_auth_credentials ) Configuration.new( connection: connection, adapter: adapter, timeout: timeout, max_retries: max_retries, retry_interval: retry_interval, backoff_factor: backoff_factor, retry_statuses: retry_statuses, retry_methods: retry_methods, http_callback: http_callback, proxy_settings: proxy_settings, environment: environment, client_credentials_auth_credentials: client_credentials_auth_credentials ) end |
#create_auth_credentials_object(o_auth_client_id, o_auth_client_secret, o_auth_token, client_credentials_auth_credentials) ⇒ Object
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 |
# File 'lib/shell_data_reporting_ap_is/configuration.rb', line 148 def create_auth_credentials_object(o_auth_client_id, o_auth_client_secret, o_auth_token, client_credentials_auth_credentials) return client_credentials_auth_credentials if o_auth_client_id.nil? && o_auth_client_secret.nil? && o_auth_token.nil? warn('The \'o_auth_client_id\', \'o_auth_client_secret\', \'o_auth_token'\ '\' params are deprecated. Use \'client_credentials_auth_credential'\ 's\' param instead.') unless client_credentials_auth_credentials.nil? return client_credentials_auth_credentials.clone_with( o_auth_client_id: o_auth_client_id, o_auth_client_secret: o_auth_client_secret, o_auth_token: o_auth_token ) end ClientCredentialsAuthCredentials.new( o_auth_client_id: o_auth_client_id, o_auth_client_secret: o_auth_client_secret, o_auth_token: o_auth_token ) end |
#get_base_uri(server = Server::SHELL) ⇒ String
Generates the appropriate base URI for the environment and the server. required.
189 190 191 |
# File 'lib/shell_data_reporting_ap_is/configuration.rb', line 189 def get_base_uri(server = Server::SHELL) ENVIRONMENTS[environment][server].clone end |
#o_auth_client_id ⇒ Object
56 57 58 |
# File 'lib/shell_data_reporting_ap_is/configuration.rb', line 56 def o_auth_client_id @client_credentials_auth_credentials.o_auth_client_id end |
#o_auth_client_secret ⇒ Object
60 61 62 |
# File 'lib/shell_data_reporting_ap_is/configuration.rb', line 60 def o_auth_client_secret @client_credentials_auth_credentials.o_auth_client_secret end |
#o_auth_token ⇒ Object
64 65 66 |
# File 'lib/shell_data_reporting_ap_is/configuration.rb', line 64 def o_auth_token @client_credentials_auth_credentials.o_auth_token end |