Sha256: 9b821db84cb43a2c6f1c920b7fce377e8e0d545b479830225f8c2e80620d9eae
Contents?: true
Size: 1.26 KB
Versions: 1
Compression:
Stored size: 1.26 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 || raise("GOOGLE_PROJECT env variable is not set. It's required.") @project_id = ENV['GOOGLE_PROJECT'] # 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, page_size: 1) 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
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
kubes_google-0.1.2 | lib/kubes_google/secrets.rb |