-
Notifications
You must be signed in to change notification settings - Fork 502
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
43 changed files
with
391 additions
and
529 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,34 @@ | ||
class Kamal::Configuration::Env | ||
include Kamal::Configuration::Validation | ||
|
||
attr_reader :secrets_keys, :clear, :secrets_file, :context | ||
attr_reader :context, :secrets | ||
attr_reader :clear, :secret_keys | ||
delegate :argumentize, to: Kamal::Utils | ||
|
||
def initialize(config:, secrets_file: nil, context: "env") | ||
def initialize(config:, secrets:, context: "env") | ||
@clear = config.fetch("clear", config.key?("secret") || config.key?("tags") ? {} : config) | ||
@secrets_keys = config.fetch("secret", []) | ||
@secrets_file = secrets_file | ||
@secrets = secrets | ||
@secret_keys = config.fetch("secret", []) | ||
@context = context | ||
validate! config, context: context, with: Kamal::Configuration::Validator::Env | ||
end | ||
|
||
def args | ||
[ "--env-file", secrets_file, *argumentize("--env", clear) ] | ||
end | ||
|
||
def secrets_io | ||
StringIO.new(Kamal::EnvFile.new(secrets).to_s) | ||
end | ||
|
||
def secrets | ||
@secrets ||= secrets_keys.to_h { |key| [ key, ENV.fetch(key) ] } | ||
end | ||
|
||
def secrets_directory | ||
File.dirname(secrets_file) | ||
[ *clear_args, *secret_args ] | ||
end | ||
|
||
def merge(other) | ||
self.class.new \ | ||
config: { "clear" => clear.merge(other.clear), "secret" => secrets_keys | other.secrets_keys }, | ||
secrets_file: secrets_file || other.secrets_file | ||
config: { "clear" => clear.merge(other.clear), "secret" => secret_keys | other.secret_keys }, | ||
secrets: secrets | ||
end | ||
|
||
private | ||
def clear_args | ||
argumentize("--env", clear) | ||
end | ||
|
||
def secret_args | ||
argumentize("--env", secret_keys.to_h { |key| [ key, secrets[key] ] }, sensitive: true) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,13 @@ | ||
class Kamal::Configuration::Env::Tag | ||
attr_reader :name, :config | ||
attr_reader :name, :config, :secrets | ||
|
||
def initialize(name, config:) | ||
def initialize(name, config:, secrets:) | ||
@name = name | ||
@config = config | ||
@secrets = secrets | ||
end | ||
|
||
def env | ||
Kamal::Configuration::Env.new(config: config) | ||
Kamal::Configuration::Env.new(config: config, secrets: secrets) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
class Kamal::Configuration::Secrets | ||
attr_reader :secret_files | ||
|
||
def initialize(destination: nil) | ||
@secret_files = \ | ||
(destination ? [ ".kamal/secrets", ".kamal/secrets.#{destination}" ] : [ ".kamal/secrets" ]) | ||
.select { |file| File.exist?(file) } | ||
end | ||
|
||
def [](key) | ||
@secrets ||= load | ||
@secrets.fetch(key) | ||
rescue KeyError | ||
if secret_files.any? | ||
raise Kamal::ConfigurationError, "Secret '#{key}' not found in #{secret_files.join(', ')}" | ||
else | ||
raise Kamal::ConfigurationError, "Secret '#{key}' not found, no secret files provided" | ||
end | ||
end | ||
|
||
private | ||
def load | ||
secret_files.any? ? Dotenv.parse(*secret_files) : {} | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.