Secrets are persistent

This commit is contained in:
Roberto Alsina 2024-07-02 15:32:31 -03:00
parent 72c519a23a
commit 02b54ca25d
2 changed files with 20 additions and 2 deletions

View File

@ -27,6 +27,18 @@ module Secrets
end
end
# Load secrets from the disk
def self.load_secrets
Dir.glob(Path.new(SECRET_PATH, "*")).each do |funko_dir|
funko = File.basename(funko_dir)
Dir.glob(Path.new(funko_dir, "*")).each do |secret_file|
name = File.basename(secret_file)
value = File.read(secret_file)
SECRETS["#{funko}-#{name}"] = value
end
end
end
# Gets a secret in form {"name": "funko_name-secret_name", "value": "secret_value"}
post "/secrets/" do |env|
name = env.params.json["name"].as(String)
@ -36,6 +48,10 @@ module Secrets
halt env, status_code: 201, response: "Created"
end
get "/secrets/" do |env|
halt env, status_code: 200, response: SECRETS.keys.to_json
end
# Deletes a secret from the disk and memory
delete "/secrets/:name/" do |env|
name = env.params.url["name"]
@ -44,3 +60,5 @@ module Secrets
halt env, status_code: 204, response: "Deleted"
end
end
Secrets.load_secrets

View File

@ -1,6 +1,6 @@
User nobody
Group nogroup
LogLevel Info
Port 8888
Listen 0.0.0.0
Timeout 600
@ -8,4 +8,4 @@
ReverseOnly Yes
ReverseMagic Yes
ReversePath "/admin/" "http://127.0.0.1:3000/"
ReversePath "/faaso/hello/" "http://hello:3000/"
ReversePath "/faaso/hello/" "http://hello:3000/"