Skip to content

Commit

Permalink
Merge pull request #306 from ninoseki/fix-api-issues
Browse files Browse the repository at this point in the history
Fix api issues
  • Loading branch information
ninoseki authored Aug 15, 2021
2 parents 35c6424 + 63f6cad commit 672e771
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 15 deletions.
8 changes: 4 additions & 4 deletions lib/mihari/models/alert.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ class << self
# @param [String, nil] source
# @param [String, nil] tag_name
# @param [String, nil] title
# @param [String, nil] from_at
# @param [String, nil] to_at
# @param [DateTime, nil] from_at
# @param [DateTime, nil] to_at
# @param [Integer, nil] limit
# @param [Integer, nil] page
#
Expand Down Expand Up @@ -62,8 +62,8 @@ def search(artifact_data: nil, description: nil, source: nil, tag_name: nil, tit
# @param [String, nil] source
# @param [String, nil] tag_name
# @param [String, nil] title
# @param [String, nil] from_at
# @param [String, nil] to_at
# @param [DateTime, nil] from_at
# @param [DateTime, nil] to_at
#
# @return [Integer]
#
Expand Down
7 changes: 3 additions & 4 deletions lib/mihari/web/controllers/alerts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ class AlertsController < BaseController
title = params["title"]

from_at = params["from_at"] || params["fromAt"]
from_at = DateTime.parse(from_at) if from_at
to_at = params["to_at"] || params["toAt"]
to_at = DateTime.parse(to_at) if to_at

alerts = Mihari::Alert.search(
artifact_data: artifact_data,
Expand All @@ -55,8 +53,9 @@ class AlertsController < BaseController
end

delete "/api/alerts/:id" do
id = params["id"]
id = id.to_i
param :id, Integer, required: true

id = params["id"].to_i

begin
alert = Mihari::Alert.find(id)
Expand Down
10 changes: 6 additions & 4 deletions lib/mihari/web/controllers/artifacts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ module Mihari
module Controllers
class ArtifactsController < BaseController
get "/api/artifacts/:id" do
id = params["id"]
id = id.to_s
param :id, Integer, required: true

id = params["id"].to_i

begin
artifact = Mihari::Artifact.find(id)
Expand All @@ -27,8 +28,9 @@ class ArtifactsController < BaseController
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)
Expand Down
5 changes: 3 additions & 2 deletions lib/mihari/web/controllers/ip_address_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ def query(ip)
end

get "/api/ip_addresses/:ip" do
ip = params["ip"]
ip = ip.to_s
param :ip, String, required: true

ip = params["ip"].to_s

begin
data = query(ip)
Expand Down
4 changes: 3 additions & 1 deletion lib/mihari/web/controllers/tags_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ class TagsController < BaseController
end

delete "/api/tags/:name" do
name = params["name"]
param :name, String, required: true

name = params["name"].to_s

begin
Mihari::Tag.where(name: name).destroy_all
Expand Down

0 comments on commit 672e771

Please sign in to comment.