lib/mihari/web/controllers/artifacts_controller.rb in mihari-3.4.1 vs lib/mihari/web/controllers/artifacts_controller.rb in mihari-3.5.0

- old
+ new

@@ -1,12 +1,37 @@ # frozen_string_literal: true module Mihari module Controllers class ArtifactsController < BaseController + get "/api/artifacts/:id" do + param :id, Integer, required: true + + id = params["id"].to_i + + begin + artifact = Mihari::Artifact.find(id) + + # TODO: improve queries + alert_ids = Mihari::Artifact.where(data: artifact.data).pluck(:alert_id) + tag_ids = Mihari::Tagging.where(alert_id: alert_ids).pluck(:tag_id) + tag_names = Mihari::Tag.where(id: tag_ids).distinct.pluck(:name) + rescue ActiveRecord::RecordNotFound + status 404 + + return json({ message: "ID:#{id} is not found" }) + end + + artifact_json = ArtifactSerializer.new(artifact).as_json + artifact_json[:tags] = tag_names + + json artifact_json + end + delete "/api/artifacts/:id" do - id = params["id"] - id = id.to_i + param :id, Integer, required: true + + id = params["id"].to_i begin alert = Mihari::Artifact.find(id) alert.delete