|
| 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