Sha256: 8dff5b966090bed664b1ea97bf53f7674e324b6970a52fe6c0bb74b1eec2852a

Contents?: true

Size: 1.29 KB

Versions: 13

Compression:

Stored size: 1.29 KB

Contents

require "google-cloud-secret_manager"

module KubesGoogle
  class Secrets
    def initialize(upcase: false, base64: false, prefix: nil)
      @upcase, @base64 = upcase, base64
      @prefix = ENV['GCP_SECRET_PREFIX'] || prefix
      @project_id = ENV['GOOGLE_PROJECT'] || raise("GOOGLE_PROJECT env variable is not set. It's required.")
      # IE: prefix: projects/686010496118/secrets/demo-dev-
    end

    def call
      client = Google::Cloud::SecretManager.secret_manager_service

      parent = "projects/#{@project_id}"
      resp = client.list_secrets(parent: parent) # note: page_size doesnt seem to get respected
      resp.each do |secret|
        next unless secret.name.include?(@prefix)
        version = client.access_secret_version(name: "#{secret.name}/versions/latest")

        # projects/686010496118/secrets/demo-dev-db_pass => DB_PASS
        key = secret.name.sub(@prefix,'')
        key = key.upcase if @upcase
        value = version.payload.data
        # strict_encode64 to avoid newlines https://stackoverflow.com/questions/2620975/strange-n-in-base64-encoded-string-in-ruby
        value = Base64.strict_encode64(value).strip if @base64
        self.class.data[key] = value
      end
    end

    def data
      self.class.data
    end

    class_attribute :data
    self.data = {}
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
kubes_google-0.3.11 lib/kubes_google/secrets.rb
kubes_google-0.3.10 lib/kubes_google/secrets.rb
kubes_google-0.3.9 lib/kubes_google/secrets.rb
kubes_google-0.3.8 lib/kubes_google/secrets.rb
kubes_google-0.3.7 lib/kubes_google/secrets.rb
kubes_google-0.3.6 lib/kubes_google/secrets.rb
kubes_google-0.3.5 lib/kubes_google/secrets.rb
kubes_google-0.3.4 lib/kubes_google/secrets.rb
kubes_google-0.3.3 lib/kubes_google/secrets.rb
kubes_google-0.3.2 lib/kubes_google/secrets.rb
kubes_google-0.3.1 lib/kubes_google/secrets.rb
kubes_google-0.3.0 lib/kubes_google/secrets.rb
kubes_google-0.2.0 lib/kubes_google/secrets.rb