Class: Kamal::Secrets

Inherits:
Object
  • Object
show all
Defined in:
lib/kamal/secrets.rb

Defined Under Namespace

Modules: Adapters

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(destination: nil) ⇒ Secrets

Returns a new instance of Secrets.



8
9
10
11
12
# File 'lib/kamal/secrets.rb', line 8

def initialize(destination: nil)
  @secrets_files = \
    [ ".kamal/secrets-common", ".kamal/secrets#{(".#{destination}" if destination)}" ].select { |f| File.exist?(f) }
  @mutex = Mutex.new
end

Instance Attribute Details

#secrets_filesObject (readonly)

Returns the value of attribute secrets_files.



4
5
6
# File 'lib/kamal/secrets.rb', line 4

def secrets_files
  @secrets_files
end

Instance Method Details

#[](key) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/kamal/secrets.rb', line 14

def [](key)
  # Fetching secrets may ask the user for input, so ensure only one thread does that
  @mutex.synchronize do
    secrets.fetch(key)
  end
rescue KeyError
  if secrets_files
    raise Kamal::ConfigurationError, "Secret '#{key}' not found in #{secrets_files.join(", ")}"
  else
    raise Kamal::ConfigurationError, "Secret '#{key}' not found, no secret files provided"
  end
end

#to_hObject



27
28
29
# File 'lib/kamal/secrets.rb', line 27

def to_h
  secrets
end