|
| 1 | +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. |
| 2 | + |
| 3 | +package abuse_reports |
| 4 | + |
| 5 | +import ( |
| 6 | + "context" |
| 7 | + "errors" |
| 8 | + "fmt" |
| 9 | + "net/http" |
| 10 | + |
| 11 | + "github.com/cloudflare/cloudflare-go/v4/internal/apijson" |
| 12 | + "github.com/cloudflare/cloudflare-go/v4/internal/param" |
| 13 | + "github.com/cloudflare/cloudflare-go/v4/internal/requestconfig" |
| 14 | + "github.com/cloudflare/cloudflare-go/v4/option" |
| 15 | +) |
| 16 | + |
| 17 | +// AbuseReportService contains methods and other services that help with |
| 18 | +// interacting with the cloudflare API. |
| 19 | +// |
| 20 | +// Note, unlike clients, this service does not read variables from the environment |
| 21 | +// automatically. You should not instantiate this service directly, and instead use |
| 22 | +// the [NewAbuseReportService] method instead. |
| 23 | +type AbuseReportService struct { |
| 24 | + Options []option.RequestOption |
| 25 | +} |
| 26 | + |
| 27 | +// NewAbuseReportService generates a new service that applies the given options to |
| 28 | +// each request. These options are applied after the parent client's options (if |
| 29 | +// there is one), and before any request-specific options. |
| 30 | +func NewAbuseReportService(opts ...option.RequestOption) (r *AbuseReportService) { |
| 31 | + r = &AbuseReportService{} |
| 32 | + r.Options = opts |
| 33 | + return |
| 34 | +} |
| 35 | + |
| 36 | +// Submit the Abuse Report of a particular type |
| 37 | +func (r *AbuseReportService) New(ctx context.Context, reportType AbuseReportNewParamsReportType, params AbuseReportNewParams, opts ...option.RequestOption) (res *string, err error) { |
| 38 | + var env AbuseReportNewResponseEnvelope |
| 39 | + opts = append(r.Options[:], opts...) |
| 40 | + if params.AccountID.Value == "" { |
| 41 | + err = errors.New("missing required account_id parameter") |
| 42 | + return |
| 43 | + } |
| 44 | + path := fmt.Sprintf("accounts/%s/abuse-reports/%v", params.AccountID, reportType) |
| 45 | + err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, params, &env, opts...) |
| 46 | + if err != nil { |
| 47 | + return |
| 48 | + } |
| 49 | + res = &env.Result |
| 50 | + return |
| 51 | +} |
| 52 | + |
| 53 | +type AbuseReportNewParams struct { |
| 54 | + AccountID param.Field[string] `path:"account_id,required"` |
| 55 | + // The abuse report type |
| 56 | + Act param.Field[AbuseReportNewParamsAct] `json:"act,required"` |
| 57 | + // A valid email of the abuse reporter |
| 58 | + Email param.Field[string] `json:"email,required"` |
| 59 | + // Should match the value provided in `email` |
| 60 | + Email2 param.Field[string] `json:"email2,required"` |
| 61 | + // Notification type based on the abuse type. NOTE: Copyright (DMCA) and Trademark |
| 62 | + // reports cannot be anonymous. |
| 63 | + HostNotification param.Field[AbuseReportNewParamsHostNotification] `json:"host_notification,required"` |
| 64 | + // Notification type based on the abuse type. NOTE: Copyright (DMCA) and Trademark |
| 65 | + // reports cannot be anonymous. |
| 66 | + NcmecNotification param.Field[AbuseReportNewParamsNcmecNotification] `json:"ncmec_notification,required"` |
| 67 | + // Notification type based on the abuse type. NOTE: Copyright (DMCA) and Trademark |
| 68 | + // reports cannot be anonymous. |
| 69 | + OwnerNotification param.Field[AbuseReportNewParamsOwnerNotification] `json:"owner_notification,required"` |
| 70 | + // A list of valid URLs separated by ‘ ’ (new line character). The list of the URLs |
| 71 | + // should not exceed 250 URLs. All URLs should have the same hostname. Each URL |
| 72 | + // should be unique |
| 73 | + URLs param.Field[string] `json:"urls,required"` |
| 74 | + // Text not exceeding 100 characters |
| 75 | + Address1 param.Field[string] `json:"address1"` |
| 76 | + // The name of the copyright holder. Text not exceeding 60 characters. |
| 77 | + AgentName param.Field[string] `json:"agent_name"` |
| 78 | + // Can be 0 or 1 |
| 79 | + Agree param.Field[AbuseReportNewParamsAgree] `json:"agree"` |
| 80 | + // Text not exceeding 255 characters |
| 81 | + City param.Field[string] `json:"city"` |
| 82 | + // Any additional comments about the infringement not exceeding 2000 characters |
| 83 | + Comments param.Field[string] `json:"comments"` |
| 84 | + // Text not exceeding 100 characters |
| 85 | + Company param.Field[string] `json:"company"` |
| 86 | + // Text not exceeding 255 characters |
| 87 | + Country param.Field[string] `json:"country"` |
| 88 | + // A list of IP addresses separated by ‘ ’ (new line character). The list of |
| 89 | + // destination IPs should not exceed 30 IP addresses. Each one of the IP addresses |
| 90 | + // ought to be unique |
| 91 | + DestinationIPs param.Field[string] `json:"destination_ips"` |
| 92 | + // A detailed description of the infringement, including any necessary access |
| 93 | + // details and the exact steps needed to view the content, not exceeding 5000 |
| 94 | + // characters |
| 95 | + Justification param.Field[string] `json:"justification"` |
| 96 | + // Text not exceeding 255 characters |
| 97 | + Name param.Field[string] `json:"name"` |
| 98 | + // If the submitter is the target of NCSEI in the URLs of the abuse report |
| 99 | + NcseiSubjectRepresentation param.Field[bool] `json:"ncsei_subject_representation"` |
| 100 | + // Text not exceeding 255 characters |
| 101 | + OriginalWork param.Field[string] `json:"original_work"` |
| 102 | + // A comma separated list of ports and protocols e.g. 80/TCP, 22/UDP. The total |
| 103 | + // size of the field should not exceed 2000 characters. Each individual |
| 104 | + // port/protocol should not exceed 100 characters. The list should not have more |
| 105 | + // than 30 unique ports and protocols. |
| 106 | + PortsProtocols param.Field[string] `json:"ports_protocols"` |
| 107 | + // Required for DMCA reports, should be same as Name. An affirmation that all |
| 108 | + // information in the report is true and accurate while agreeing to the policies of |
| 109 | + // Cloudflare's abuse reports |
| 110 | + Signature param.Field[string] `json:"signature"` |
| 111 | + // A list of IP addresses separated by ‘ ’ (new line character). The list of source |
| 112 | + // IPs should not exceed 30 IP addresses. Each one of the IP addresses ought to be |
| 113 | + // unique |
| 114 | + SourceIPs param.Field[string] `json:"source_ips"` |
| 115 | + // Text not exceeding 255 characters |
| 116 | + State param.Field[string] `json:"state"` |
| 117 | + // Text not exceeding 20 characters |
| 118 | + Tele param.Field[string] `json:"tele"` |
| 119 | + // Text not exceeding 255 characters |
| 120 | + Title param.Field[string] `json:"title"` |
| 121 | + // Text not exceeding 1000 characters |
| 122 | + TrademarkNumber param.Field[string] `json:"trademark_number"` |
| 123 | + // Text not exceeding 1000 characters |
| 124 | + TrademarkOffice param.Field[string] `json:"trademark_office"` |
| 125 | + // Text not exceeding 1000 characters |
| 126 | + TrademarkSymbol param.Field[string] `json:"trademark_symbol"` |
| 127 | +} |
| 128 | + |
| 129 | +func (r AbuseReportNewParams) MarshalJSON() (data []byte, err error) { |
| 130 | + return apijson.MarshalRoot(r) |
| 131 | +} |
| 132 | + |
| 133 | +// The abuse report type |
| 134 | +type AbuseReportNewParamsReportType string |
| 135 | + |
| 136 | +const ( |
| 137 | + AbuseReportNewParamsReportTypeAbuseDmca AbuseReportNewParamsReportType = "abuse_dmca" |
| 138 | + AbuseReportNewParamsReportTypeAbuseTrademark AbuseReportNewParamsReportType = "abuse_trademark" |
| 139 | + AbuseReportNewParamsReportTypeAbuseGeneral AbuseReportNewParamsReportType = "abuse_general" |
| 140 | + AbuseReportNewParamsReportTypeAbusePhishing AbuseReportNewParamsReportType = "abuse_phishing" |
| 141 | + AbuseReportNewParamsReportTypeAbuseChildren AbuseReportNewParamsReportType = "abuse_children" |
| 142 | + AbuseReportNewParamsReportTypeAbuseThreat AbuseReportNewParamsReportType = "abuse_threat" |
| 143 | + AbuseReportNewParamsReportTypeAbuseRegistrarWhois AbuseReportNewParamsReportType = "abuse_registrar_whois" |
| 144 | + AbuseReportNewParamsReportTypeAbuseNcsei AbuseReportNewParamsReportType = "abuse_ncsei" |
| 145 | +) |
| 146 | + |
| 147 | +func (r AbuseReportNewParamsReportType) IsKnown() bool { |
| 148 | + switch r { |
| 149 | + case AbuseReportNewParamsReportTypeAbuseDmca, AbuseReportNewParamsReportTypeAbuseTrademark, AbuseReportNewParamsReportTypeAbuseGeneral, AbuseReportNewParamsReportTypeAbusePhishing, AbuseReportNewParamsReportTypeAbuseChildren, AbuseReportNewParamsReportTypeAbuseThreat, AbuseReportNewParamsReportTypeAbuseRegistrarWhois, AbuseReportNewParamsReportTypeAbuseNcsei: |
| 150 | + return true |
| 151 | + } |
| 152 | + return false |
| 153 | +} |
| 154 | + |
| 155 | +// The abuse report type |
| 156 | +type AbuseReportNewParamsAct string |
| 157 | + |
| 158 | +const ( |
| 159 | + AbuseReportNewParamsActAbuseDmca AbuseReportNewParamsAct = "abuse_dmca" |
| 160 | + AbuseReportNewParamsActAbuseTrademark AbuseReportNewParamsAct = "abuse_trademark" |
| 161 | + AbuseReportNewParamsActAbuseGeneral AbuseReportNewParamsAct = "abuse_general" |
| 162 | + AbuseReportNewParamsActAbusePhishing AbuseReportNewParamsAct = "abuse_phishing" |
| 163 | + AbuseReportNewParamsActAbuseChildren AbuseReportNewParamsAct = "abuse_children" |
| 164 | + AbuseReportNewParamsActAbuseThreat AbuseReportNewParamsAct = "abuse_threat" |
| 165 | + AbuseReportNewParamsActAbuseRegistrarWhois AbuseReportNewParamsAct = "abuse_registrar_whois" |
| 166 | + AbuseReportNewParamsActAbuseNcsei AbuseReportNewParamsAct = "abuse_ncsei" |
| 167 | +) |
| 168 | + |
| 169 | +func (r AbuseReportNewParamsAct) IsKnown() bool { |
| 170 | + switch r { |
| 171 | + case AbuseReportNewParamsActAbuseDmca, AbuseReportNewParamsActAbuseTrademark, AbuseReportNewParamsActAbuseGeneral, AbuseReportNewParamsActAbusePhishing, AbuseReportNewParamsActAbuseChildren, AbuseReportNewParamsActAbuseThreat, AbuseReportNewParamsActAbuseRegistrarWhois, AbuseReportNewParamsActAbuseNcsei: |
| 172 | + return true |
| 173 | + } |
| 174 | + return false |
| 175 | +} |
| 176 | + |
| 177 | +// Notification type based on the abuse type. NOTE: Copyright (DMCA) and Trademark |
| 178 | +// reports cannot be anonymous. |
| 179 | +type AbuseReportNewParamsHostNotification string |
| 180 | + |
| 181 | +const ( |
| 182 | + AbuseReportNewParamsHostNotificationSend AbuseReportNewParamsHostNotification = "send" |
| 183 | + AbuseReportNewParamsHostNotificationSendAnon AbuseReportNewParamsHostNotification = "send-anon" |
| 184 | + AbuseReportNewParamsHostNotificationNone AbuseReportNewParamsHostNotification = "none" |
| 185 | +) |
| 186 | + |
| 187 | +func (r AbuseReportNewParamsHostNotification) IsKnown() bool { |
| 188 | + switch r { |
| 189 | + case AbuseReportNewParamsHostNotificationSend, AbuseReportNewParamsHostNotificationSendAnon, AbuseReportNewParamsHostNotificationNone: |
| 190 | + return true |
| 191 | + } |
| 192 | + return false |
| 193 | +} |
| 194 | + |
| 195 | +// Notification type based on the abuse type. NOTE: Copyright (DMCA) and Trademark |
| 196 | +// reports cannot be anonymous. |
| 197 | +type AbuseReportNewParamsNcmecNotification string |
| 198 | + |
| 199 | +const ( |
| 200 | + AbuseReportNewParamsNcmecNotificationSend AbuseReportNewParamsNcmecNotification = "send" |
| 201 | + AbuseReportNewParamsNcmecNotificationSendAnon AbuseReportNewParamsNcmecNotification = "send-anon" |
| 202 | + AbuseReportNewParamsNcmecNotificationNone AbuseReportNewParamsNcmecNotification = "none" |
| 203 | +) |
| 204 | + |
| 205 | +func (r AbuseReportNewParamsNcmecNotification) IsKnown() bool { |
| 206 | + switch r { |
| 207 | + case AbuseReportNewParamsNcmecNotificationSend, AbuseReportNewParamsNcmecNotificationSendAnon, AbuseReportNewParamsNcmecNotificationNone: |
| 208 | + return true |
| 209 | + } |
| 210 | + return false |
| 211 | +} |
| 212 | + |
| 213 | +// Notification type based on the abuse type. NOTE: Copyright (DMCA) and Trademark |
| 214 | +// reports cannot be anonymous. |
| 215 | +type AbuseReportNewParamsOwnerNotification string |
| 216 | + |
| 217 | +const ( |
| 218 | + AbuseReportNewParamsOwnerNotificationSend AbuseReportNewParamsOwnerNotification = "send" |
| 219 | + AbuseReportNewParamsOwnerNotificationSendAnon AbuseReportNewParamsOwnerNotification = "send-anon" |
| 220 | + AbuseReportNewParamsOwnerNotificationNone AbuseReportNewParamsOwnerNotification = "none" |
| 221 | +) |
| 222 | + |
| 223 | +func (r AbuseReportNewParamsOwnerNotification) IsKnown() bool { |
| 224 | + switch r { |
| 225 | + case AbuseReportNewParamsOwnerNotificationSend, AbuseReportNewParamsOwnerNotificationSendAnon, AbuseReportNewParamsOwnerNotificationNone: |
| 226 | + return true |
| 227 | + } |
| 228 | + return false |
| 229 | +} |
| 230 | + |
| 231 | +// Can be 0 or 1 |
| 232 | +type AbuseReportNewParamsAgree int64 |
| 233 | + |
| 234 | +const ( |
| 235 | + AbuseReportNewParamsAgree0 AbuseReportNewParamsAgree = 0 |
| 236 | + AbuseReportNewParamsAgree1 AbuseReportNewParamsAgree = 1 |
| 237 | +) |
| 238 | + |
| 239 | +func (r AbuseReportNewParamsAgree) IsKnown() bool { |
| 240 | + switch r { |
| 241 | + case AbuseReportNewParamsAgree0, AbuseReportNewParamsAgree1: |
| 242 | + return true |
| 243 | + } |
| 244 | + return false |
| 245 | +} |
| 246 | + |
| 247 | +type AbuseReportNewResponseEnvelope struct { |
| 248 | + // The identifier for the submitted abuse report. |
| 249 | + AbuseRand string `json:"abuse_rand,required"` |
| 250 | + Request AbuseReportNewResponseEnvelopeRequest `json:"request,required"` |
| 251 | + // The result should be 'success' for successful response |
| 252 | + Result string `json:"result,required"` |
| 253 | + JSON abuseReportNewResponseEnvelopeJSON `json:"-"` |
| 254 | +} |
| 255 | + |
| 256 | +// abuseReportNewResponseEnvelopeJSON contains the JSON metadata for the struct |
| 257 | +// [AbuseReportNewResponseEnvelope] |
| 258 | +type abuseReportNewResponseEnvelopeJSON struct { |
| 259 | + AbuseRand apijson.Field |
| 260 | + Request apijson.Field |
| 261 | + Result apijson.Field |
| 262 | + raw string |
| 263 | + ExtraFields map[string]apijson.Field |
| 264 | +} |
| 265 | + |
| 266 | +func (r *AbuseReportNewResponseEnvelope) UnmarshalJSON(data []byte) (err error) { |
| 267 | + return apijson.UnmarshalRoot(data, r) |
| 268 | +} |
| 269 | + |
| 270 | +func (r abuseReportNewResponseEnvelopeJSON) RawJSON() string { |
| 271 | + return r.raw |
| 272 | +} |
| 273 | + |
| 274 | +type AbuseReportNewResponseEnvelopeRequest struct { |
| 275 | + // The abuse report type |
| 276 | + Act AbuseReportNewResponseEnvelopeRequestAct `json:"act,required"` |
| 277 | + JSON abuseReportNewResponseEnvelopeRequestJSON `json:"-"` |
| 278 | +} |
| 279 | + |
| 280 | +// abuseReportNewResponseEnvelopeRequestJSON contains the JSON metadata for the |
| 281 | +// struct [AbuseReportNewResponseEnvelopeRequest] |
| 282 | +type abuseReportNewResponseEnvelopeRequestJSON struct { |
| 283 | + Act apijson.Field |
| 284 | + raw string |
| 285 | + ExtraFields map[string]apijson.Field |
| 286 | +} |
| 287 | + |
| 288 | +func (r *AbuseReportNewResponseEnvelopeRequest) UnmarshalJSON(data []byte) (err error) { |
| 289 | + return apijson.UnmarshalRoot(data, r) |
| 290 | +} |
| 291 | + |
| 292 | +func (r abuseReportNewResponseEnvelopeRequestJSON) RawJSON() string { |
| 293 | + return r.raw |
| 294 | +} |
| 295 | + |
| 296 | +// The abuse report type |
| 297 | +type AbuseReportNewResponseEnvelopeRequestAct string |
| 298 | + |
| 299 | +const ( |
| 300 | + AbuseReportNewResponseEnvelopeRequestActAbuseDmca AbuseReportNewResponseEnvelopeRequestAct = "abuse_dmca" |
| 301 | + AbuseReportNewResponseEnvelopeRequestActAbuseTrademark AbuseReportNewResponseEnvelopeRequestAct = "abuse_trademark" |
| 302 | + AbuseReportNewResponseEnvelopeRequestActAbuseGeneral AbuseReportNewResponseEnvelopeRequestAct = "abuse_general" |
| 303 | + AbuseReportNewResponseEnvelopeRequestActAbusePhishing AbuseReportNewResponseEnvelopeRequestAct = "abuse_phishing" |
| 304 | + AbuseReportNewResponseEnvelopeRequestActAbuseChildren AbuseReportNewResponseEnvelopeRequestAct = "abuse_children" |
| 305 | + AbuseReportNewResponseEnvelopeRequestActAbuseThreat AbuseReportNewResponseEnvelopeRequestAct = "abuse_threat" |
| 306 | + AbuseReportNewResponseEnvelopeRequestActAbuseRegistrarWhois AbuseReportNewResponseEnvelopeRequestAct = "abuse_registrar_whois" |
| 307 | + AbuseReportNewResponseEnvelopeRequestActAbuseNcsei AbuseReportNewResponseEnvelopeRequestAct = "abuse_ncsei" |
| 308 | +) |
| 309 | + |
| 310 | +func (r AbuseReportNewResponseEnvelopeRequestAct) IsKnown() bool { |
| 311 | + switch r { |
| 312 | + case AbuseReportNewResponseEnvelopeRequestActAbuseDmca, AbuseReportNewResponseEnvelopeRequestActAbuseTrademark, AbuseReportNewResponseEnvelopeRequestActAbuseGeneral, AbuseReportNewResponseEnvelopeRequestActAbusePhishing, AbuseReportNewResponseEnvelopeRequestActAbuseChildren, AbuseReportNewResponseEnvelopeRequestActAbuseThreat, AbuseReportNewResponseEnvelopeRequestActAbuseRegistrarWhois, AbuseReportNewResponseEnvelopeRequestActAbuseNcsei: |
| 313 | + return true |
| 314 | + } |
| 315 | + return false |
| 316 | +} |
0 commit comments