Skip to content
This repository was archived by the owner on Sep 20, 2024. It is now read-only.

Commit 6e7daa5

Browse files
authored
Merge pull request #27 from vulncheck-oss/26-rules-endpoint
Issue #26 - Add snort & suricata rules endpoint support
2 parents 926e79b + 27bc20d commit 6e7daa5

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

rules.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package sdk
2+
3+
import (
4+
"io"
5+
"net/http"
6+
"net/url"
7+
)
8+
9+
// https://docs.vulncheck.com/api/rules
10+
func (c *Client) GetRule(rule string) (string, error) {
11+
12+
// in the future, we can add more indexes. For now, we only have initial-access
13+
index := "initial-access"
14+
15+
client := &http.Client{}
16+
req, err := http.NewRequest("GET", c.GetUrl()+"/v3/rules/"+index+"/"+url.QueryEscape(rule), nil)
17+
if err != nil {
18+
panic(err)
19+
}
20+
21+
c.SetAuthHeader(req)
22+
23+
res, err := client.Do(req)
24+
if err != nil {
25+
panic(err)
26+
}
27+
28+
defer res.Body.Close()
29+
body, _ := io.ReadAll(res.Body)
30+
31+
return string(body), nil
32+
}

rules_test.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package sdk
2+
3+
// LIVE TESTS - these tests require a valid token to run
4+
// func TestGetRule(t *testing.T) {
5+
// t.Run("GetRule", func(t *testing.T) {
6+
// client := Connect("URL", "")
7+
8+
// data, err := client.GetRule("suricata")
9+
// if err != nil {
10+
// t.Errorf("Error: %v", err)
11+
// }
12+
13+
// if data == "" {
14+
// t.Errorf("Expected a string, got %v", data)
15+
// }
16+
17+
// data, err := client.GetRule("snort")
18+
// if err != nil {
19+
// t.Errorf("Error: %v", err)
20+
// }
21+
// })
22+
// }

0 commit comments

Comments
 (0)