-
Notifications
You must be signed in to change notification settings - Fork 773
Expand file tree
/
Copy pathintelligence_domain.go
More file actions
177 lines (148 loc) · 5.45 KB
/
Copy pathintelligence_domain.go
File metadata and controls
177 lines (148 loc) · 5.45 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
package cloudflare
import (
"context"
"errors"
"fmt"
"net/http"
"github.com/goccy/go-json"
)
// ErrMissingDomain is for when domain is needed but not given.
var ErrMissingDomain = errors.New("required domain missing")
// DomainDetails represents details for a domain.
type DomainDetails struct {
Domain string `json:"domain"`
ResolvesToRefs []ResolvesToRefs `json:"resolves_to_refs"`
PopularityRank int `json:"popularity_rank"`
Application Application `json:"application"`
RiskTypes []interface{} `json:"risk_types"`
ContentCategories []ContentCategories `json:"content_categories"`
AdditionalInformation AdditionalInformation `json:"additional_information"`
}
// ResolvesToRefs what a domain resolves to.
type ResolvesToRefs struct {
ID string `json:"id"`
Value string `json:"value"`
}
type Application struct {
ID int `json:"id"`
Name string `json:"name"`
}
// ContentCategories represents the categories for a domain.
type ContentCategories struct {
ID int `json:"id"`
SuperCategoryID int `json:"super_category_id"`
Name string `json:"name"`
}
// AdditionalInformation represents any additional information for a domain.
type AdditionalInformation struct {
SuspectedMalwareFamily string `json:"suspected_malware_family"`
}
// DomainHistory represents the history for a domain.
type DomainHistory struct {
Domain string `json:"domain"`
Categorizations []Categorizations `json:"categorizations"`
}
// Categories represents categories for a domain.
type Categories struct {
ID int `json:"id"`
Name string `json:"name"`
}
// Categorizations represents the categories and when those categories were set.
type Categorizations struct {
Categories []Categories `json:"categories"`
Start string `json:"start"`
End string `json:"end"`
}
// GetDomainDetailsParameters represent the parameters for a domain details request.
type GetDomainDetailsParameters struct {
AccountID string `url:"-"`
Domain string `url:"domain,omitempty"`
}
// DomainDetailsResponse represents an API response for domain details.
type DomainDetailsResponse struct {
Response
Result DomainDetails `json:"result,omitempty"`
}
// GetBulkDomainDetailsParameters represents the parameters for bulk domain details request.
type GetBulkDomainDetailsParameters struct {
AccountID string `url:"-"`
Domains []string `url:"domain"`
}
// GetBulkDomainDetailsResponse represents an API response for bulk domain details.
type GetBulkDomainDetailsResponse struct {
Response
Result []DomainDetails `json:"result,omitempty"`
}
// GetDomainHistoryParameters represents the parameters for domain history request.
type GetDomainHistoryParameters struct {
AccountID string `url:"-"`
Domain string `url:"domain,omitempty"`
}
// GetDomainHistoryResponse represents an API response for domain history.
type GetDomainHistoryResponse struct {
Response
Result []DomainHistory `json:"result,omitempty"`
}
// IntelligenceDomainDetails gets domain information.
//
// API Reference: https://api.cloudflare.com/#domain-intelligence-get-domain-details
func (api *API) IntelligenceDomainDetails(ctx context.Context, params GetDomainDetailsParameters) (DomainDetails, error) {
if params.AccountID == "" {
return DomainDetails{}, ErrMissingAccountID
}
if params.Domain == "" {
return DomainDetails{}, ErrMissingDomain
}
uri := buildURI(fmt.Sprintf("/accounts/%s/intel/domain", params.AccountID), params)
res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil)
if err != nil {
return DomainDetails{}, err
}
var domainDetails DomainDetailsResponse
if err := json.Unmarshal(res, &domainDetails); err != nil {
return DomainDetails{}, err
}
return domainDetails.Result, nil
}
// IntelligenceBulkDomainDetails gets domain information for a list of domains.
//
// API Reference: https://api.cloudflare.com/#domain-intelligence-get-multiple-domain-details
func (api *API) IntelligenceBulkDomainDetails(ctx context.Context, params GetBulkDomainDetailsParameters) ([]DomainDetails, error) {
if params.AccountID == "" {
return []DomainDetails{}, ErrMissingAccountID
}
if len(params.Domains) == 0 {
return []DomainDetails{}, ErrMissingDomain
}
uri := buildURI(fmt.Sprintf("/accounts/%s/intel/domain/bulk", params.AccountID), params)
res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil)
if err != nil {
return []DomainDetails{}, err
}
var domainDetails GetBulkDomainDetailsResponse
if err := json.Unmarshal(res, &domainDetails); err != nil {
return []DomainDetails{}, err
}
return domainDetails.Result, nil
}
// IntelligenceDomainHistory get domain history for given domain
//
// API Reference: https://api.cloudflare.com/#domain-history-get-domain-history
func (api *API) IntelligenceDomainHistory(ctx context.Context, params GetDomainHistoryParameters) ([]DomainHistory, error) {
if params.AccountID == "" {
return []DomainHistory{}, ErrMissingAccountID
}
if params.Domain == "" {
return []DomainHistory{}, ErrMissingDomain
}
uri := buildURI(fmt.Sprintf("/accounts/%s/intel/domain-history", params.AccountID), params)
res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil)
if err != nil {
return []DomainHistory{}, err
}
var domainDetails GetDomainHistoryResponse
if err := json.Unmarshal(res, &domainDetails); err != nil {
return []DomainHistory{}, err
}
return domainDetails.Result, nil
}