hachi 0.2.3 → 0.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/hachi/clients/alert.rb +2 -2
- data/lib/hachi/clients/base.rb +9 -2
- data/lib/hachi/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 25c386c075dc1e5962bd50ab50194d9489ab6ac017eb582be0136ea80b130fee
|
4
|
+
data.tar.gz: 50c9377cbf664c06aeb72675799d5657ae9368a3dcbd52e1dab29bf6990e928a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fcea0e7d85452ee6a9bfc94cb154abe28234bf0bc87db4b855d296a1ec7119085973fb29d5c71a5304c58c2f78a7a9df30a1b9d6bc3cdc0ea6f72ba02fab8ee0
|
7
|
+
data.tar.gz: b31c9631dc876c7d030fb3171a35985a442cb0c8da5755cd64644d5041e16f995435ef921ef72e4739fafd0048d2f2024c2e499aacb8eb61e4883ecd7611f0dd
|
data/README.md
CHANGED
@@ -41,7 +41,7 @@ See `samples` for more.
|
|
41
41
|
| HTTP Method | URI | Action | API method |
|
42
42
|
|-------------|-----------------------------------|-----------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
43
43
|
| GET | /api/alert | List alerts | `#api.alert.list` |
|
44
|
-
| POST | /api/alert/_search | Find alerts | `#api.alert.search(attributes
|
44
|
+
| POST | /api/alert/_search | Find alerts | `#api.alert.search(attributes, range: "all")` |
|
45
45
|
| PATCH | /api/alert/_bulk | Update alerts in bulk | N/A |
|
46
46
|
| POST | /api/alert/_stats | Compute stats on alerts | N/A |
|
47
47
|
| POST | /api/alert | Create an alert | `#api.alert.create(title:, description:, severity: nil, date: nil, tags: nil, tlp: nil, status: nil, type:, source:, source_ref: nil, artifacts: nil, follow: nil)` |
|
data/lib/hachi/clients/alert.rb
CHANGED
@@ -36,8 +36,8 @@ module Hachi
|
|
36
36
|
post("/api/alert", alert.payload) { |json| json }
|
37
37
|
end
|
38
38
|
|
39
|
-
def search(attributes, range: "all")
|
40
|
-
_search("/api/alert/_search", attributes: attributes, range: range) { |json| json }
|
39
|
+
def search(attributes, range: "all", sort: nil)
|
40
|
+
_search("/api/alert/_search", attributes: attributes, range: range, sort: sort) { |json| json }
|
41
41
|
end
|
42
42
|
end
|
43
43
|
end
|
data/lib/hachi/clients/base.rb
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
require "json"
|
4
4
|
require "net/https"
|
5
|
+
require "uri"
|
5
6
|
|
6
7
|
module Hachi
|
7
8
|
module Clients
|
@@ -113,7 +114,7 @@ module Hachi
|
|
113
114
|
raise ArgumentError, "from should be smaller than to"
|
114
115
|
end
|
115
116
|
|
116
|
-
def _search(path, attributes:, range: "all")
|
117
|
+
def _search(path, attributes:, range: "all", sort: nil)
|
117
118
|
validate_range range
|
118
119
|
|
119
120
|
attributes = normalize_attributes(attributes)
|
@@ -136,7 +137,9 @@ module Hachi
|
|
136
137
|
_and: [conditions, default_conditions].flatten,
|
137
138
|
}
|
138
139
|
|
139
|
-
|
140
|
+
query_string = build_query_string(range: range, sort: sort)
|
141
|
+
|
142
|
+
post("#{path}?#{query_string}", query: query) { |json| json }
|
140
143
|
end
|
141
144
|
|
142
145
|
def decompose_data(data)
|
@@ -157,6 +160,10 @@ module Hachi
|
|
157
160
|
head, *others = string.to_s.split("_")
|
158
161
|
[head, others.map(&:capitalize)].flatten.join
|
159
162
|
end
|
163
|
+
|
164
|
+
def build_query_string(params)
|
165
|
+
URI.encode_www_form(params.reject { |_k, v| v.nil? })
|
166
|
+
end
|
160
167
|
end
|
161
168
|
end
|
162
169
|
end
|
data/lib/hachi/version.rb
CHANGED