forked from cloudflare/cloudflare-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathintelligence_phishing.go
52 lines (44 loc) · 1.47 KB
/
intelligence_phishing.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
package cloudflare
import (
"context"
"fmt"
"net/http"
"github.com/goccy/go-json"
)
// PhishingScan represent information about a phishing scan.
type PhishingScan struct {
URL string `json:"url"`
Phishing bool `json:"phishing"`
Verified bool `json:"verified"`
Score float64 `json:"score"`
Classifier string `json:"classifier"`
}
// PhishingScanParameters represent parameters for a phishing scan request.
type PhishingScanParameters struct {
AccountID string `url:"-"`
URL string `url:"url,omitempty"`
Skip bool `url:"skip,omitempty"`
}
// PhishingScanResponse represent an API response for a phishing scan.
type PhishingScanResponse struct {
Response
Result PhishingScan `json:"result,omitempty"`
}
// IntelligencePhishingScan scans a URL for suspected phishing
//
// API Reference: https://api.cloudflare.com/#phishing-url-scanner-scan-suspicious-url
func (api *API) IntelligencePhishingScan(ctx context.Context, params PhishingScanParameters) (PhishingScan, error) {
if params.AccountID == "" {
return PhishingScan{}, ErrMissingAccountID
}
uri := buildURI(fmt.Sprintf("/accounts/%s/intel-phishing/predict", params.AccountID), params)
res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil)
if err != nil {
return PhishingScan{}, err
}
var phishingScanResponse PhishingScanResponse
if err := json.Unmarshal(res, &phishingScanResponse); err != nil {
return PhishingScan{}, err
}
return phishingScanResponse.Result, nil
}