Skip to content

Commit 473b61c

Browse files
concentratorKNechaevWallarm
authored andcommitted
Fixes credential_stuffing resource
1 parent 64b4ee7 commit 473b61c

2 files changed

Lines changed: 44 additions & 0 deletions

File tree

config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ type (
5151
OverlimitResSettings
5252
RuleSettings
5353
ApiSpec
54+
CredentialStuffingConfigs
5455
SecurityIssues
5556
Hits
5657
}

credential_stuffing.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package wallarm
2+
3+
import (
4+
"encoding/json"
5+
"fmt"
6+
)
7+
8+
type (
9+
// CredentialStuffingConfigs contains operations for reading credential stuffing configurations.
10+
CredentialStuffingConfigs interface {
11+
CredentialStuffingConfigsRead(clientID int) ([]ActionBody, error)
12+
}
13+
14+
// CredentialStuffingConfigsResp is the response from
15+
// GET /v4/clients/{clientID}/credential_stuffing/configs.
16+
// Configs are split into "default" and "custom" buckets.
17+
CredentialStuffingConfigsResp struct {
18+
Status int `json:"status"`
19+
Body struct {
20+
Default []ActionBody `json:"default"`
21+
Custom []ActionBody `json:"custom"`
22+
} `json:"body"`
23+
}
24+
)
25+
26+
// CredentialStuffingConfigsRead fetches all credential stuffing configs for a client.
27+
// API: GET /v4/clients/{clientID}/credential_stuffing/configs
28+
func (api *api) CredentialStuffingConfigsRead(clientID int) ([]ActionBody, error) {
29+
uri := fmt.Sprintf("/v4/clients/%d/credential_stuffing/configs", clientID)
30+
respBody, err := api.makeRequest("GET", uri, "credential_stuffing", nil, nil)
31+
if err != nil {
32+
return nil, err
33+
}
34+
var resp CredentialStuffingConfigsResp
35+
if err = json.Unmarshal(respBody, &resp); err != nil {
36+
return nil, fmt.Errorf("CredentialStuffingConfigsRead: failed to parse response: %w", err)
37+
}
38+
// Merge both buckets into a single slice.
39+
configs := make([]ActionBody, 0, len(resp.Body.Default)+len(resp.Body.Custom))
40+
configs = append(configs, resp.Body.Default...)
41+
configs = append(configs, resp.Body.Custom...)
42+
return configs, nil
43+
}

0 commit comments

Comments
 (0)