Add command to delete snikket instance

Amolith created

Change summary

forms/snikket_id.rb |  9 +++++++++
sgx_jmp.rb          | 23 +++++++++++++++++++++++
2 files changed, 32 insertions(+)

Detailed changes

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"
+)

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",