github.com/akamai/AkamaiOPEN-edgegrid-golang/v8@v8.1.0/pkg/botman/bot_detection.go (about) 1 package botman 2 3 import ( 4 "context" 5 "fmt" 6 "net/http" 7 ) 8 9 type ( 10 // The BotDetection interface supports retrieving bot detections 11 BotDetection interface { 12 // GetBotDetectionList todo: add link 13 GetBotDetectionList(ctx context.Context, params GetBotDetectionListRequest) (*GetBotDetectionListResponse, error) 14 } 15 16 // GetBotDetectionListRequest is used to retrieve the akamai bot category actions for a policy. 17 GetBotDetectionListRequest struct { 18 DetectionName string 19 } 20 21 // GetBotDetectionListResponse is returned from a call to GetBotDetectionList. 22 GetBotDetectionListResponse struct { 23 Detections []map[string]interface{} `json:"detections"` 24 } 25 ) 26 27 func (b *botman) GetBotDetectionList(ctx context.Context, params GetBotDetectionListRequest) (*GetBotDetectionListResponse, error) { 28 29 logger := b.Log(ctx) 30 logger.Debug("GetBotDetectionList") 31 32 uri := "/appsec/v1/bot-detections" 33 34 req, err := http.NewRequestWithContext(ctx, http.MethodGet, uri, nil) 35 if err != nil { 36 return nil, fmt.Errorf("failed to create GetBotDetectionList request: %w", err) 37 } 38 39 var result GetBotDetectionListResponse 40 resp, err := b.Exec(req, &result) 41 if err != nil { 42 return nil, fmt.Errorf("GetBotDetectionList request failed: %w", err) 43 } 44 45 if resp.StatusCode != http.StatusOK { 46 return nil, b.Error(resp) 47 } 48 49 var filteredResult GetBotDetectionListResponse 50 if params.DetectionName != "" { 51 for _, val := range result.Detections { 52 if val["detectionName"].(string) == params.DetectionName { 53 filteredResult.Detections = append(filteredResult.Detections, val) 54 } 55 } 56 } else { 57 filteredResult = result 58 } 59 return &filteredResult, nil 60 }