Class: Kamal::Secrets

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

Defined Under Namespace

Modules: Adapters

Instance Method Summary collapse

Constructor Details

#initialize(destination: nil, secrets_path:) ⇒ Secrets



6
7
8
9
10
# File 'lib/kamal/secrets.rb', line 6

def initialize(destination: nil, secrets_path:)
  @destination = destination
  @secrets_path = secrets_path
  @mutex = Mutex.new
end

Instance Method Details

#[](key) ⇒ Object



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

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.present?
    raise Kamal::ConfigurationError, "Secret '#{key}' not found in #{secrets_files.join(", ")}"
  else
    raise Kamal::ConfigurationError, "Secret '#{key}' not found, no secret files (#{secrets_filenames.join(", ")}) provided"
  end
end

#secrets_filesObject



29
30
31
# File 'lib/kamal/secrets.rb', line 29

def secrets_files
  @secrets_files ||= secrets_filenames.select { |f| File.exist?(f) }
end

#to_hObject



25
26
27
# File 'lib/kamal/secrets.rb', line 25

def to_h
  secrets
end