Sha256: 22cfc0e9dea583e2e54aeb91cdb411f7a18b571ab6b78ab7ff946ee2e9b62cec

Contents?: true

Size: 1.31 KB

Versions: 2

Compression:

Stored size: 1.31 KB

Contents

class KubesGoogle::Secrets::Fetcher
  class Sdk < Base
    include KubesGoogle::Services

    def fetch(short_name, version="latest")
      value = fetch_value(short_name, version)
      value = Base64.strict_encode64(value).strip if base64?
      value
    end

    def fetch_value(short_name, version="latest")
      name = "projects/#{project_number}/secrets/#{short_name}/versions/#{version}"
      version = secret_manager_service.access_secret_version(name: name)
      version.payload.data
    rescue Google::Cloud::NotFoundError => e
      logger.info "WARN: secret #{name} not found".color(:yellow)
      logger.info e.message
      "NOT FOUND #{name}" # simple string so Kubernetes YAML is valid
    end

    # TODO: Get the project from the list project api instead. Unsure where the docs are for this.
    # If someone knows, let me know.
    # Right now grabbing the first secret to then be able to get the google project number
    @@project_number = nil
    def project_number
      return @@project_number if @@project_number

      parent = "projects/#{@project_id}"
      resp = secret_manager_service.list_secrets(parent: parent) # note: page_size doesnt seem to get respected
      name = resp.first.name # IE: projects/686010496118/secrets/demo-dev-db_host
      @@project_number = name.split('/')[1]
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
kubes_google-0.3.4 lib/kubes_google/secrets/fetcher/sdk.rb
kubes_google-0.3.3 lib/kubes_google/secrets/fetcher/sdk.rb