Sha256: 9c85e4367930cdf6358ede7da7f1ed5d7c9a77dd07b80bac6a41cb305f5c75d7

Contents?: true

Size: 891 Bytes

Versions: 23

Compression:

Stored size: 891 Bytes

Contents

class ComplexConfig::KeySource
  def initialize(pathname: nil, env_var: nil, var: nil, master_key_pathname: nil)
    settings = [ pathname, env_var, var, master_key_pathname ].compact.size
    if settings > 1
      raise ArgumentError, 'only one setting at most possible'
    end
    pathname and pathname = pathname.to_s
    master_key_pathname and master_key_pathname = master_key_pathname.to_s
    @pathname, @env_var, @var, @master_key_pathname =
      pathname, env_var, var, master_key_pathname
  end

  def master_key?
    !!@master_key_pathname
  end

  def key
    if @var
      @var.ask_and_send(:chomp)
    elsif @env_var
      ENV[@env_var].ask_and_send(:chomp)
    elsif master_key?
      IO.binread(@master_key_pathname).chomp
    elsif @pathname
      IO.binread(@pathname + '.key').chomp
    end
  rescue Errno::ENOENT
  end

  def key_bytes
    [ key ].pack('H*')
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
complex_config-0.22.1 lib/complex_config/key_source.rb
complex_config-0.22.0 lib/complex_config/key_source.rb
complex_config-0.21.2 lib/complex_config/key_source.rb
complex_config-0.21.1 lib/complex_config/key_source.rb
complex_config-0.21.0 lib/complex_config/key_source.rb
complex_config-0.20.0 lib/complex_config/key_source.rb
complex_config-0.19.4 lib/complex_config/key_source.rb
complex_config-0.19.3 lib/complex_config/key_source.rb
complex_config-0.19.2 lib/complex_config/key_source.rb
complex_config-0.19.1 lib/complex_config/key_source.rb
complex_config-0.19.0 lib/complex_config/key_source.rb
complex_config-0.18.2 lib/complex_config/key_source.rb
complex_config-0.18.1 lib/complex_config/key_source.rb
complex_config-0.18.0 lib/complex_config/key_source.rb
complex_config-0.17.1 lib/complex_config/key_source.rb
complex_config-0.17.0 lib/complex_config/key_source.rb
complex_config-0.16.0 lib/complex_config/key_source.rb
complex_config-0.15.1 lib/complex_config/key_source.rb
complex_config-0.15.0 lib/complex_config/key_source.rb
complex_config-0.14.1 lib/complex_config/key_source.rb