Beginnings of secret admin w/dialog

This commit is contained in:
2024-07-03 20:54:19 -03:00
parent 1f02e0af11
commit 6d1651f3ec
9 changed files with 152 additions and 16 deletions

View File

@ -39,7 +39,7 @@ module Proxy
ReverseOnly Yes
ReverseMagic Yes
ReversePath "/admin/" "http://127.0.0.1:3000/"
) + funkos.map { |funko| %(ReversePath "/faaso/#{funko}/" "http://#{funko}:3000/") }.join("\n")
) + funkos.map { |funko| %(ReversePath "/faaso/#{funko.split("-")[0]}/" "http://#{funko}:3000/") }.join("\n")
if @@current_config != config
File.open("tinyproxy.conf", "w") do |file|

View File

@ -7,15 +7,30 @@ module Secrets
# Gets a secret in form {"name": "funko_name-secret_name", "value": "secret_value"}
post "/secrets/" do |env|
name = env.params.json["name"].as(String)
value = env.params.json["value"].as(String)
SECRETS[name] = value
funko = env.params.body["funko"].as(String)
name = env.params.body["name"].as(String)
value = env.params.body["value"].as(String)
if funko.empty? || name.empty? || value.empty?
halt env, status_code: 400, response: "Bad request"
end
SECRETS["#{funko}-#{name}"] = value
Secrets.update_secrets
halt env, status_code: 201, response: "Created"
end
get "/secrets/" do |env|
halt env, status_code: 200, response: SECRETS.keys.to_json
result = [] of Hash(String, String)
SECRETS.each { |k, _|
result << {
"funko" => k.split("-")[0],
"name" => k.split("-", 2)[1],
}
}
if env.params.query.fetch("format", "json") == "html"
render "src/views/secrets.ecr"
else
result.to_json
end
end
# Deletes a secret from the disk and memory

View File

@ -96,10 +96,11 @@ module Funko
Log.info { "Scaling #{name} from #{current_scale} to #{new_scale}" }
if new_scale > current_scale
Log.info { "Adding instance" }
(current_scale...new_scale).each {
Log.info { "Adding instance" }
id = create_container
start(id)
sleep 0.1.seconds
}
else
containers.select { |container| container.@state == "running" }.sort! { |i, j|
@ -109,6 +110,7 @@ module Funko
docker_api.containers.stop(container.@id)
current_scale -= 1
break if current_scale == new_scale
sleep 0.1.seconds
}
end

View File

@ -17,7 +17,7 @@
<button hx-get="funkos/<%= f["name"] %>/restart" hx-on:htmx:after-request="update_funkos()">Restart</button>
<%- end -%>
<%- end -%>
<img id="spinner-<%= f["name"] %>" src="https://htmx.org/img/bars.svg" class="htmx-indicator">
<img id="spinner-<%= f["name"] %>" src="bars.svg" class="htmx-indicator">
</td>
</tr>
<%- end -%>

11
src/views/secrets.ecr Normal file
View File

@ -0,0 +1,11 @@
<%- result.each do |f| -%>
<tr hx-indicator="#spinner-<%= f["name"] %>">
<td><%= f["funko"] %></td>
<td><%= f["name"] %></td>
<td>
<button hx-post="secrets/" hx-on:htmx:after-request="update_secrets()">Change</button>
<button hx-delete="secrets/<%= f["funko"] %>-<%= f["name"] %>/" hx-on:htmx:after-request="update_secrets()">Delete</button>
<img id="spinner-<%= f["name"] %>" src="bars.svg" class="htmx-indicator">
</td>
</tr>
<%- end -%>