Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/gems/kubeclient/lib/kubeclient/gcp_command_credentials.rb')
-rw-r--r--vendor/gems/kubeclient/lib/kubeclient/gcp_command_credentials.rb31
1 files changed, 31 insertions, 0 deletions
diff --git a/vendor/gems/kubeclient/lib/kubeclient/gcp_command_credentials.rb b/vendor/gems/kubeclient/lib/kubeclient/gcp_command_credentials.rb
new file mode 100644
index 00000000000..9c68c1a2847
--- /dev/null
+++ b/vendor/gems/kubeclient/lib/kubeclient/gcp_command_credentials.rb
@@ -0,0 +1,31 @@
+# frozen_string_literal: true
+
+module Kubeclient
+ # Generates a bearer token for Google Cloud Platform.
+ class GCPCommandCredentials
+ class << self
+ def token(config)
+ require 'open3'
+ require 'shellwords'
+ require 'json'
+ require 'jsonpath'
+
+ cmd = config['cmd-path']
+ args = config['cmd-args']
+ token_key = config['token-key']
+
+ out, err, st = Open3.capture3(cmd, *args.split(' '))
+
+ raise "exec command failed: #{err}" unless st.success?
+
+ extract_token(out, token_key)
+ end
+
+ private
+
+ def extract_token(output, token_key)
+ JsonPath.on(output, token_key.gsub(/^{|}$/, '')).first
+ end
+ end
+ end
+end