Secrets client side implementation

This commit is contained in:
Roberto Alsina 2024-07-04 10:38:15 -03:00
parent f938653f8e
commit 3bcb427dd7
6 changed files with 17 additions and 12 deletions

View File

@ -66,9 +66,9 @@
<input placeholder="funko name" id="new-secret-funko" name="funko"> <input placeholder="funko name" id="new-secret-funko" name="funko">
<input placeholder="secret name" id="new-secret-name" name="name"> <input placeholder="secret name" id="new-secret-name" name="name">
<input placeholder="secret value" type="password" id="new-secret-password" name="value"> <input placeholder="secret value" type="password" id="new-secret-password" name="value">
<button type="submit" hx-on:htmx:after-request="update_secrets(); hide_new_secret()">CREATE</button> <button type="submit" hx-on:htmx:after-request="hide_new_secret()">CREATE</button>
</form> </form>
<button onclick="hide_new_secret(); close()">CLOSE</button> <button onclick="hide_new_secret(); close();">CLOSE</button>
</dialog> </dialog>
<script> <script>
update_secrets = function() { update_secrets = function() {
@ -76,15 +76,16 @@
} }
show_new_secret = function() { show_new_secret = function() {
document.getElementById('new-secret-funko').value="" document.getElementById('new-secret-funko').value=""
document.getElementById('add-secret').value="" document.getElementById('new-secret-name').value=""
document.getElementById('add-secret').value="" document.getElementById('new-secret-password').value=""
document.getElementById('add-secret').show() document.getElementById('add-secret').show()
} }
hide_new_secret = function() { hide_new_secret = function() {
document.getElementById('new-secret-funko').value="" document.getElementById('new-secret-funko').value=""
document.getElementById('add-secret').value="" document.getElementById('new-secret-name').value=""
document.getElementById('add-secret').value="" document.getElementById('new-secret-password').value=""
document.getElementById('add-secret').close() document.getElementById('add-secret').close()
update_secrets()
} }
</script> </script>
</main> </main>

View File

@ -34,9 +34,10 @@ module Secrets
end end
# Deletes a secret from the disk and memory # Deletes a secret from the disk and memory
delete "/secrets/:name/" do |env| delete "/secrets/:funko/:name/" do |env|
funko = env.params.url["funko"]
name = env.params.url["name"] name = env.params.url["name"]
SECRETS.delete(name) SECRETS.delete("#{funko}-#{name}")
update_secrets update_secrets
halt env, status_code: 204, response: "Deleted" halt env, status_code: 204, response: "Deleted"
end end

View File

@ -1,6 +1,7 @@
require "./commands/build.cr" require "./commands/build.cr"
require "./commands/export.cr" require "./commands/export.cr"
require "./commands/scale.cr" require "./commands/scale.cr"
require "./commands/secret.cr"
require "./commands/status.cr" require "./commands/status.cr"
require "./funko.cr" require "./funko.cr"
require "crest" require "crest"

View File

@ -41,7 +41,7 @@ Usage:
faaso scale FUNKO [SCALE] [-v=<level>] [-l] faaso scale FUNKO [SCALE] [-v=<level>] [-l]
faaso status FUNKO_NAME [-v=<level>] [-l] faaso status FUNKO_NAME [-v=<level>] [-l]
faaso export SOURCE DESTINATION [-v=<level>] faaso export SOURCE DESTINATION [-v=<level>]
faaso secret [-d|-a] FUNKO NAME [-v=<level>] [-l] faaso secret [-d|-a] FUNKO SECRET [-v=<level>] [-l]
Options: Options:
-l --local Run commands locally instead of against a FaaSO server. -l --local Run commands locally instead of against a FaaSO server.
@ -65,4 +65,6 @@ when .fetch("scale", false)
Faaso::Commands::Scale.new.run(ans, ans["FUNKO_NAME"].as(String), ans["SCALE"]) Faaso::Commands::Scale.new.run(ans, ans["FUNKO_NAME"].as(String), ans["SCALE"])
when .fetch("status", false) when .fetch("status", false)
Faaso::Commands::Status.new.run(ans, ans["FUNKO_NAME"].as(String)) Faaso::Commands::Status.new.run(ans, ans["FUNKO_NAME"].as(String))
when .fetch("secret", false)
Faaso::Commands::Secret.new.run(ans, ans["FUNKO"].as(String), ans["SECRET"].as(String))
end end

View File

@ -15,9 +15,9 @@ module Secrets
File.write(Path.new(funko_dir, name), value) File.write(Path.new(funko_dir, name), value)
end end
# Delete secrets not in the hash # Delete secrets not in the hash
Dir.glob(Path.new(SECRET_PATH, "*")).each do |funko_dir| Dir.glob("#{SECRET_PATH}/*").each do |funko_dir|
funko = File.basename(funko_dir) funko = File.basename(funko_dir)
Dir.glob(Path.new(funko_dir, "*")).each do |secret_file| Dir.glob("#{funko_dir}/*").each do |secret_file|
name = File.basename(secret_file) name = File.basename(secret_file)
unless SECRETS.has_key?("#{funko}-#{name}") unless SECRETS.has_key?("#{funko}-#{name}")
File.delete(secret_file) File.delete(secret_file)

View File

@ -4,7 +4,7 @@
<td><%= f["name"] %></td> <td><%= f["name"] %></td>
<td> <td>
<button hx-post="secrets/" hx-on:htmx:after-request="update_secrets()">Change</button> <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> <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"> <img id="spinner-<%= f["name"] %>" src="bars.svg" class="htmx-indicator">
</td> </td>
</tr> </tr>