From 83b66155038fe01ec25e528c24a0c777e088c704 Mon Sep 17 00:00:00 2001 From: Roberto Alsina Date: Thu, 4 Jul 2024 15:20:07 -0300 Subject: [PATCH] Forgotten file --- src/commands/secret.cr | 49 +++++++++++++++++++++++++++++++++++++++++ src/daemon/proxyconf.cr | 1 + 2 files changed, 50 insertions(+) create mode 100644 src/commands/secret.cr diff --git a/src/commands/secret.cr b/src/commands/secret.cr new file mode 100644 index 0000000..9015ab5 --- /dev/null +++ b/src/commands/secret.cr @@ -0,0 +1,49 @@ +module Faaso + module Commands + struct Secret + def local(options, funko, name, secret) + if options["--add"] + dst_dir = "secrets/#{funko}" + Dir.mkdir_p(dst_dir) unless Dir.exists?(dst_dir) + File.write("#{dst_dir}/#{name}", secret) + elsif options["--delete"] + File.delete("secrets/#{funko}/#{name}") + end + end + + def remote(options, funko, name, secret) + if options["--add"] + Crest.post( + "#{FAASO_SERVER}secrets/", + { + "funko" => funko, + "name" => name, + "value" => secret, + }, user: "admin", password: "admin") + Log.info { "Secret created" } + elsif options["--delete"] + Crest.delete( + "#{FAASO_SERVER}secrets/#{funko}/#{name}", + user: "admin", password: "admin") + end + rescue ex : Crest::RequestFailed + Log.error { "Error #{ex.response.status_code}" } + exit 1 + end + + def run(options, funko, name) + if options["--add"] + Log.info { "Enter the secret, end with Ctrl-D" } if STDIN.tty? + secret = STDIN.gets_to_end + else + secret = "" + end + + if options["--local"] + return local(options, funko, name, secret) + end + remote(options, funko, name, secret) + end + end + end +end diff --git a/src/daemon/proxyconf.cr b/src/daemon/proxyconf.cr index 39cf8b0..01e14c2 100644 --- a/src/daemon/proxyconf.cr +++ b/src/daemon/proxyconf.cr @@ -48,6 +48,7 @@ localhost:8888 { reverse_proxy /* http://#{funko}:3000 } ) }.join("\n") + "}" + # FIXME that 👆🏼 is not a functional load balancing config if scale > 1 if @@current_config != config File.open("Caddyfile", "w") do |file|