mihari 5.7.0 → 5.7.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +1 -1
- data/lib/mihari/actor.rb +10 -4
- data/lib/mihari/commands/alert.rb +6 -4
- data/lib/mihari/commands/search.rb +10 -29
- data/lib/mihari/enrichers/ipinfo.rb +1 -1
- data/lib/mihari/entities/tag.rb +1 -0
- data/lib/mihari/rule.rb +14 -0
- data/lib/mihari/service.rb +12 -2
- data/lib/mihari/services/alert_builder.rb +81 -8
- data/lib/mihari/services/alert_runner.rb +3 -10
- data/lib/mihari/services/rule_builder.rb +8 -10
- data/lib/mihari/services/rule_runner.rb +2 -25
- data/lib/mihari/structs/binaryedge.rb +9 -0
- data/lib/mihari/structs/censys.rb +0 -14
- data/lib/mihari/structs/fofa.rb +3 -0
- data/lib/mihari/structs/google_public_dns.rb +0 -4
- data/lib/mihari/structs/greynoise.rb +0 -6
- data/lib/mihari/structs/hunterhow.rb +0 -6
- data/lib/mihari/structs/ipinfo.rb +0 -2
- data/lib/mihari/structs/onyphe.rb +0 -4
- data/lib/mihari/structs/shodan.rb +0 -2
- data/lib/mihari/structs/urlscan.rb +0 -6
- data/lib/mihari/structs/virustotal_intelligence.rb +0 -8
- data/lib/mihari/version.rb +1 -1
- data/lib/mihari/web/app.rb +20 -17
- data/lib/mihari/web/endpoints/alerts.rb +75 -38
- data/lib/mihari/web/endpoints/artifacts.rb +60 -53
- data/lib/mihari/web/endpoints/ip_addresses.rb +19 -4
- data/lib/mihari/web/endpoints/rules.rb +132 -88
- data/lib/mihari/web/endpoints/tags.rb +15 -13
- data/lib/mihari/web/public/assets/{index-821134e2.js → index-07fafab5.js} +4 -3
- data/lib/mihari/web/public/index.html +1 -1
- data/lib/mihari.rb +0 -1
- data/mihari.gemspec +1 -1
- data/mkdocs.yml +1 -0
- metadata +3 -130
- data/docs/alternatives.md +0 -5
- data/docs/analyzers/binaryedge.md +0 -26
- data/docs/analyzers/censys.md +0 -31
- data/docs/analyzers/circl.md +0 -37
- data/docs/analyzers/crtsh.md +0 -26
- data/docs/analyzers/dnstwister.md +0 -25
- data/docs/analyzers/feed.md +0 -73
- data/docs/analyzers/fofa.md +0 -31
- data/docs/analyzers/greynoise.md +0 -26
- data/docs/analyzers/hunterhow.md +0 -33
- data/docs/analyzers/index.md +0 -104
- data/docs/analyzers/onyphe.md +0 -26
- data/docs/analyzers/otx.md +0 -28
- data/docs/analyzers/passivetotal.md +0 -52
- data/docs/analyzers/pulsedive.md +0 -28
- data/docs/analyzers/securitytrails.md +0 -41
- data/docs/analyzers/shodan.md +0 -26
- data/docs/analyzers/urlscan.md +0 -28
- data/docs/analyzers/virustotal.md +0 -43
- data/docs/analyzers/virustotal_intelligence.md +0 -33
- data/docs/analyzers/zoomeye.md +0 -38
- data/docs/configuration.md +0 -35
- data/docs/emitters/database.md +0 -22
- data/docs/emitters/hive.md +0 -26
- data/docs/emitters/index.md +0 -36
- data/docs/emitters/misp.md +0 -21
- data/docs/emitters/slack.md +0 -21
- data/docs/emitters/webhook.md +0 -63
- data/docs/enrichers/google_public_dns.md +0 -19
- data/docs/enrichers/index.md +0 -35
- data/docs/enrichers/ipinfo.md +0 -26
- data/docs/enrichers/shodan.md +0 -22
- data/docs/enrichers/whois.md +0 -17
- data/docs/github_actions.md +0 -43
- data/docs/index.md +0 -11
- data/docs/installation.md +0 -31
- data/docs/requirements.md +0 -13
- data/docs/rule.md +0 -168
- data/docs/tags.md +0 -3
- data/docs/usage.md +0 -103
- data/frontend/.eslintrc.cjs +0 -22
- data/frontend/.gitignore +0 -31
- data/frontend/.prettierrc.json +0 -8
- data/frontend/README.md +0 -3
- data/frontend/env.d.ts +0 -5
- data/frontend/index.html +0 -21
- data/frontend/package-lock.json +0 -7219
- data/frontend/package.json +0 -67
- data/frontend/public/favicon.ico +0 -0
- data/frontend/scripts/swagger_doc_to_yaml.rb +0 -23
- data/frontend/src/App.vue +0 -27
- data/frontend/src/ace-config.ts +0 -6
- data/frontend/src/api-helper.ts +0 -111
- data/frontend/src/api.ts +0 -105
- data/frontend/src/components/ErrorMessage.vue +0 -31
- data/frontend/src/components/Loading.vue +0 -15
- data/frontend/src/components/Navbar.vue +0 -42
- data/frontend/src/components/Pagination.vue +0 -119
- data/frontend/src/components/alert/Alert.vue +0 -87
- data/frontend/src/components/alert/Alerts.vue +0 -63
- data/frontend/src/components/alert/AlertsWithPagination.vue +0 -90
- data/frontend/src/components/alert/AlertsWrapper.vue +0 -128
- data/frontend/src/components/alert/Form.vue +0 -169
- data/frontend/src/components/artifact/AS.vue +0 -23
- data/frontend/src/components/artifact/Artifact.vue +0 -287
- data/frontend/src/components/artifact/ArtifactTag.vue +0 -64
- data/frontend/src/components/artifact/ArtifactTags.vue +0 -29
- data/frontend/src/components/artifact/ArtifactWrapper.vue +0 -57
- data/frontend/src/components/artifact/CPEs.vue +0 -23
- data/frontend/src/components/artifact/DnsRecords.vue +0 -32
- data/frontend/src/components/artifact/Ports.vue +0 -23
- data/frontend/src/components/artifact/ReverseDnsNames.vue +0 -23
- data/frontend/src/components/artifact/Tags.vue +0 -29
- data/frontend/src/components/artifact/WhoisRecord.vue +0 -44
- data/frontend/src/components/config/Configs.vue +0 -65
- data/frontend/src/components/config/ConfigsWrapper.vue +0 -32
- data/frontend/src/components/link/Link.vue +0 -32
- data/frontend/src/components/link/Links.vue +0 -42
- data/frontend/src/components/rule/EditRule.vue +0 -72
- data/frontend/src/components/rule/EditRuleWrapper.vue +0 -48
- data/frontend/src/components/rule/Form.vue +0 -158
- data/frontend/src/components/rule/InputForm.vue +0 -45
- data/frontend/src/components/rule/NewRule.vue +0 -57
- data/frontend/src/components/rule/Rule.vue +0 -100
- data/frontend/src/components/rule/RuleWrapper.vue +0 -53
- data/frontend/src/components/rule/Rules.vue +0 -84
- data/frontend/src/components/rule/RulesWrapper.vue +0 -121
- data/frontend/src/components/rule/YAML.vue +0 -37
- data/frontend/src/components/tag/Tag.vue +0 -65
- data/frontend/src/components/tag/Tags.vue +0 -37
- data/frontend/src/countries.ts +0 -350
- data/frontend/src/index.ts +0 -20
- data/frontend/src/links/anyrun.ts +0 -19
- data/frontend/src/links/base.ts +0 -14
- data/frontend/src/links/censys.ts +0 -20
- data/frontend/src/links/crtsh.ts +0 -20
- data/frontend/src/links/dnslytics.ts +0 -38
- data/frontend/src/links/greynoise.ts +0 -20
- data/frontend/src/links/index.ts +0 -40
- data/frontend/src/links/intezer.ts +0 -20
- data/frontend/src/links/otx.ts +0 -33
- data/frontend/src/links/securitytrails.ts +0 -38
- data/frontend/src/links/shodan.ts +0 -20
- data/frontend/src/links/urlscan.ts +0 -50
- data/frontend/src/links/virustotal.ts +0 -72
- data/frontend/src/main.ts +0 -41
- data/frontend/src/router/index.ts +0 -57
- data/frontend/src/rule.ts +0 -14
- data/frontend/src/shims-vue.d.ts +0 -6
- data/frontend/src/swagger.yaml +0 -771
- data/frontend/src/types.ts +0 -188
- data/frontend/src/utils.ts +0 -54
- data/frontend/src/views/Alerts.vue +0 -20
- data/frontend/src/views/Artifact.vue +0 -39
- data/frontend/src/views/Configs.vue +0 -20
- data/frontend/src/views/EditRule.vue +0 -39
- data/frontend/src/views/NewRule.vue +0 -26
- data/frontend/src/views/Rule.vue +0 -39
- data/frontend/src/views/Rules.vue +0 -20
- data/frontend/tests/utils.spec.ts +0 -9
- data/frontend/tsconfig.app.json +0 -21
- data/frontend/tsconfig.json +0 -14
- data/frontend/tsconfig.node.json +0 -13
- data/frontend/tsconfig.vitest.json +0 -12
- data/frontend/vite.config.ts +0 -24
- data/frontend/vitest.config.ts +0 -21
- data/lib/mihari/services/alert_proxy.rb +0 -97
data/lib/mihari/web/app.rb
CHANGED
@@ -22,6 +22,12 @@ module Mihari
|
|
22
22
|
# Rack + Grape based web app
|
23
23
|
#
|
24
24
|
class App
|
25
|
+
# @return [Array<String>]
|
26
|
+
attr_reader :filenames
|
27
|
+
|
28
|
+
# @return [Rack::Static]
|
29
|
+
attr_reader :rack_static
|
30
|
+
|
25
31
|
def initialize
|
26
32
|
@filenames = ["", ".html", "index.html", "/index.html"]
|
27
33
|
@rack_static = Rack::Static.new(
|
@@ -31,6 +37,20 @@ module Mihari
|
|
31
37
|
)
|
32
38
|
end
|
33
39
|
|
40
|
+
def call(env)
|
41
|
+
status, headers, body = API.call(env)
|
42
|
+
return [status, headers, body] unless headers["X-Cascade"] == "pass"
|
43
|
+
|
44
|
+
# Check if the App wants us to pass the response along to others
|
45
|
+
request_path = env["PATH_INFO"]
|
46
|
+
filenames.each do |path|
|
47
|
+
static_status, static_headers, static_body = rack_static.call(env.merge("PATH_INFO" => request_path + path))
|
48
|
+
return [static_status, static_headers, static_body] if static_status != 404
|
49
|
+
end
|
50
|
+
|
51
|
+
[status, headers, body]
|
52
|
+
end
|
53
|
+
|
34
54
|
class << self
|
35
55
|
def instance
|
36
56
|
@instance ||= Rack::Builder.new do
|
@@ -71,23 +91,6 @@ module Mihari
|
|
71
91
|
end
|
72
92
|
end
|
73
93
|
end
|
74
|
-
|
75
|
-
def call(env)
|
76
|
-
# api
|
77
|
-
api_response = API.call(env)
|
78
|
-
|
79
|
-
# Check if the App wants us to pass the response along to others
|
80
|
-
if api_response[1]["X-Cascade"] == "pass"
|
81
|
-
# static files
|
82
|
-
request_path = env["PATH_INFO"]
|
83
|
-
@filenames.each do |path|
|
84
|
-
response = @rack_static.call(env.merge("PATH_INFO" => request_path + path))
|
85
|
-
return response if response[0] != 404
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
api_response
|
90
|
-
end
|
91
94
|
end
|
92
95
|
end
|
93
96
|
end
|
@@ -7,6 +7,72 @@ module Mihari
|
|
7
7
|
# Alert API endpoint
|
8
8
|
#
|
9
9
|
class Alerts < Grape::API
|
10
|
+
class AlertSearcher < Mihari::Service
|
11
|
+
class ResultValue
|
12
|
+
# @return [Array<Mihari::Models::Alert>]
|
13
|
+
attr_reader :alerts
|
14
|
+
|
15
|
+
# @return [Integer]
|
16
|
+
attr_reader :total
|
17
|
+
|
18
|
+
# @return [Mihari::Structs::Filters::Alert::SearchFilterWithPagination]
|
19
|
+
attr_reader :filter
|
20
|
+
|
21
|
+
#
|
22
|
+
# @param [Array<Mihari::Models::Alert>] alerts
|
23
|
+
# @param [Integer] total
|
24
|
+
# @param [Mihari::Structs::Filters::Alert::SearchFilterWithPagination] filter
|
25
|
+
#
|
26
|
+
def initialize(alerts:, total:, filter:)
|
27
|
+
@alerts = alerts
|
28
|
+
@total = total
|
29
|
+
@filter = filter
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
#
|
34
|
+
# @param [Hash] params
|
35
|
+
#
|
36
|
+
# @return [ResultValue]
|
37
|
+
#
|
38
|
+
def call(params)
|
39
|
+
filter = params.to_h.to_snake_keys
|
40
|
+
|
41
|
+
# normalize keys
|
42
|
+
filter["artifact_data"] = filter["artifact"]
|
43
|
+
filter["tag_name"] = filter["tag"]
|
44
|
+
# symbolize hash keys
|
45
|
+
filter = filter.to_h.symbolize_keys
|
46
|
+
|
47
|
+
search_filter_with_pagination = Structs::Filters::Alert::SearchFilterWithPagination.new(**filter)
|
48
|
+
alerts = Mihari::Models::Alert.search(search_filter_with_pagination)
|
49
|
+
total = Mihari::Models::Alert.count(search_filter_with_pagination.without_pagination)
|
50
|
+
|
51
|
+
ResultValue.new(alerts: alerts, total: total, filter: filter)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
class AlertCreator < Service
|
56
|
+
#
|
57
|
+
# @param [Hash] params
|
58
|
+
#
|
59
|
+
# @return [Mihari::Models::Alert]
|
60
|
+
#
|
61
|
+
def call(params)
|
62
|
+
proxy = Services::AlertProxy.new(**params.to_snake_keys)
|
63
|
+
Services::AlertRunner.call proxy
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
class AlertDestroyer < Service
|
68
|
+
#
|
69
|
+
# @param [String] id
|
70
|
+
#
|
71
|
+
def call(id)
|
72
|
+
Mihari::Models::Alert.find(id).destroy
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
10
76
|
namespace :alerts do
|
11
77
|
desc "Search alerts", {
|
12
78
|
is_array: true,
|
@@ -17,33 +83,20 @@ module Mihari
|
|
17
83
|
params do
|
18
84
|
optional :page, type: Integer, default: 1
|
19
85
|
optional :limit, type: Integer, default: 10
|
20
|
-
|
21
86
|
optional :artifact, type: String
|
22
87
|
optional :rule_id, type: String
|
23
88
|
optional :tag, type: String
|
24
|
-
|
25
89
|
optional :fromAt, type: DateTime
|
26
90
|
optional :toAt, type: DateTime
|
27
91
|
end
|
28
92
|
get "/" do
|
29
|
-
|
30
|
-
|
31
|
-
# normalize keys
|
32
|
-
filter["artifact_data"] = filter["artifact"]
|
33
|
-
filter["tag_name"] = filter["tag"]
|
34
|
-
# symbolize hash keys
|
35
|
-
filter = filter.to_h.symbolize_keys
|
36
|
-
|
37
|
-
search_filter_with_pagination = Structs::Filters::Alert::SearchFilterWithPagination.new(**filter)
|
38
|
-
alerts = Mihari::Models::Alert.search(search_filter_with_pagination)
|
39
|
-
total = Mihari::Models::Alert.count(search_filter_with_pagination.without_pagination)
|
40
|
-
|
93
|
+
value = AlertSearcher.call(params.to_h)
|
41
94
|
present(
|
42
95
|
{
|
43
|
-
alerts: alerts,
|
44
|
-
total: total,
|
45
|
-
current_page: filter[:page].to_i,
|
46
|
-
page_size: filter[:limit].to_i
|
96
|
+
alerts: value.alerts,
|
97
|
+
total: value.total,
|
98
|
+
current_page: value.filter[:page].to_i,
|
99
|
+
page_size: value.filter[:limit].to_i
|
47
100
|
},
|
48
101
|
with: Entities::AlertsWithPagination
|
49
102
|
)
|
@@ -58,15 +111,8 @@ module Mihari
|
|
58
111
|
requires :id, type: Integer
|
59
112
|
end
|
60
113
|
delete "/:id" do
|
61
|
-
extend Dry::Monads[:result, :try]
|
62
|
-
|
63
114
|
id = params["id"].to_i
|
64
|
-
|
65
|
-
result = Try do
|
66
|
-
alert = Mihari::Models::Alert.find(id)
|
67
|
-
alert.destroy
|
68
|
-
end.to_result
|
69
|
-
|
115
|
+
result = AlertDestroyer.result(id)
|
70
116
|
if result.success?
|
71
117
|
status 204
|
72
118
|
return present({ message: "" }, with: Entities::Message)
|
@@ -76,9 +122,8 @@ module Mihari
|
|
76
122
|
case failure
|
77
123
|
when ActiveRecord::RecordNotFound
|
78
124
|
error!({ message: "ID:#{id} is not found" }, 404)
|
79
|
-
else
|
80
|
-
raise failure
|
81
125
|
end
|
126
|
+
raise failure
|
82
127
|
end
|
83
128
|
|
84
129
|
desc "Create an alert", {
|
@@ -90,14 +135,7 @@ module Mihari
|
|
90
135
|
requires :artifacts, type: Array, documentation: { type: String, is_array: true, param_type: "body" }
|
91
136
|
end
|
92
137
|
post "/" do
|
93
|
-
|
94
|
-
|
95
|
-
result = Try do
|
96
|
-
proxy = Services::AlertProxy.new(**params.to_snake_keys)
|
97
|
-
runner = Services::AlertRunner.new(proxy)
|
98
|
-
runner.call
|
99
|
-
end.to_result
|
100
|
-
|
138
|
+
result = AlertCreator.result(params)
|
101
139
|
if result.success?
|
102
140
|
status 201
|
103
141
|
return present(result.value!, with: Entities::Alert)
|
@@ -107,9 +145,8 @@ module Mihari
|
|
107
145
|
case failure
|
108
146
|
when ActiveRecord::RecordNotFound
|
109
147
|
error!({ message: "Rule:#{params["ruleId"]} is not found" }, 404)
|
110
|
-
else
|
111
|
-
raise failure
|
112
148
|
end
|
149
|
+
raise failure
|
113
150
|
end
|
114
151
|
end
|
115
152
|
end
|
@@ -7,6 +7,60 @@ module Mihari
|
|
7
7
|
# Artifact API endpoint
|
8
8
|
#
|
9
9
|
class Artifacts < Grape::API
|
10
|
+
class ArtifactGetter < Service
|
11
|
+
#
|
12
|
+
# @param [Integer] id
|
13
|
+
#
|
14
|
+
# @return [Mihari::Models::Artifact]
|
15
|
+
#
|
16
|
+
def call(id)
|
17
|
+
artifact = Mihari::Models::Artifact.includes(
|
18
|
+
:autonomous_system,
|
19
|
+
:geolocation,
|
20
|
+
:whois_record,
|
21
|
+
:dns_records,
|
22
|
+
:reverse_dns_names
|
23
|
+
).find(id)
|
24
|
+
# TODO: improve queries
|
25
|
+
alert_ids = Mihari::Models::Artifact.where(data: artifact.data).pluck(:alert_id)
|
26
|
+
tag_ids = Mihari::Models::Tagging.where(alert_id: alert_ids).pluck(:tag_id)
|
27
|
+
tags = Mihari::Models::Tag.where(id: tag_ids)
|
28
|
+
|
29
|
+
artifact.tags = tags
|
30
|
+
|
31
|
+
artifact
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
class ArtifactEnricher < Service
|
36
|
+
#
|
37
|
+
# @param [String] id
|
38
|
+
#
|
39
|
+
def call(id)
|
40
|
+
artifact = Mihari::Models::Artifact.includes(
|
41
|
+
:autonomous_system,
|
42
|
+
:geolocation,
|
43
|
+
:whois_record,
|
44
|
+
:dns_records,
|
45
|
+
:reverse_dns_names,
|
46
|
+
:cpes,
|
47
|
+
:ports
|
48
|
+
).find(id)
|
49
|
+
|
50
|
+
artifact.enrich_all
|
51
|
+
artifact.save
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
class ArtifactDestroyer < Service
|
56
|
+
#
|
57
|
+
# @param [Integer] id
|
58
|
+
#
|
59
|
+
def call(id)
|
60
|
+
Mihari::Models::Artifact.find(id).destroy
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
10
64
|
namespace :artifacts do
|
11
65
|
desc "Get an artifact", {
|
12
66
|
success: Entities::Artifact,
|
@@ -17,37 +71,16 @@ module Mihari
|
|
17
71
|
requires :id, type: Integer
|
18
72
|
end
|
19
73
|
get "/:id" do
|
20
|
-
extend Dry::Monads[:result, :try]
|
21
|
-
|
22
74
|
id = params[:id].to_i
|
23
|
-
|
24
|
-
result = Try do
|
25
|
-
artifact = Mihari::Models::Artifact.includes(
|
26
|
-
:autonomous_system,
|
27
|
-
:geolocation,
|
28
|
-
:whois_record,
|
29
|
-
:dns_records,
|
30
|
-
:reverse_dns_names
|
31
|
-
).find(id)
|
32
|
-
# TODO: improve queries
|
33
|
-
alert_ids = Mihari::Models::Artifact.where(data: artifact.data).pluck(:alert_id)
|
34
|
-
tag_ids = Mihari::Models::Tagging.where(alert_id: alert_ids).pluck(:tag_id)
|
35
|
-
tag_names = Mihari::Models::Tag.where(id: tag_ids).distinct.pluck(:name)
|
36
|
-
|
37
|
-
artifact.tags = tag_names
|
38
|
-
|
39
|
-
artifact
|
40
|
-
end.to_result
|
41
|
-
|
75
|
+
result = ArtifactGetter.result(id)
|
42
76
|
return present(result.value!, with: Entities::Artifact) if result.success?
|
43
77
|
|
44
78
|
failure = result.failure
|
45
79
|
case failure
|
46
80
|
when ActiveRecord::RecordNotFound
|
47
81
|
error!({ message: "ID:#{id} is not found" }, 404)
|
48
|
-
else
|
49
|
-
raise failure
|
50
82
|
end
|
83
|
+
raise failure
|
51
84
|
end
|
52
85
|
|
53
86
|
desc "Enrich an artifact", {
|
@@ -59,25 +92,8 @@ module Mihari
|
|
59
92
|
requires :id, type: Integer
|
60
93
|
end
|
61
94
|
get "/:id/enrich" do
|
62
|
-
extend Dry::Monads[:result, :try]
|
63
|
-
|
64
95
|
id = params["id"].to_i
|
65
|
-
|
66
|
-
result = Try do
|
67
|
-
artifact = Mihari::Models::Artifact.includes(
|
68
|
-
:autonomous_system,
|
69
|
-
:geolocation,
|
70
|
-
:whois_record,
|
71
|
-
:dns_records,
|
72
|
-
:reverse_dns_names,
|
73
|
-
:cpes,
|
74
|
-
:ports
|
75
|
-
).find(id)
|
76
|
-
|
77
|
-
artifact.enrich_all
|
78
|
-
artifact.save
|
79
|
-
end.to_result
|
80
|
-
|
96
|
+
result = ArtifactEnricher.result(id)
|
81
97
|
if result.success?
|
82
98
|
status 201
|
83
99
|
return present({ message: "" }, with: Entities::Message)
|
@@ -87,9 +103,8 @@ module Mihari
|
|
87
103
|
case failure
|
88
104
|
when ActiveRecord::RecordNotFound
|
89
105
|
error!({ message: "ID:#{id} is not found" }, 404)
|
90
|
-
else
|
91
|
-
raise failure
|
92
106
|
end
|
107
|
+
raise failure
|
93
108
|
end
|
94
109
|
|
95
110
|
desc "Delete an artifact", {
|
@@ -101,15 +116,8 @@ module Mihari
|
|
101
116
|
requires :id, type: Integer
|
102
117
|
end
|
103
118
|
delete "/:id" do
|
104
|
-
extend Dry::Monads[:result, :try]
|
105
|
-
|
106
119
|
id = params["id"].to_i
|
107
|
-
|
108
|
-
result = Try do
|
109
|
-
alert = Mihari::Models::Artifact.find(id)
|
110
|
-
alert.destroy
|
111
|
-
end.to_result
|
112
|
-
|
120
|
+
result = ArtifactDestroyer.result(id)
|
113
121
|
if result.success?
|
114
122
|
status 204
|
115
123
|
return present({ message: "" }, with: Entities::Message)
|
@@ -119,9 +127,8 @@ module Mihari
|
|
119
127
|
case failure
|
120
128
|
when ActiveRecord::RecordNotFound
|
121
129
|
error!({ message: "ID:#{id} is not found" }, 404)
|
122
|
-
else
|
123
|
-
raise failure
|
124
130
|
end
|
131
|
+
raise failure
|
125
132
|
end
|
126
133
|
end
|
127
134
|
end
|
@@ -7,6 +7,17 @@ module Mihari
|
|
7
7
|
# IP address API endpoint
|
8
8
|
#
|
9
9
|
class IPAddresses < Grape::API
|
10
|
+
class IPGetter < Service
|
11
|
+
#
|
12
|
+
# @param [String] ip
|
13
|
+
#
|
14
|
+
# @return [Mihari::Structs::IPInfo::Response]
|
15
|
+
#
|
16
|
+
def call(ip)
|
17
|
+
Mihari::Enrichers::IPInfo.new.call ip
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
10
21
|
namespace :ip_addresses do
|
11
22
|
desc "Get an IP address", {
|
12
23
|
success: Entities::IPAddress,
|
@@ -18,11 +29,15 @@ module Mihari
|
|
18
29
|
end
|
19
30
|
get "/:ip", requirements: { ip: %r{[^/]+} } do
|
20
31
|
ip = params[:ip].to_s
|
32
|
+
result = IPGetter.result(ip)
|
33
|
+
return present(result.value!, with: Entities::IPAddress) if result.success?
|
21
34
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
35
|
+
failure = result.failure
|
36
|
+
case failure
|
37
|
+
when Mihari::StatusCodeError
|
38
|
+
error!({ message: "ID:#{id} is not found" }, 404) if failure.status_code == 404
|
39
|
+
end
|
40
|
+
raise failure
|
26
41
|
end
|
27
42
|
end
|
28
43
|
end
|