Class: SemgrepWebApp::Configuration
- Inherits:
-
CoreLibrary::HttpClientConfiguration
- Object
- CoreLibrary::HttpClientConfiguration
- SemgrepWebApp::Configuration
- Defined in:
- lib/semgrep_web_app/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::PRODUCTION => { Server::SEMGREP => 'https://semgrep.dev' } }.freeze
Class Attribute Summary collapse
-
.environments ⇒ Object
readonly
Returns the value of attribute environments.
Instance Attribute Summary collapse
-
#environment ⇒ Object
readonly
The attribute readers for properties.
-
#semgrep_admin_jwt_credentials ⇒ Object
readonly
The attribute readers for properties.
-
#semgrep_jwt_credentials ⇒ Object
readonly
The attribute readers for properties.
-
#semgrep_web_token_credentials ⇒ 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, logging_configuration: nil, environment: nil, semgrep_admin_jwt_credentials: nil, semgrep_jwt_credentials: nil, semgrep_web_token_credentials: nil) ⇒ Object
-
#get_base_uri(server = Server::SEMGREP) ⇒ String
Generates the appropriate base URI for the environment and the server.
-
#initialize(connection: nil, adapter: :net_http_persistent, timeout: 30, 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, logging_configuration: nil, environment: Environment::PRODUCTION, semgrep_admin_jwt_credentials: nil, semgrep_jwt_credentials: nil, semgrep_web_token_credentials: nil) ⇒ Configuration
constructor
A new instance of Configuration.
Constructor Details
#initialize(connection: nil, adapter: :net_http_persistent, timeout: 30, 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, logging_configuration: nil, environment: Environment::PRODUCTION, semgrep_admin_jwt_credentials: nil, semgrep_jwt_credentials: nil, semgrep_web_token_credentials: nil) ⇒ Configuration
Returns a new instance of Configuration.
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/semgrep_web_app/configuration.rb', line 46 def initialize( connection: nil, adapter: :net_http_persistent, timeout: 30, 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, logging_configuration: nil, environment: Environment::PRODUCTION, semgrep_admin_jwt_credentials: nil, semgrep_jwt_credentials: nil, semgrep_web_token_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, logging_configuration: logging_configuration # Current API environment @environment = String(environment) # The object holding OAuth 2 Bearer token credentials @semgrep_admin_jwt_credentials = semgrep_admin_jwt_credentials # The object holding OAuth 2 Bearer token credentials @semgrep_jwt_credentials = semgrep_jwt_credentials # The object holding OAuth 2 Bearer token credentials @semgrep_web_token_credentials = semgrep_web_token_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.
43 44 45 |
# File 'lib/semgrep_web_app/configuration.rb', line 43 def environments @environments end |
Instance Attribute Details
#environment ⇒ Object (readonly)
The attribute readers for properties.
39 40 41 |
# File 'lib/semgrep_web_app/configuration.rb', line 39 def environment @environment end |
#semgrep_admin_jwt_credentials ⇒ Object (readonly)
The attribute readers for properties.
39 40 41 |
# File 'lib/semgrep_web_app/configuration.rb', line 39 def semgrep_admin_jwt_credentials @semgrep_admin_jwt_credentials end |
#semgrep_jwt_credentials ⇒ Object (readonly)
The attribute readers for properties.
39 40 41 |
# File 'lib/semgrep_web_app/configuration.rb', line 39 def semgrep_jwt_credentials @semgrep_jwt_credentials end |
#semgrep_web_token_credentials ⇒ Object (readonly)
The attribute readers for properties.
39 40 41 |
# File 'lib/semgrep_web_app/configuration.rb', line 39 def semgrep_web_token_credentials @semgrep_web_token_credentials end |
Class Method Details
.build_default_config_from_env ⇒ Object
Builds a Configuration instance using environment variables.
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
# File 'lib/semgrep_web_app/configuration.rb', line 131 def self.build_default_config_from_env # === Core environment === environment = Environment.from_value(ENV.fetch('ENVIRONMENT', 'production')) timeout = (ENV['TIMEOUT'] || 30).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 === semgrep_admin_jwt_credentials = SemgrepAdminJwtCredentials.from_env semgrep_jwt_credentials = SemgrepJwtCredentials.from_env semgrep_web_token_credentials = SemgrepWebTokenCredentials.from_env # === Proxy settings === proxy_settings = ProxySettings.from_env # === Logging Configuration === logging_configuration = LoggingConfiguration.from_env if LoggingConfiguration.any_logging_configured? 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, semgrep_admin_jwt_credentials: semgrep_admin_jwt_credentials, semgrep_jwt_credentials: semgrep_jwt_credentials, semgrep_web_token_credentials: semgrep_web_token_credentials, proxy_settings: proxy_settings, logging_configuration: logging_configuration ) 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, logging_configuration: nil, environment: nil, semgrep_admin_jwt_credentials: nil, semgrep_jwt_credentials: nil, semgrep_web_token_credentials: nil) ⇒ Object
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 |
# File 'lib/semgrep_web_app/configuration.rb', line 78 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, logging_configuration: nil, environment: nil, semgrep_admin_jwt_credentials: nil, semgrep_jwt_credentials: nil, semgrep_web_token_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 logging_configuration ||= self.logging_configuration environment ||= self.environment semgrep_admin_jwt_credentials ||= self.semgrep_admin_jwt_credentials semgrep_jwt_credentials ||= self.semgrep_jwt_credentials semgrep_web_token_credentials ||= self.semgrep_web_token_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, logging_configuration: logging_configuration, environment: environment, semgrep_admin_jwt_credentials: semgrep_admin_jwt_credentials, semgrep_jwt_credentials: semgrep_jwt_credentials, semgrep_web_token_credentials: semgrep_web_token_credentials ) end |
#get_base_uri(server = Server::SEMGREP) ⇒ String
Generates the appropriate base URI for the environment and the server. required.
126 127 128 |
# File 'lib/semgrep_web_app/configuration.rb', line 126 def get_base_uri(server = Server::SEMGREP) ENVIRONMENTS[environment][server].clone end |