From 97b693b6f60406a7d0eeb9ce26d49426c05ae65a Mon Sep 17 00:00:00 2001 From: Kjetil Joergensen Date: Mon, 14 Feb 2022 18:06:28 -0800 Subject: [PATCH 1/4] load bearer token inline with request --- lib/kubeclient.rb | 9 ++------- lib/kubeclient/version.rb | 2 +- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/lib/kubeclient.rb b/lib/kubeclient.rb index a0ba6518..87398e33 100644 --- a/lib/kubeclient.rb +++ b/lib/kubeclient.rb @@ -353,6 +353,8 @@ def create_faraday_client Faraday.new(url, options) do |connection| if @auth_options[:username] connection.request(:basic_auth, @auth_options[:username], @auth_options[:password]) + elsif @auth_options[:bearer_token_file] + connection.request(:authorization, 'Bearer', -> { File.read(@auth_options[:bearer_token_file]).chomp }) elsif @auth_options[:bearer_token] connection.request(:authorization, 'Bearer', @auth_options[:bearer_token]) end @@ -366,7 +368,6 @@ def create_faraday_client end def faraday_client - refresh_bearer_token_from_file @faraday_client ||= create_faraday_client end @@ -705,7 +706,6 @@ def return_or_yield_to_watcher(watcher, &block) end def http_options(uri) - refresh_bearer_token_from_file options = { basic_auth_user: @auth_options[:username], @@ -730,11 +730,6 @@ def http_options(uri) options.merge(@socket_options) end - def refresh_bearer_token_from_file - return unless (file = @auth_options[:bearer_token_file]) - @auth_options[:bearer_token] = File.read(file).chomp - end - def json_headers { 'Content-Type' => 'application/json' } end diff --git a/lib/kubeclient/version.rb b/lib/kubeclient/version.rb index 1dd4ac8c..80951488 100644 --- a/lib/kubeclient/version.rb +++ b/lib/kubeclient/version.rb @@ -2,5 +2,5 @@ # Kubernetes REST-API Client module Kubeclient - VERSION = '4.9.2' + VERSION = '4.9.3' end From 4f07d3cd8418b0baa870b790c4c51a02481e3cea Mon Sep 17 00:00:00 2001 From: Kjetil Joergensen Date: Tue, 22 Feb 2022 09:37:40 -0800 Subject: [PATCH 2/4] =?UTF-8?q?no=20version=20bump=20=F0=9F=98=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/kubeclient/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/kubeclient/version.rb b/lib/kubeclient/version.rb index 80951488..1dd4ac8c 100644 --- a/lib/kubeclient/version.rb +++ b/lib/kubeclient/version.rb @@ -2,5 +2,5 @@ # Kubernetes REST-API Client module Kubeclient - VERSION = '4.9.3' + VERSION = '4.9.2' end From 9a8dcf72ed9c4f74ccb6617742c320cd5e8f1eee Mon Sep 17 00:00:00 2001 From: Kjetil Joergensen Date: Tue, 22 Feb 2022 15:01:32 -0800 Subject: [PATCH 3/4] unbreak watch_foo --- lib/kubeclient.rb | 11 +++++++++++ lib/kubeclient/watch_stream.rb | 4 ++++ 2 files changed, 15 insertions(+) diff --git a/lib/kubeclient.rb b/lib/kubeclient.rb index 87398e33..32429f98 100644 --- a/lib/kubeclient.rb +++ b/lib/kubeclient.rb @@ -706,10 +706,21 @@ def return_or_yield_to_watcher(watcher, &block) end def http_options(uri) + bearer_token = nil + if @auth_options[:bearer_token_file] + bearer_token_file = @auth_options[:bearer_token_file] + if File.file?(bearer_token_file) and File.readable?(bearer_token_file) + token = File.read(bearer_token_file).chomp + bearer_token = "Bearer #{token}" + end + elsif @auth_options[:bearer_token] + bearer_token = "Bearer #{@auth_options[:bearer_token]}" + end options = { basic_auth_user: @auth_options[:username], basic_auth_password: @auth_options[:password], + authorization: bearer_token, headers: @headers, http_proxy_uri: @http_proxy_uri, http_max_redirects: http_max_redirects diff --git a/lib/kubeclient/watch_stream.rb b/lib/kubeclient/watch_stream.rb index aa43b5c9..75005f9e 100644 --- a/lib/kubeclient/watch_stream.rb +++ b/lib/kubeclient/watch_stream.rb @@ -65,6 +65,10 @@ def build_client ) end + if @http_options[:authorization] + client = client.auth(@http_options[:authorization]) + end + client end From 0eb2acadea6200cd5b87726bca4f4923ed2f21bc Mon Sep 17 00:00:00 2001 From: Kjetil Joergensen Date: Wed, 23 Feb 2022 11:36:39 -0800 Subject: [PATCH 4/4] appease rubocop --- lib/kubeclient.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/kubeclient.rb b/lib/kubeclient.rb index 32429f98..3af9afbd 100644 --- a/lib/kubeclient.rb +++ b/lib/kubeclient.rb @@ -354,7 +354,9 @@ def create_faraday_client if @auth_options[:username] connection.request(:basic_auth, @auth_options[:username], @auth_options[:password]) elsif @auth_options[:bearer_token_file] - connection.request(:authorization, 'Bearer', -> { File.read(@auth_options[:bearer_token_file]).chomp }) + connection.request(:authorization, 'Bearer', lambda do + File.read(@auth_options[:bearer_token_file]).chomp + end) elsif @auth_options[:bearer_token] connection.request(:authorization, 'Bearer', @auth_options[:bearer_token]) end @@ -709,7 +711,7 @@ def http_options(uri) bearer_token = nil if @auth_options[:bearer_token_file] bearer_token_file = @auth_options[:bearer_token_file] - if File.file?(bearer_token_file) and File.readable?(bearer_token_file) + if File.file?(bearer_token_file) && File.readable?(bearer_token_file) token = File.read(bearer_token_file).chomp bearer_token = "Bearer #{token}" end