From d69f1f868544f328571183cd04d8aef2491188f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Serge=20H=C3=A4nni?= Date: Mon, 22 Apr 2024 18:03:14 +0200 Subject: [PATCH 1/2] Add missing env variable to README --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 6cc94b99..6cac46ca 100644 --- a/README.md +++ b/README.md @@ -116,6 +116,7 @@ and api_client_secret. You can setup these ENV variables: ENV['IOKI_OAUTH_APP_URL'] ENV['IOKI_RETRY_COUNT'] ENV['IOKI_RETRY_SLEEP_SECONDS'] + ENV['IOKI_IGNORE_DEPRECATED_ATTRIBUTES'] ``` or define them for one of the three supported apis with a prefix: From e4a4448ce9702c1828cdc2a2619430cd49866e7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Serge=20H=C3=A4nni?= Date: Mon, 22 Apr 2024 18:04:07 +0200 Subject: [PATCH 2/2] Add support for proxy settings --- README.md | 2 ++ lib/ioki/configuration.rb | 14 +++++++++++--- lib/ioki/http_adapter.rb | 8 +++++++- spec/ioki/configuration_spec.rb | 12 +++++++++--- 4 files changed, 29 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 6cac46ca..33dd84fb 100644 --- a/README.md +++ b/README.md @@ -117,6 +117,8 @@ and api_client_secret. You can setup these ENV variables: ENV['IOKI_RETRY_COUNT'] ENV['IOKI_RETRY_SLEEP_SECONDS'] ENV['IOKI_IGNORE_DEPRECATED_ATTRIBUTES'] + ENV['IOKI_PROXY_URL'] + ENV['IOKI_VERIFY_SSL'] ``` or define them for one of the three supported apis with a prefix: diff --git a/lib/ioki/configuration.rb b/lib/ioki/configuration.rb index e6ebb91e..74e206b2 100644 --- a/lib/ioki/configuration.rb +++ b/lib/ioki/configuration.rb @@ -11,7 +11,9 @@ class Configuration logger_options: { headers: true, bodies: false, log_level: :info }, retry_count: 3, retry_sleep_seconds: 1, - ignore_deprecated_attributes: false + ignore_deprecated_attributes: false, + proxy_url: nil, + verify_ssl: true }.freeze CONFIG_KEYS = [ @@ -34,7 +36,9 @@ class Configuration :oauth_token_callback, :retry_count, :retry_sleep_seconds, - :ignore_deprecated_attributes + :ignore_deprecated_attributes, + :proxy_url, + :verify_ssl ].freeze attr_accessor(*CONFIG_KEYS) @@ -61,6 +65,8 @@ def initialize(params = {}) @retry_count = params[:retry_count] @retry_sleep_seconds = params[:retry_sleep_seconds] @ignore_deprecated_attributes = params[:ignore_deprecated_attributes] + @proxy_url = params[:proxy_url] + @verify_ssl = params[:verify_ssl] # you can pass in a custom Faraday::Connection instance: @http_adapter = params[:http_adapter] || Ioki::HttpAdapter.get(self) @custom_http_adapter = !!params[:http_adapter] @@ -93,7 +99,9 @@ def self.values_from_env(env_prefix = '') oauth_app_url: ENV.fetch("#{prefix}_OAUTH_APP_URL", nil), retry_count: ENV.fetch("#{prefix}_RETRY_COUNT", nil), retry_sleep_seconds: ENV.fetch("#{prefix}_RETRY_SLEEP_SECONDS", nil), - ignore_deprecated_attributes: ENV.fetch("#{prefix}_IGNORE_DEPRECATED_ATTRIBUTES", nil) + ignore_deprecated_attributes: ENV.fetch("#{prefix}_IGNORE_DEPRECATED_ATTRIBUTES", nil), + proxy_url: ENV.fetch("#{prefix}_PROXY_URL", nil), + verify_ssl: ENV.fetch("#{prefix}_VERIFY_SSL", 'true')&.downcase == 'true' }.reject { |_key, value| value.nil? || value.to_s == '' } end diff --git a/lib/ioki/http_adapter.rb b/lib/ioki/http_adapter.rb index 561a4a13..911a673e 100644 --- a/lib/ioki/http_adapter.rb +++ b/lib/ioki/http_adapter.rb @@ -7,7 +7,13 @@ module Ioki class HttpAdapter def self.get(config) - ::Faraday.new(config.api_base_url, headers: headers(config)) do |f| + options = { + proxy: config.proxy_url, + ssl: { verify: config.verify_ssl }, + headers: headers(config) + } + + ::Faraday.new(config.api_base_url, options) do |f| f.adapter :net_http f.request :authorization, 'Bearer', -> { config.token } diff --git a/spec/ioki/configuration_spec.rb b/spec/ioki/configuration_spec.rb index ee7be6b8..8ced07db 100644 --- a/spec/ioki/configuration_spec.rb +++ b/spec/ioki/configuration_spec.rb @@ -36,7 +36,9 @@ :oauth_token_callback, :retry_count, :retry_sleep_seconds, - :ignore_deprecated_attributes + :ignore_deprecated_attributes, + :proxy_url, + :verify_ssl ) end @@ -52,6 +54,7 @@ describe 'default values and resetting' do before do allow(ENV).to receive(:fetch).and_return(nil) + allow(ENV).to receive(:fetch).with('IOKI_VERIFY_SSL', anything).and_return('true') stub_const( 'EXPECTED_DEFAULTS', { @@ -66,7 +69,9 @@ logger_options: described_class::DEFAULT_VALUES[:logger_options], retry_count: 3, retry_sleep_seconds: 1, - ignore_deprecated_attributes: false + ignore_deprecated_attributes: false, + proxy_url: nil, + verify_ssl: true }.freeze ) end @@ -89,7 +94,8 @@ expect { config.reset! }.to change { config.send(attribute) - }.from(:dummy_value).to(EXPECTED_DEFAULTS[attribute]) + }.from(:dummy_value).to(EXPECTED_DEFAULTS[attribute]), + "#{attribute} was expected to change to #{EXPECTED_DEFAULTS[attribute]}" end end end