From 2946b849b329579ac3606c4b6a1ac8d96e98331b Mon Sep 17 00:00:00 2001 From: Amolith Date: Mon, 22 Jan 2024 15:05:16 -0500 Subject: [PATCH] Add command to delete snikket instance --- forms/snikket_id.rb | 9 +++++++++ sgx_jmp.rb | 23 +++++++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 forms/snikket_id.rb diff --git a/forms/snikket_id.rb b/forms/snikket_id.rb new file mode 100644 index 0000000000000000000000000000000000000000..5e3f623cffdaf59770c49059d24913892b2f8789 --- /dev/null +++ b/forms/snikket_id.rb @@ -0,0 +1,9 @@ +form! +title "DELETE Snikket Instance" + +instructions "Permanently delete instance by id" + +field( + var: "instance_id", + label: "Instance ID" +) diff --git a/sgx_jmp.rb b/sgx_jmp.rb index b6cda9e3c4dae5b3d503f38f7517d62cf49c1b7c..289335f3259833445f2a5eaa9ac31edb3da99f6d 100644 --- a/sgx_jmp.rb +++ b/sgx_jmp.rb @@ -917,6 +917,29 @@ Command.new( end }.register(self).then(&CommandList.method(:register)) +Command.new( + "delete snikket", + "DELETE Snikket Instance", + list_for: ->(customer: nil, **) { customer&.admin? } +) { + Command.customer.then do |customer| + raise AuthError, "You are not an admin" unless customer&.admin? + + Command.reply { |reply| + reply.allowed_actions = [:next] + reply.command << FormTemplate.render("snikket_id") + }.then { |response| + instance_id = response.form.field("instance_id").value.to_s + IQ_MANAGER.write(Snikket::Delete.new( + nil, CONFIG[:snikket_hosting_api], + instance_id: instance_id + )) + }.then { |iq| + Command.finish(iq.to_s) + } + end +}.register(self).then(&CommandList.method(:register)) + Command.new( "find snikket", "Lookup Snikket Instance",