Sha256: a4030161c18642775be4cfd39d0dd180f46588b44df1ae9c55b713ff23daf59f

Contents?: true

Size: 833 Bytes

Versions: 1

Compression:

Stored size: 833 Bytes

Contents

# frozen_string_literal: true

require 'secrets_loader/version'
require 'json'

module SecretsLoader
  class << self
    attr_accessor :config

    def load
      return unless enable_secrets_loader?

      load_secret_values.each do |key, value|
        if ENV.has_key?(key)
          warn "WARNING: Skipping key #{key.inspect}. Already set in ENV."
        else
          ENV[key] = value.to_s
        end
      end
    end

    def load_secret_values
      secrets_manager = config.client
      secret_string = secrets_manager.get_secret_value(secret_id: config.secret_id).secret_string
      JSON.parse(secret_string)
    end

    def enable_secrets_loader?
      return false if ENV['ENABLE_SECRETS_LOADER'].nil? || ENV['ENABLE_SECRETS_LOADER'].empty?
      !(config.secret_id.nil? || config.secret_id.empty?)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
secrets_loader-0.1.0 lib/secrets_loader.rb