Sha256: 18b50b5abf428fd6f1cc17052b5cb56001f23000a1107918e4096547ee8e2964
Contents?: true
Size: 1.2 KB
Versions: 1
Compression:
Stored size: 1.2 KB
Contents
# 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 param :id, Integer, required: true id = params["id"].to_i begin alert = Mihari::Artifact.find(id) alert.delete status 204 body "" rescue ActiveRecord::RecordNotFound status 404 json({ message: "ID:#{id} is not found" }) end end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
mihari-3.5.0 | lib/mihari/web/controllers/artifacts_controller.rb |