@@ -4,13 +4,15 @@ import (
44 "context"
55 "fmt"
66 "net/http"
7+ "net/url"
78)
89
910const (
10- CreateRulePath = "%s/api/secure/rules"
11- GetRuleByIDPath = "%s/api/secure/rules/%d"
12- UpdateRulePath = "%s/api/secure/rules/%d"
13- DeleteURLPath = "%s/api/secure/rules/%d"
11+ CreateRulePath = "%s/api/secure/rules"
12+ GetRuleByIDPath = "%s/api/secure/rules/%d"
13+ UpdateRulePath = "%s/api/secure/rules/%d"
14+ DeleteURLPath = "%s/api/secure/rules/%d"
15+ GetRuleGroupPath = "%s/api/secure/rules/groups?name=%s&type=%s"
1416)
1517
1618type RuleInterface interface {
@@ -19,6 +21,7 @@ type RuleInterface interface {
1921 GetRuleByID (ctx context.Context , ruleID int ) (Rule , error )
2022 UpdateRule (ctx context.Context , rule Rule ) (Rule , error )
2123 DeleteRule (ctx context.Context , ruleID int ) error
24+ GetRuleGroup (ctx context.Context , ruleName string , ruleType string ) ([]Rule , error )
2225}
2326
2427func (client * Client ) CreateRule (ctx context.Context , rule Rule ) (Rule , error ) {
@@ -88,6 +91,21 @@ func (client *Client) DeleteRule(ctx context.Context, ruleID int) error {
8891 return err
8992}
9093
94+ func (client * Client ) GetRuleGroup (ctx context.Context , ruleName string , ruleType string ) ([]Rule , error ) {
95+ response , err := client .requester .Request (ctx , http .MethodGet , client .GetRuleGroupURL (ruleName , ruleType ), nil )
96+ if err != nil {
97+ return []Rule {}, err
98+ }
99+ defer response .Body .Close ()
100+
101+ if response .StatusCode != http .StatusOK {
102+ return []Rule {}, client .ErrorFromResponse (response )
103+ }
104+
105+ return Unmarshal [[]Rule ](response .Body )
106+
107+ }
108+
91109func (client * Client ) CreateRuleURL () string {
92110 return fmt .Sprintf (CreateRulePath , client .config .url )
93111}
@@ -103,3 +121,7 @@ func (client *Client) UpdateRuleURL(ruleID int) string {
103121func (client * Client ) DeleteRuleURL (ruleID int ) string {
104122 return fmt .Sprintf (DeleteURLPath , client .config .url , ruleID )
105123}
124+
125+ func (client * Client ) GetRuleGroupURL (ruleName string , ruleType string ) string {
126+ return fmt .Sprintf (GetRuleGroupPath , client .config .url , url .QueryEscape (ruleName ), url .QueryEscape (ruleType ))
127+ }
0 commit comments