Class: Kamal::Secrets::Dotenv::InlineCommandSubstitution
- Inherits:
-
Object
- Object
- Kamal::Secrets::Dotenv::InlineCommandSubstitution
- Defined in:
- lib/kamal/secrets/dotenv/inline_command_substitution.rb
Class Method Summary collapse
- .call(value, _env, overwrite: false) ⇒ Object
- .inline_secrets_command(command) ⇒ Object
- .install! ⇒ Object
Class Method Details
.call(value, _env, overwrite: false) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/kamal/secrets/dotenv/inline_command_substitution.rb', line 7 def call(value, _env, overwrite: false) # Process interpolated shell commands value.gsub(Dotenv::Substitutions::Command.singleton_class::INTERPOLATED_SHELL_COMMAND) do |*| # Eliminate opening and closing parentheses command = $LAST_MATCH_INFO[:cmd][1..-2] if $LAST_MATCH_INFO[:backslash] # Command is escaped, don't replace it. $LAST_MATCH_INFO[0][1..] else if command =~ /\A\s*kamal\s*secrets\s+/ # Inline the command inline_secrets_command(command) else # Execute the command and return the value `#{command}`.chomp end end end end |
.inline_secrets_command(command) ⇒ Object
28 29 30 |
# File 'lib/kamal/secrets/dotenv/inline_command_substitution.rb', line 28 def inline_secrets_command(command) Kamal::Cli::Main.start(command.shellsplit[1..] + [ "--inline" ]).chomp end |
.install! ⇒ Object
3 4 5 |
# File 'lib/kamal/secrets/dotenv/inline_command_substitution.rb', line 3 def install! ::Dotenv::Parser.substitutions.map! { |sub| sub == ::Dotenv::Substitutions::Command ? self : sub } end |