Sha256: 0b8f07a809442c3ba88a007ceb57ec0655ed68ed004e0dd07b22e0d20a99f9ee

Contents?: true

Size: 807 Bytes

Versions: 4

Compression:

Stored size: 807 Bytes

Contents

module SecretsCli
  class Configuration
    attr_reader :environment, :verbose

    def initialize(options)
      @environment = (options.environment || ENV['RAILS_ENV'] || ENV['NODE_ENV'] || 'development').to_sym
      @verbose = options.verbose
    end

    def config
      @config ||=
        Psych.load(File.read(SECRETS_CONFIG_FILE), symbolize_names: true)
    end

    def secrets_file
      fetch(:secrets_file)
    end

    def secrets_storage_key
      fetch(:secrets_storage_key)
    end

    def vault_addr
      fetch(:vault_addr) || ENV['VAULT_ADDR']
    end

    def self.write(config)
      File.open(SECRETS_CONFIG_FILE, 'w') { |file| file.write(config.to_yaml) }
    end

    private

    def fetch(var)
      config.fetch(environment, {}).fetch(var, nil) || config[var]
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
secrets_cli-1.12.3 lib/secrets_cli/configuration.rb
secrets_cli-1.12.2 lib/secrets_cli/configuration.rb
secrets_cli-1.12.1 lib/secrets_cli/configuration.rb
secrets_cli-1.11.0 lib/secrets_cli/configuration.rb