/
akamai_defined_bot.go
60 lines (49 loc) · 1.69 KB
/
akamai_defined_bot.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package botman
import (
"context"
"fmt"
"net/http"
)
type (
// The AkamaiDefinedBot interface supports retrieving akamai defined bots
AkamaiDefinedBot interface {
// GetAkamaiDefinedBotList https://techdocs.akamai.com/bot-manager/reference/get-akamai-defined-bots
GetAkamaiDefinedBotList(ctx context.Context, params GetAkamaiDefinedBotListRequest) (*GetAkamaiDefinedBotListResponse, error)
}
// GetAkamaiDefinedBotListRequest is used to retrieve the akamai bot category actions for a policy.
GetAkamaiDefinedBotListRequest struct {
BotName string
}
// GetAkamaiDefinedBotListResponse is returned from a call to GetAkamaiDefinedBotList.
GetAkamaiDefinedBotListResponse struct {
Bots []map[string]interface{} `json:"bots"`
}
)
func (b *botman) GetAkamaiDefinedBotList(ctx context.Context, params GetAkamaiDefinedBotListRequest) (*GetAkamaiDefinedBotListResponse, error) {
logger := b.Log(ctx)
logger.Debug("GetAkamaiDefinedBotList")
uri := "/appsec/v1/akamai-defined-bots"
req, err := http.NewRequestWithContext(ctx, http.MethodGet, uri, nil)
if err != nil {
return nil, fmt.Errorf("failed to create GetAkamaiDefinedBotList request: %w", err)
}
var result GetAkamaiDefinedBotListResponse
resp, err := b.Exec(req, &result)
if err != nil {
return nil, fmt.Errorf("GetAkamaiDefinedBotList request failed: %w", err)
}
if resp.StatusCode != http.StatusOK {
return nil, b.Error(resp)
}
var filteredResult GetAkamaiDefinedBotListResponse
if params.BotName != "" {
for _, val := range result.Bots {
if val["botName"].(string) == params.BotName {
filteredResult.Bots = append(filteredResult.Bots, val)
}
}
} else {
filteredResult = result
}
return &filteredResult, nil
}