Module: SamsonSecretPuller

Extended by:
Forwardable
Defined in:
lib/samson_secret_puller.rb

Constant Summary collapse

FOLDER =
'/secrets'.freeze
ENV =

store a copy since we might replace ENV on Object

ENV

Class Method Summary collapse

Class Method Details

.[]=(key, value) ⇒ Object



23
24
25
26
27
28
29
30
31
# File 'lib/samson_secret_puller.rb', line 23

def []=(key, value)
  if value.nil?
    delete key
  elsif secrets && @secret_keys.include?(key)
    secrets[key] = value
  else
    ENV[key] = secrets[key] = value
  end
end

.delete(key) ⇒ Object



33
34
35
36
# File 'lib/samson_secret_puller.rb', line 33

def delete(key)
  secrets.delete(key)
  ENV.delete(key)
end

.replace(other) ⇒ Object



38
39
40
# File 'lib/samson_secret_puller.rb', line 38

def replace(other)
  (secrets.keys + other.keys).uniq.each { |k| self[k] = other[k] }
end

.replace_ENV!Object

When we run in kubernetes we need to read secrets from ENV and secret storage but other parts of the apps or gems do not need to know about this



44
45
46
47
48
49
50
# File 'lib/samson_secret_puller.rb', line 44

def replace_ENV! # rubocop:disable Style/MethodName
  old = $VERBOSE
  $VERBOSE = nil
  Object.const_set(:ENV, self)
ensure
  $VERBOSE = old
end

.to_hObject Also known as: to_hash, dup



17
18
19
# File 'lib/samson_secret_puller.rb', line 17

def to_h
  secrets.dup
end