File: gcp_command_credentials.rb

package info (click to toggle)
ruby-kubeclient 4.13.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,128 kB
  • sloc: ruby: 4,229; makefile: 6
file content (31 lines) | stat: -rw-r--r-- 713 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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