diff --git a/.stats.yml b/.stats.yml index f8966a9125..b0cb3255a6 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,2 +1,2 @@ -configured_endpoints: 1268 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/cloudflare%2Fcloudflare-0ca9f3bf36e4be37e5ff9fff004f125665870f7b965d04ba56aea67a98964371.yml +configured_endpoints: 1269 +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/cloudflare%2Fcloudflare-35412fd158c3e184d9aa368a2fd1c169ec542af1a1892f41155afe8df8ad79bf.yml diff --git a/api.md b/api.md index 94e742e014..7f3a94dce4 100644 --- a/api.md +++ b/api.md @@ -3361,11 +3361,21 @@ Response Types: Methods: - client.Intel.IndicatorFeeds.New(ctx context.Context, params intel.IndicatorFeedNewParams) (intel.IndicatorFeedNewResponse, error) -- client.Intel.IndicatorFeeds.Update(ctx context.Context, feedID int64, params intel.IndicatorFeedUpdateParams) (intel.IndicatorFeedUpdateResponse, error) +- client.Intel.IndicatorFeeds.Update(ctx context.Context, feedID int64, params intel.IndicatorFeedUpdateParams) (intel.IndicatorFeedUpdateResponse, error) - client.Intel.IndicatorFeeds.List(ctx context.Context, query intel.IndicatorFeedListParams) (pagination.SinglePage[intel.IndicatorFeedListResponse], error) - client.Intel.IndicatorFeeds.Data(ctx context.Context, feedID int64, query intel.IndicatorFeedDataParams) (string, error) - client.Intel.IndicatorFeeds.Get(ctx context.Context, feedID int64, query intel.IndicatorFeedGetParams) (intel.IndicatorFeedGetResponse, error) +### Snapshots + +Response Types: + +- intel.IndicatorFeedSnapshotUpdateResponse + +Methods: + +- client.Intel.IndicatorFeeds.Snapshots.Update(ctx context.Context, feedID int64, params intel.IndicatorFeedSnapshotUpdateParams) (intel.IndicatorFeedSnapshotUpdateResponse, error) + ### Permissions Response Types: @@ -6730,14 +6740,14 @@ Response Types: - cloudforce_one.Quota - cloudforce_one.RequestConstants - cloudforce_one.RequestTypes -- cloudforce_one.RequestDeleteResponseUnion +- cloudforce_one.RequestDeleteResponse Methods: - client.CloudforceOne.Requests.New(ctx context.Context, accountIdentifier string, body cloudforce_one.RequestNewParams) (cloudforce_one.Item, error) - client.CloudforceOne.Requests.Update(ctx context.Context, accountIdentifier string, requestIdentifier string, body cloudforce_one.RequestUpdateParams) (cloudforce_one.Item, error) - client.CloudforceOne.Requests.List(ctx context.Context, accountIdentifier string, body cloudforce_one.RequestListParams) (pagination.V4PagePaginationArray[cloudforce_one.ListItem], error) -- client.CloudforceOne.Requests.Delete(ctx context.Context, accountIdentifier string, requestIdentifier string) (cloudforce_one.RequestDeleteResponseUnion, error) +- client.CloudforceOne.Requests.Delete(ctx context.Context, accountIdentifier string, requestIdentifier string) (cloudforce_one.RequestDeleteResponse, error) - client.CloudforceOne.Requests.Constants(ctx context.Context, accountIdentifier string) (cloudforce_one.RequestConstants, error) - client.CloudforceOne.Requests.Get(ctx context.Context, accountIdentifier string, requestIdentifier string) (cloudforce_one.Item, error) - client.CloudforceOne.Requests.Quota(ctx context.Context, accountIdentifier string) (cloudforce_one.Quota, error) @@ -6748,13 +6758,13 @@ Methods: Response Types: - cloudforce_one.Message -- cloudforce_one.RequestMessageDeleteResponseUnion +- cloudforce_one.RequestMessageDeleteResponse Methods: - client.CloudforceOne.Requests.Message.New(ctx context.Context, accountIdentifier string, requestIdentifier string, body cloudforce_one.RequestMessageNewParams) (cloudforce_one.Message, error) - client.CloudforceOne.Requests.Message.Update(ctx context.Context, accountIdentifier string, requestIdentifier string, messageIdentifer int64, body cloudforce_one.RequestMessageUpdateParams) (cloudforce_one.Message, error) -- client.CloudforceOne.Requests.Message.Delete(ctx context.Context, accountIdentifier string, requestIdentifier string, messageIdentifer int64) (cloudforce_one.RequestMessageDeleteResponseUnion, error) +- client.CloudforceOne.Requests.Message.Delete(ctx context.Context, accountIdentifier string, requestIdentifier string, messageIdentifer int64) (cloudforce_one.RequestMessageDeleteResponse, error) - client.CloudforceOne.Requests.Message.Get(ctx context.Context, accountIdentifier string, requestIdentifier string, body cloudforce_one.RequestMessageGetParams) ([]cloudforce_one.Message, error) ### Priority @@ -6768,13 +6778,13 @@ Response Types: - cloudforce_one.Label - cloudforce_one.Priority -- cloudforce_one.RequestPriorityDeleteResponseUnion +- cloudforce_one.RequestPriorityDeleteResponse Methods: - client.CloudforceOne.Requests.Priority.New(ctx context.Context, accountIdentifier string, body cloudforce_one.RequestPriorityNewParams) (cloudforce_one.Priority, error) - client.CloudforceOne.Requests.Priority.Update(ctx context.Context, accountIdentifier string, priorityIdentifer string, body cloudforce_one.RequestPriorityUpdateParams) (cloudforce_one.Item, error) -- client.CloudforceOne.Requests.Priority.Delete(ctx context.Context, accountIdentifier string, priorityIdentifer string) (cloudforce_one.RequestPriorityDeleteResponseUnion, error) +- client.CloudforceOne.Requests.Priority.Delete(ctx context.Context, accountIdentifier string, priorityIdentifer string) (cloudforce_one.RequestPriorityDeleteResponse, error) - client.CloudforceOne.Requests.Priority.Get(ctx context.Context, accountIdentifier string, priorityIdentifer string) (cloudforce_one.Item, error) - client.CloudforceOne.Requests.Priority.Quota(ctx context.Context, accountIdentifier string) (cloudforce_one.Quota, error) diff --git a/cloudforce_one/request.go b/cloudforce_one/request.go index ce028e3612..a5865d5f35 100644 --- a/cloudforce_one/request.go +++ b/cloudforce_one/request.go @@ -6,7 +6,6 @@ import ( "context" "fmt" "net/http" - "reflect" "time" "github.com/cloudflare/cloudflare-go/v2/internal/apijson" @@ -15,7 +14,6 @@ import ( "github.com/cloudflare/cloudflare-go/v2/internal/requestconfig" "github.com/cloudflare/cloudflare-go/v2/option" "github.com/cloudflare/cloudflare-go/v2/shared" - "github.com/tidwall/gjson" ) // RequestService contains methods and other services that help with interacting @@ -93,15 +91,10 @@ func (r *RequestService) ListAutoPaging(ctx context.Context, accountIdentifier s } // Delete a Request -func (r *RequestService) Delete(ctx context.Context, accountIdentifier string, requestIdentifier string, opts ...option.RequestOption) (res *RequestDeleteResponseUnion, err error) { +func (r *RequestService) Delete(ctx context.Context, accountIdentifier string, requestIdentifier string, opts ...option.RequestOption) (res *RequestDeleteResponse, err error) { opts = append(r.Options[:], opts...) - var env RequestDeleteResponseEnvelope path := fmt.Sprintf("accounts/%s/cloudforce-one/requests/%s", accountIdentifier, requestIdentifier) - err = requestconfig.ExecuteNewRequest(ctx, http.MethodDelete, path, nil, &env, opts...) - if err != nil { - return - } - res = &env.Result + err = requestconfig.ExecuteNewRequest(ctx, http.MethodDelete, path, nil, &res, opts...) return } @@ -469,30 +462,46 @@ func (r RequestConstantsTlp) IsKnown() bool { type RequestTypes []string -// Union satisfied by [cloudforce_one.RequestDeleteResponseUnknown], -// [cloudforce_one.RequestDeleteResponseArray] or [shared.UnionString]. -type RequestDeleteResponseUnion interface { - ImplementsCloudforceOneRequestDeleteResponseUnion() +type RequestDeleteResponse struct { + Errors []shared.ResponseInfo `json:"errors,required"` + Messages []shared.ResponseInfo `json:"messages,required"` + // Whether the API call was successful + Success RequestDeleteResponseSuccess `json:"success,required"` + JSON requestDeleteResponseJSON `json:"-"` +} + +// requestDeleteResponseJSON contains the JSON metadata for the struct +// [RequestDeleteResponse] +type requestDeleteResponseJSON struct { + Errors apijson.Field + Messages apijson.Field + Success apijson.Field + raw string + ExtraFields map[string]apijson.Field +} + +func (r *RequestDeleteResponse) UnmarshalJSON(data []byte) (err error) { + return apijson.UnmarshalRoot(data, r) } -func init() { - apijson.RegisterUnion( - reflect.TypeOf((*RequestDeleteResponseUnion)(nil)).Elem(), - "", - apijson.UnionVariant{ - TypeFilter: gjson.JSON, - Type: reflect.TypeOf(RequestDeleteResponseArray{}), - }, - apijson.UnionVariant{ - TypeFilter: gjson.String, - Type: reflect.TypeOf(shared.UnionString("")), - }, - ) +func (r requestDeleteResponseJSON) RawJSON() string { + return r.raw } -type RequestDeleteResponseArray []interface{} +// Whether the API call was successful +type RequestDeleteResponseSuccess bool -func (r RequestDeleteResponseArray) ImplementsCloudforceOneRequestDeleteResponseUnion() {} +const ( + RequestDeleteResponseSuccessTrue RequestDeleteResponseSuccess = true +) + +func (r RequestDeleteResponseSuccess) IsKnown() bool { + switch r { + case RequestDeleteResponseSuccessTrue: + return true + } + return false +} type RequestNewParams struct { // Request content @@ -533,9 +542,9 @@ func (r RequestNewParamsTlp) IsKnown() bool { type RequestNewResponseEnvelope struct { Errors []shared.ResponseInfo `json:"errors,required"` Messages []shared.ResponseInfo `json:"messages,required"` - Result Item `json:"result,required"` // Whether the API call was successful Success RequestNewResponseEnvelopeSuccess `json:"success,required"` + Result Item `json:"result"` JSON requestNewResponseEnvelopeJSON `json:"-"` } @@ -544,8 +553,8 @@ type RequestNewResponseEnvelope struct { type requestNewResponseEnvelopeJSON struct { Errors apijson.Field Messages apijson.Field - Result apijson.Field Success apijson.Field + Result apijson.Field raw string ExtraFields map[string]apijson.Field } @@ -612,9 +621,9 @@ func (r RequestUpdateParamsTlp) IsKnown() bool { type RequestUpdateResponseEnvelope struct { Errors []shared.ResponseInfo `json:"errors,required"` Messages []shared.ResponseInfo `json:"messages,required"` - Result Item `json:"result,required"` // Whether the API call was successful Success RequestUpdateResponseEnvelopeSuccess `json:"success,required"` + Result Item `json:"result"` JSON requestUpdateResponseEnvelopeJSON `json:"-"` } @@ -623,8 +632,8 @@ type RequestUpdateResponseEnvelope struct { type requestUpdateResponseEnvelopeJSON struct { Errors apijson.Field Messages apijson.Field - Result apijson.Field Success apijson.Field + Result apijson.Field raw string ExtraFields map[string]apijson.Field } @@ -715,55 +724,12 @@ func (r RequestListParamsStatus) IsKnown() bool { return false } -type RequestDeleteResponseEnvelope struct { - Errors []shared.ResponseInfo `json:"errors,required"` - Messages []shared.ResponseInfo `json:"messages,required"` - Result RequestDeleteResponseUnion `json:"result,required"` - // Whether the API call was successful - Success RequestDeleteResponseEnvelopeSuccess `json:"success,required"` - JSON requestDeleteResponseEnvelopeJSON `json:"-"` -} - -// requestDeleteResponseEnvelopeJSON contains the JSON metadata for the struct -// [RequestDeleteResponseEnvelope] -type requestDeleteResponseEnvelopeJSON struct { - Errors apijson.Field - Messages apijson.Field - Result apijson.Field - Success apijson.Field - raw string - ExtraFields map[string]apijson.Field -} - -func (r *RequestDeleteResponseEnvelope) UnmarshalJSON(data []byte) (err error) { - return apijson.UnmarshalRoot(data, r) -} - -func (r requestDeleteResponseEnvelopeJSON) RawJSON() string { - return r.raw -} - -// Whether the API call was successful -type RequestDeleteResponseEnvelopeSuccess bool - -const ( - RequestDeleteResponseEnvelopeSuccessTrue RequestDeleteResponseEnvelopeSuccess = true -) - -func (r RequestDeleteResponseEnvelopeSuccess) IsKnown() bool { - switch r { - case RequestDeleteResponseEnvelopeSuccessTrue: - return true - } - return false -} - type RequestConstantsResponseEnvelope struct { Errors []shared.ResponseInfo `json:"errors,required"` Messages []shared.ResponseInfo `json:"messages,required"` - Result RequestConstants `json:"result,required"` // Whether the API call was successful Success RequestConstantsResponseEnvelopeSuccess `json:"success,required"` + Result RequestConstants `json:"result"` JSON requestConstantsResponseEnvelopeJSON `json:"-"` } @@ -772,8 +738,8 @@ type RequestConstantsResponseEnvelope struct { type requestConstantsResponseEnvelopeJSON struct { Errors apijson.Field Messages apijson.Field - Result apijson.Field Success apijson.Field + Result apijson.Field raw string ExtraFields map[string]apijson.Field } @@ -804,9 +770,9 @@ func (r RequestConstantsResponseEnvelopeSuccess) IsKnown() bool { type RequestGetResponseEnvelope struct { Errors []shared.ResponseInfo `json:"errors,required"` Messages []shared.ResponseInfo `json:"messages,required"` - Result Item `json:"result,required"` // Whether the API call was successful Success RequestGetResponseEnvelopeSuccess `json:"success,required"` + Result Item `json:"result"` JSON requestGetResponseEnvelopeJSON `json:"-"` } @@ -815,8 +781,8 @@ type RequestGetResponseEnvelope struct { type requestGetResponseEnvelopeJSON struct { Errors apijson.Field Messages apijson.Field - Result apijson.Field Success apijson.Field + Result apijson.Field raw string ExtraFields map[string]apijson.Field } @@ -847,9 +813,9 @@ func (r RequestGetResponseEnvelopeSuccess) IsKnown() bool { type RequestQuotaResponseEnvelope struct { Errors []shared.ResponseInfo `json:"errors,required"` Messages []shared.ResponseInfo `json:"messages,required"` - Result Quota `json:"result,required"` // Whether the API call was successful Success RequestQuotaResponseEnvelopeSuccess `json:"success,required"` + Result Quota `json:"result"` JSON requestQuotaResponseEnvelopeJSON `json:"-"` } @@ -858,8 +824,8 @@ type RequestQuotaResponseEnvelope struct { type requestQuotaResponseEnvelopeJSON struct { Errors apijson.Field Messages apijson.Field - Result apijson.Field Success apijson.Field + Result apijson.Field raw string ExtraFields map[string]apijson.Field } @@ -890,9 +856,9 @@ func (r RequestQuotaResponseEnvelopeSuccess) IsKnown() bool { type RequestTypesResponseEnvelope struct { Errors []shared.ResponseInfo `json:"errors,required"` Messages []shared.ResponseInfo `json:"messages,required"` - Result RequestTypes `json:"result,required"` // Whether the API call was successful Success RequestTypesResponseEnvelopeSuccess `json:"success,required"` + Result RequestTypes `json:"result"` JSON requestTypesResponseEnvelopeJSON `json:"-"` } @@ -901,8 +867,8 @@ type RequestTypesResponseEnvelope struct { type requestTypesResponseEnvelopeJSON struct { Errors apijson.Field Messages apijson.Field - Result apijson.Field Success apijson.Field + Result apijson.Field raw string ExtraFields map[string]apijson.Field } diff --git a/cloudforce_one/requestmessage.go b/cloudforce_one/requestmessage.go index b5a88e43b5..f3949be2ee 100644 --- a/cloudforce_one/requestmessage.go +++ b/cloudforce_one/requestmessage.go @@ -6,7 +6,6 @@ import ( "context" "fmt" "net/http" - "reflect" "time" "github.com/cloudflare/cloudflare-go/v2/internal/apijson" @@ -14,7 +13,6 @@ import ( "github.com/cloudflare/cloudflare-go/v2/internal/requestconfig" "github.com/cloudflare/cloudflare-go/v2/option" "github.com/cloudflare/cloudflare-go/v2/shared" - "github.com/tidwall/gjson" ) // RequestMessageService contains methods and other services that help with @@ -64,15 +62,10 @@ func (r *RequestMessageService) Update(ctx context.Context, accountIdentifier st } // Delete a Request Message -func (r *RequestMessageService) Delete(ctx context.Context, accountIdentifier string, requestIdentifier string, messageIdentifer int64, opts ...option.RequestOption) (res *RequestMessageDeleteResponseUnion, err error) { +func (r *RequestMessageService) Delete(ctx context.Context, accountIdentifier string, requestIdentifier string, messageIdentifer int64, opts ...option.RequestOption) (res *RequestMessageDeleteResponse, err error) { opts = append(r.Options[:], opts...) - var env RequestMessageDeleteResponseEnvelope path := fmt.Sprintf("accounts/%s/cloudforce-one/requests/%s/message/%v", accountIdentifier, requestIdentifier, messageIdentifer) - err = requestconfig.ExecuteNewRequest(ctx, http.MethodDelete, path, nil, &env, opts...) - if err != nil { - return - } - res = &env.Result + err = requestconfig.ExecuteNewRequest(ctx, http.MethodDelete, path, nil, &res, opts...) return } @@ -125,30 +118,45 @@ func (r messageJSON) RawJSON() string { return r.raw } -// Union satisfied by [cloudforce_one.RequestMessageDeleteResponseUnknown], -// [cloudforce_one.RequestMessageDeleteResponseArray] or [shared.UnionString]. -type RequestMessageDeleteResponseUnion interface { - ImplementsCloudforceOneRequestMessageDeleteResponseUnion() +type RequestMessageDeleteResponse struct { + Errors []shared.ResponseInfo `json:"errors,required"` + Messages []shared.ResponseInfo `json:"messages,required"` + // Whether the API call was successful + Success RequestMessageDeleteResponseSuccess `json:"success,required"` + JSON requestMessageDeleteResponseJSON `json:"-"` +} + +// requestMessageDeleteResponseJSON contains the JSON metadata for the struct +// [RequestMessageDeleteResponse] +type requestMessageDeleteResponseJSON struct { + Errors apijson.Field + Messages apijson.Field + Success apijson.Field + raw string + ExtraFields map[string]apijson.Field +} + +func (r *RequestMessageDeleteResponse) UnmarshalJSON(data []byte) (err error) { + return apijson.UnmarshalRoot(data, r) } -func init() { - apijson.RegisterUnion( - reflect.TypeOf((*RequestMessageDeleteResponseUnion)(nil)).Elem(), - "", - apijson.UnionVariant{ - TypeFilter: gjson.JSON, - Type: reflect.TypeOf(RequestMessageDeleteResponseArray{}), - }, - apijson.UnionVariant{ - TypeFilter: gjson.String, - Type: reflect.TypeOf(shared.UnionString("")), - }, - ) +func (r requestMessageDeleteResponseJSON) RawJSON() string { + return r.raw } -type RequestMessageDeleteResponseArray []interface{} +// Whether the API call was successful +type RequestMessageDeleteResponseSuccess bool + +const ( + RequestMessageDeleteResponseSuccessTrue RequestMessageDeleteResponseSuccess = true +) -func (r RequestMessageDeleteResponseArray) ImplementsCloudforceOneRequestMessageDeleteResponseUnion() { +func (r RequestMessageDeleteResponseSuccess) IsKnown() bool { + switch r { + case RequestMessageDeleteResponseSuccessTrue: + return true + } + return false } type RequestMessageNewParams struct { @@ -163,9 +171,9 @@ func (r RequestMessageNewParams) MarshalJSON() (data []byte, err error) { type RequestMessageNewResponseEnvelope struct { Errors []shared.ResponseInfo `json:"errors,required"` Messages []shared.ResponseInfo `json:"messages,required"` - Result Message `json:"result,required"` // Whether the API call was successful Success RequestMessageNewResponseEnvelopeSuccess `json:"success,required"` + Result Message `json:"result"` JSON requestMessageNewResponseEnvelopeJSON `json:"-"` } @@ -174,8 +182,8 @@ type RequestMessageNewResponseEnvelope struct { type requestMessageNewResponseEnvelopeJSON struct { Errors apijson.Field Messages apijson.Field - Result apijson.Field Success apijson.Field + Result apijson.Field raw string ExtraFields map[string]apijson.Field } @@ -242,9 +250,9 @@ func (r RequestMessageUpdateParamsTlp) IsKnown() bool { type RequestMessageUpdateResponseEnvelope struct { Errors []shared.ResponseInfo `json:"errors,required"` Messages []shared.ResponseInfo `json:"messages,required"` - Result Message `json:"result,required"` // Whether the API call was successful Success RequestMessageUpdateResponseEnvelopeSuccess `json:"success,required"` + Result Message `json:"result"` JSON requestMessageUpdateResponseEnvelopeJSON `json:"-"` } @@ -253,8 +261,8 @@ type RequestMessageUpdateResponseEnvelope struct { type requestMessageUpdateResponseEnvelopeJSON struct { Errors apijson.Field Messages apijson.Field - Result apijson.Field Success apijson.Field + Result apijson.Field raw string ExtraFields map[string]apijson.Field } @@ -282,49 +290,6 @@ func (r RequestMessageUpdateResponseEnvelopeSuccess) IsKnown() bool { return false } -type RequestMessageDeleteResponseEnvelope struct { - Errors []shared.ResponseInfo `json:"errors,required"` - Messages []shared.ResponseInfo `json:"messages,required"` - Result RequestMessageDeleteResponseUnion `json:"result,required"` - // Whether the API call was successful - Success RequestMessageDeleteResponseEnvelopeSuccess `json:"success,required"` - JSON requestMessageDeleteResponseEnvelopeJSON `json:"-"` -} - -// requestMessageDeleteResponseEnvelopeJSON contains the JSON metadata for the -// struct [RequestMessageDeleteResponseEnvelope] -type requestMessageDeleteResponseEnvelopeJSON struct { - Errors apijson.Field - Messages apijson.Field - Result apijson.Field - Success apijson.Field - raw string - ExtraFields map[string]apijson.Field -} - -func (r *RequestMessageDeleteResponseEnvelope) UnmarshalJSON(data []byte) (err error) { - return apijson.UnmarshalRoot(data, r) -} - -func (r requestMessageDeleteResponseEnvelopeJSON) RawJSON() string { - return r.raw -} - -// Whether the API call was successful -type RequestMessageDeleteResponseEnvelopeSuccess bool - -const ( - RequestMessageDeleteResponseEnvelopeSuccessTrue RequestMessageDeleteResponseEnvelopeSuccess = true -) - -func (r RequestMessageDeleteResponseEnvelopeSuccess) IsKnown() bool { - switch r { - case RequestMessageDeleteResponseEnvelopeSuccessTrue: - return true - } - return false -} - type RequestMessageGetParams struct { // Page number of results Page param.Field[int64] `json:"page,required"` @@ -363,9 +328,9 @@ func (r RequestMessageGetParamsSortOrder) IsKnown() bool { type RequestMessageGetResponseEnvelope struct { Errors []shared.ResponseInfo `json:"errors,required"` Messages []shared.ResponseInfo `json:"messages,required"` - Result []Message `json:"result,required"` // Whether the API call was successful Success RequestMessageGetResponseEnvelopeSuccess `json:"success,required"` + Result []Message `json:"result"` JSON requestMessageGetResponseEnvelopeJSON `json:"-"` } @@ -374,8 +339,8 @@ type RequestMessageGetResponseEnvelope struct { type requestMessageGetResponseEnvelopeJSON struct { Errors apijson.Field Messages apijson.Field - Result apijson.Field Success apijson.Field + Result apijson.Field raw string ExtraFields map[string]apijson.Field } diff --git a/cloudforce_one/requestpriority.go b/cloudforce_one/requestpriority.go index 702df8b577..eef29460bf 100644 --- a/cloudforce_one/requestpriority.go +++ b/cloudforce_one/requestpriority.go @@ -6,7 +6,6 @@ import ( "context" "fmt" "net/http" - "reflect" "time" "github.com/cloudflare/cloudflare-go/v2/internal/apijson" @@ -14,7 +13,6 @@ import ( "github.com/cloudflare/cloudflare-go/v2/internal/requestconfig" "github.com/cloudflare/cloudflare-go/v2/option" "github.com/cloudflare/cloudflare-go/v2/shared" - "github.com/tidwall/gjson" ) // RequestPriorityService contains methods and other services that help with @@ -62,15 +60,10 @@ func (r *RequestPriorityService) Update(ctx context.Context, accountIdentifier s } // Delete a Priority Intelligence Report -func (r *RequestPriorityService) Delete(ctx context.Context, accountIdentifier string, priorityIdentifer string, opts ...option.RequestOption) (res *RequestPriorityDeleteResponseUnion, err error) { +func (r *RequestPriorityService) Delete(ctx context.Context, accountIdentifier string, priorityIdentifer string, opts ...option.RequestOption) (res *RequestPriorityDeleteResponse, err error) { opts = append(r.Options[:], opts...) - var env RequestPriorityDeleteResponseEnvelope path := fmt.Sprintf("accounts/%s/cloudforce-one/requests/priority/%s", accountIdentifier, priorityIdentifer) - err = requestconfig.ExecuteNewRequest(ctx, http.MethodDelete, path, nil, &env, opts...) - if err != nil { - return - } - res = &env.Result + err = requestconfig.ExecuteNewRequest(ctx, http.MethodDelete, path, nil, &res, opts...) return } @@ -196,30 +189,45 @@ func (r PriorityEditTlp) IsKnown() bool { return false } -// Union satisfied by [cloudforce_one.RequestPriorityDeleteResponseUnknown], -// [cloudforce_one.RequestPriorityDeleteResponseArray] or [shared.UnionString]. -type RequestPriorityDeleteResponseUnion interface { - ImplementsCloudforceOneRequestPriorityDeleteResponseUnion() +type RequestPriorityDeleteResponse struct { + Errors []shared.ResponseInfo `json:"errors,required"` + Messages []shared.ResponseInfo `json:"messages,required"` + // Whether the API call was successful + Success RequestPriorityDeleteResponseSuccess `json:"success,required"` + JSON requestPriorityDeleteResponseJSON `json:"-"` } -func init() { - apijson.RegisterUnion( - reflect.TypeOf((*RequestPriorityDeleteResponseUnion)(nil)).Elem(), - "", - apijson.UnionVariant{ - TypeFilter: gjson.JSON, - Type: reflect.TypeOf(RequestPriorityDeleteResponseArray{}), - }, - apijson.UnionVariant{ - TypeFilter: gjson.String, - Type: reflect.TypeOf(shared.UnionString("")), - }, - ) +// requestPriorityDeleteResponseJSON contains the JSON metadata for the struct +// [RequestPriorityDeleteResponse] +type requestPriorityDeleteResponseJSON struct { + Errors apijson.Field + Messages apijson.Field + Success apijson.Field + raw string + ExtraFields map[string]apijson.Field } -type RequestPriorityDeleteResponseArray []interface{} +func (r *RequestPriorityDeleteResponse) UnmarshalJSON(data []byte) (err error) { + return apijson.UnmarshalRoot(data, r) +} -func (r RequestPriorityDeleteResponseArray) ImplementsCloudforceOneRequestPriorityDeleteResponseUnion() { +func (r requestPriorityDeleteResponseJSON) RawJSON() string { + return r.raw +} + +// Whether the API call was successful +type RequestPriorityDeleteResponseSuccess bool + +const ( + RequestPriorityDeleteResponseSuccessTrue RequestPriorityDeleteResponseSuccess = true +) + +func (r RequestPriorityDeleteResponseSuccess) IsKnown() bool { + switch r { + case RequestPriorityDeleteResponseSuccessTrue: + return true + } + return false } type RequestPriorityNewParams struct { @@ -233,9 +241,9 @@ func (r RequestPriorityNewParams) MarshalJSON() (data []byte, err error) { type RequestPriorityNewResponseEnvelope struct { Errors []shared.ResponseInfo `json:"errors,required"` Messages []shared.ResponseInfo `json:"messages,required"` - Result Priority `json:"result,required"` // Whether the API call was successful Success RequestPriorityNewResponseEnvelopeSuccess `json:"success,required"` + Result Priority `json:"result"` JSON requestPriorityNewResponseEnvelopeJSON `json:"-"` } @@ -244,8 +252,8 @@ type RequestPriorityNewResponseEnvelope struct { type requestPriorityNewResponseEnvelopeJSON struct { Errors apijson.Field Messages apijson.Field - Result apijson.Field Success apijson.Field + Result apijson.Field raw string ExtraFields map[string]apijson.Field } @@ -284,9 +292,9 @@ func (r RequestPriorityUpdateParams) MarshalJSON() (data []byte, err error) { type RequestPriorityUpdateResponseEnvelope struct { Errors []shared.ResponseInfo `json:"errors,required"` Messages []shared.ResponseInfo `json:"messages,required"` - Result Item `json:"result,required"` // Whether the API call was successful Success RequestPriorityUpdateResponseEnvelopeSuccess `json:"success,required"` + Result Item `json:"result"` JSON requestPriorityUpdateResponseEnvelopeJSON `json:"-"` } @@ -295,8 +303,8 @@ type RequestPriorityUpdateResponseEnvelope struct { type requestPriorityUpdateResponseEnvelopeJSON struct { Errors apijson.Field Messages apijson.Field - Result apijson.Field Success apijson.Field + Result apijson.Field raw string ExtraFields map[string]apijson.Field } @@ -324,55 +332,12 @@ func (r RequestPriorityUpdateResponseEnvelopeSuccess) IsKnown() bool { return false } -type RequestPriorityDeleteResponseEnvelope struct { - Errors []shared.ResponseInfo `json:"errors,required"` - Messages []shared.ResponseInfo `json:"messages,required"` - Result RequestPriorityDeleteResponseUnion `json:"result,required"` - // Whether the API call was successful - Success RequestPriorityDeleteResponseEnvelopeSuccess `json:"success,required"` - JSON requestPriorityDeleteResponseEnvelopeJSON `json:"-"` -} - -// requestPriorityDeleteResponseEnvelopeJSON contains the JSON metadata for the -// struct [RequestPriorityDeleteResponseEnvelope] -type requestPriorityDeleteResponseEnvelopeJSON struct { - Errors apijson.Field - Messages apijson.Field - Result apijson.Field - Success apijson.Field - raw string - ExtraFields map[string]apijson.Field -} - -func (r *RequestPriorityDeleteResponseEnvelope) UnmarshalJSON(data []byte) (err error) { - return apijson.UnmarshalRoot(data, r) -} - -func (r requestPriorityDeleteResponseEnvelopeJSON) RawJSON() string { - return r.raw -} - -// Whether the API call was successful -type RequestPriorityDeleteResponseEnvelopeSuccess bool - -const ( - RequestPriorityDeleteResponseEnvelopeSuccessTrue RequestPriorityDeleteResponseEnvelopeSuccess = true -) - -func (r RequestPriorityDeleteResponseEnvelopeSuccess) IsKnown() bool { - switch r { - case RequestPriorityDeleteResponseEnvelopeSuccessTrue: - return true - } - return false -} - type RequestPriorityGetResponseEnvelope struct { Errors []shared.ResponseInfo `json:"errors,required"` Messages []shared.ResponseInfo `json:"messages,required"` - Result Item `json:"result,required"` // Whether the API call was successful Success RequestPriorityGetResponseEnvelopeSuccess `json:"success,required"` + Result Item `json:"result"` JSON requestPriorityGetResponseEnvelopeJSON `json:"-"` } @@ -381,8 +346,8 @@ type RequestPriorityGetResponseEnvelope struct { type requestPriorityGetResponseEnvelopeJSON struct { Errors apijson.Field Messages apijson.Field - Result apijson.Field Success apijson.Field + Result apijson.Field raw string ExtraFields map[string]apijson.Field } @@ -413,9 +378,9 @@ func (r RequestPriorityGetResponseEnvelopeSuccess) IsKnown() bool { type RequestPriorityQuotaResponseEnvelope struct { Errors []shared.ResponseInfo `json:"errors,required"` Messages []shared.ResponseInfo `json:"messages,required"` - Result Quota `json:"result,required"` // Whether the API call was successful Success RequestPriorityQuotaResponseEnvelopeSuccess `json:"success,required"` + Result Quota `json:"result"` JSON requestPriorityQuotaResponseEnvelopeJSON `json:"-"` } @@ -424,8 +389,8 @@ type RequestPriorityQuotaResponseEnvelope struct { type requestPriorityQuotaResponseEnvelopeJSON struct { Errors apijson.Field Messages apijson.Field - Result apijson.Field Success apijson.Field + Result apijson.Field raw string ExtraFields map[string]apijson.Field } diff --git a/intel/indicatorfeed.go b/intel/indicatorfeed.go index 018d96fc62..74e4a0bef0 100644 --- a/intel/indicatorfeed.go +++ b/intel/indicatorfeed.go @@ -23,6 +23,7 @@ import ( // instead. type IndicatorFeedService struct { Options []option.RequestOption + Snapshots *IndicatorFeedSnapshotService Permissions *IndicatorFeedPermissionService } @@ -32,6 +33,7 @@ type IndicatorFeedService struct { func NewIndicatorFeedService(opts ...option.RequestOption) (r *IndicatorFeedService) { r = &IndicatorFeedService{} r.Options = opts + r.Snapshots = NewIndicatorFeedSnapshotService(opts...) r.Permissions = NewIndicatorFeedPermissionService(opts...) return } @@ -49,11 +51,11 @@ func (r *IndicatorFeedService) New(ctx context.Context, params IndicatorFeedNewP return } -// Update indicator feed data +// Update indicator feed metadata func (r *IndicatorFeedService) Update(ctx context.Context, feedID int64, params IndicatorFeedUpdateParams, opts ...option.RequestOption) (res *IndicatorFeedUpdateResponse, err error) { opts = append(r.Options[:], opts...) var env IndicatorFeedUpdateResponseEnvelope - path := fmt.Sprintf("accounts/%s/intel/indicator-feeds/%v/snapshot", params.AccountID, feedID) + path := fmt.Sprintf("accounts/%s/intel/indicator-feeds/%v", params.AccountID, feedID) err = requestconfig.ExecuteNewRequest(ctx, http.MethodPut, path, params, &env, opts...) if err != nil { return @@ -148,23 +150,35 @@ func (r indicatorFeedNewResponseJSON) RawJSON() string { } type IndicatorFeedUpdateResponse struct { - // Feed id - FileID int64 `json:"file_id"` - // Name of the file unified in our system - Filename string `json:"filename"` - // Current status of upload, should be unified - Status string `json:"status"` - JSON indicatorFeedUpdateResponseJSON `json:"-"` + // The unique identifier for the indicator feed + ID int64 `json:"id"` + // The date and time when the data entry was created + CreatedOn time.Time `json:"created_on" format:"date-time"` + // The description of the example test + Description string `json:"description"` + // Whether the indicator feed can be attributed to a provider + IsAttributable bool `json:"is_attributable"` + // Whether the indicator feed is exposed to customers + IsPublic bool `json:"is_public"` + // The date and time when the data entry was last modified + ModifiedOn time.Time `json:"modified_on" format:"date-time"` + // The name of the indicator feed + Name string `json:"name"` + JSON indicatorFeedUpdateResponseJSON `json:"-"` } // indicatorFeedUpdateResponseJSON contains the JSON metadata for the struct // [IndicatorFeedUpdateResponse] type indicatorFeedUpdateResponseJSON struct { - FileID apijson.Field - Filename apijson.Field - Status apijson.Field - raw string - ExtraFields map[string]apijson.Field + ID apijson.Field + CreatedOn apijson.Field + Description apijson.Field + IsAttributable apijson.Field + IsPublic apijson.Field + ModifiedOn apijson.Field + Name apijson.Field + raw string + ExtraFields map[string]apijson.Field } func (r *IndicatorFeedUpdateResponse) UnmarshalJSON(data []byte) (err error) { @@ -331,8 +345,12 @@ func (r IndicatorFeedNewResponseEnvelopeSuccess) IsKnown() bool { type IndicatorFeedUpdateParams struct { // Identifier AccountID param.Field[string] `path:"account_id,required"` - // The file to upload - Source param.Field[string] `json:"source"` + // The new description of the feed + FeedDescription param.Field[string] `json:"feed_description"` + // The new is_attributable value of the feed + IsAttributable param.Field[bool] `json:"is_attributable"` + // The new is_public value of the feed + IsPublic param.Field[bool] `json:"is_public"` } func (r IndicatorFeedUpdateParams) MarshalJSON() (data []byte, err error) { diff --git a/intel/indicatorfeed_test.go b/intel/indicatorfeed_test.go index 78e4e79f04..e3f2fb800e 100644 --- a/intel/indicatorfeed_test.go +++ b/intel/indicatorfeed_test.go @@ -42,7 +42,6 @@ func TestIndicatorFeedNewWithOptionalParams(t *testing.T) { } func TestIndicatorFeedUpdateWithOptionalParams(t *testing.T) { - t.Skip("TODO: investigate broken test") baseURL := "http://localhost:4010" if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok { baseURL = envURL @@ -59,8 +58,10 @@ func TestIndicatorFeedUpdateWithOptionalParams(t *testing.T) { context.TODO(), int64(12), intel.IndicatorFeedUpdateParams{ - AccountID: cloudflare.F("023e105f4ecef8ad9ca31a8372d0c353"), - Source: cloudflare.F("@/Users/me/test.stix2"), + AccountID: cloudflare.F("023e105f4ecef8ad9ca31a8372d0c353"), + FeedDescription: cloudflare.F("This is an example description"), + IsAttributable: cloudflare.F(true), + IsPublic: cloudflare.F(true), }, ) if err != nil { diff --git a/intel/indicatorfeedsnapshot.go b/intel/indicatorfeedsnapshot.go new file mode 100644 index 0000000000..0e36b78bc0 --- /dev/null +++ b/intel/indicatorfeedsnapshot.go @@ -0,0 +1,128 @@ +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +package intel + +import ( + "context" + "fmt" + "net/http" + + "github.com/cloudflare/cloudflare-go/v2/internal/apijson" + "github.com/cloudflare/cloudflare-go/v2/internal/param" + "github.com/cloudflare/cloudflare-go/v2/internal/requestconfig" + "github.com/cloudflare/cloudflare-go/v2/option" + "github.com/cloudflare/cloudflare-go/v2/shared" +) + +// IndicatorFeedSnapshotService contains methods and other services that help with +// interacting with the cloudflare API. Note, unlike clients, this service does not +// read variables from the environment automatically. You should not instantiate +// this service directly, and instead use the [NewIndicatorFeedSnapshotService] +// method instead. +type IndicatorFeedSnapshotService struct { + Options []option.RequestOption +} + +// NewIndicatorFeedSnapshotService generates a new service that applies the given +// options to each request. These options are applied after the parent client's +// options (if there is one), and before any request-specific options. +func NewIndicatorFeedSnapshotService(opts ...option.RequestOption) (r *IndicatorFeedSnapshotService) { + r = &IndicatorFeedSnapshotService{} + r.Options = opts + return +} + +// Update indicator feed data +func (r *IndicatorFeedSnapshotService) Update(ctx context.Context, feedID int64, params IndicatorFeedSnapshotUpdateParams, opts ...option.RequestOption) (res *IndicatorFeedSnapshotUpdateResponse, err error) { + opts = append(r.Options[:], opts...) + var env IndicatorFeedSnapshotUpdateResponseEnvelope + path := fmt.Sprintf("accounts/%s/intel/indicator-feeds/%v/snapshot", params.AccountID, feedID) + err = requestconfig.ExecuteNewRequest(ctx, http.MethodPut, path, params, &env, opts...) + if err != nil { + return + } + res = &env.Result + return +} + +type IndicatorFeedSnapshotUpdateResponse struct { + // Feed id + FileID int64 `json:"file_id"` + // Name of the file unified in our system + Filename string `json:"filename"` + // Current status of upload, should be unified + Status string `json:"status"` + JSON indicatorFeedSnapshotUpdateResponseJSON `json:"-"` +} + +// indicatorFeedSnapshotUpdateResponseJSON contains the JSON metadata for the +// struct [IndicatorFeedSnapshotUpdateResponse] +type indicatorFeedSnapshotUpdateResponseJSON struct { + FileID apijson.Field + Filename apijson.Field + Status apijson.Field + raw string + ExtraFields map[string]apijson.Field +} + +func (r *IndicatorFeedSnapshotUpdateResponse) UnmarshalJSON(data []byte) (err error) { + return apijson.UnmarshalRoot(data, r) +} + +func (r indicatorFeedSnapshotUpdateResponseJSON) RawJSON() string { + return r.raw +} + +type IndicatorFeedSnapshotUpdateParams struct { + // Identifier + AccountID param.Field[string] `path:"account_id,required"` + // The file to upload + Source param.Field[string] `json:"source"` +} + +func (r IndicatorFeedSnapshotUpdateParams) MarshalJSON() (data []byte, err error) { + return apijson.MarshalRoot(r) +} + +type IndicatorFeedSnapshotUpdateResponseEnvelope struct { + Errors []shared.ResponseInfo `json:"errors,required"` + Messages []shared.ResponseInfo `json:"messages,required"` + // Whether the API call was successful + Success IndicatorFeedSnapshotUpdateResponseEnvelopeSuccess `json:"success,required"` + Result IndicatorFeedSnapshotUpdateResponse `json:"result"` + JSON indicatorFeedSnapshotUpdateResponseEnvelopeJSON `json:"-"` +} + +// indicatorFeedSnapshotUpdateResponseEnvelopeJSON contains the JSON metadata for +// the struct [IndicatorFeedSnapshotUpdateResponseEnvelope] +type indicatorFeedSnapshotUpdateResponseEnvelopeJSON struct { + Errors apijson.Field + Messages apijson.Field + Success apijson.Field + Result apijson.Field + raw string + ExtraFields map[string]apijson.Field +} + +func (r *IndicatorFeedSnapshotUpdateResponseEnvelope) UnmarshalJSON(data []byte) (err error) { + return apijson.UnmarshalRoot(data, r) +} + +func (r indicatorFeedSnapshotUpdateResponseEnvelopeJSON) RawJSON() string { + return r.raw +} + +// Whether the API call was successful +type IndicatorFeedSnapshotUpdateResponseEnvelopeSuccess bool + +const ( + IndicatorFeedSnapshotUpdateResponseEnvelopeSuccessTrue IndicatorFeedSnapshotUpdateResponseEnvelopeSuccess = true +) + +func (r IndicatorFeedSnapshotUpdateResponseEnvelopeSuccess) IsKnown() bool { + switch r { + case IndicatorFeedSnapshotUpdateResponseEnvelopeSuccessTrue: + return true + } + return false +} diff --git a/intel/indicatorfeedsnapshot_test.go b/intel/indicatorfeedsnapshot_test.go new file mode 100644 index 0000000000..1744ee1930 --- /dev/null +++ b/intel/indicatorfeedsnapshot_test.go @@ -0,0 +1,46 @@ +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +package intel_test + +import ( + "context" + "errors" + "os" + "testing" + + "github.com/cloudflare/cloudflare-go/v2" + "github.com/cloudflare/cloudflare-go/v2/intel" + "github.com/cloudflare/cloudflare-go/v2/internal/testutil" + "github.com/cloudflare/cloudflare-go/v2/option" +) + +func TestIndicatorFeedSnapshotUpdateWithOptionalParams(t *testing.T) { + t.Skip("TODO: investigate broken test") + baseURL := "http://localhost:4010" + if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok { + baseURL = envURL + } + if !testutil.CheckTestServer(t, baseURL) { + return + } + client := cloudflare.NewClient( + option.WithBaseURL(baseURL), + option.WithAPIKey("144c9defac04969c7bfad8efaa8ea194"), + option.WithAPIEmail("user@example.com"), + ) + _, err := client.Intel.IndicatorFeeds.Snapshots.Update( + context.TODO(), + int64(12), + intel.IndicatorFeedSnapshotUpdateParams{ + AccountID: cloudflare.F("023e105f4ecef8ad9ca31a8372d0c353"), + Source: cloudflare.F("@/Users/me/test.stix2"), + }, + ) + if err != nil { + var apierr *cloudflare.Error + if errors.As(err, &apierr) { + t.Log(string(apierr.DumpRequest(true))) + } + t.Fatalf("err should be nil: %s", err.Error()) + } +} diff --git a/intel/whois.go b/intel/whois.go index ece63a5b8f..5655c7c1a8 100644 --- a/intel/whois.go +++ b/intel/whois.go @@ -259,9 +259,9 @@ func (r WhoisGetParams) URLQuery() (v url.Values) { type WhoisGetResponseEnvelope struct { Errors []shared.ResponseInfo `json:"errors,required"` Messages []shared.ResponseInfo `json:"messages,required"` - Result WhoisGetResponse `json:"result,required"` // Whether the API call was successful Success WhoisGetResponseEnvelopeSuccess `json:"success,required"` + Result WhoisGetResponse `json:"result"` JSON whoisGetResponseEnvelopeJSON `json:"-"` } @@ -270,8 +270,8 @@ type WhoisGetResponseEnvelope struct { type whoisGetResponseEnvelopeJSON struct { Errors apijson.Field Messages apijson.Field - Result apijson.Field Success apijson.Field + Result apijson.Field raw string ExtraFields map[string]apijson.Field } diff --git a/shared/union.go b/shared/union.go index 7537786749..212561aacd 100644 --- a/shared/union.go +++ b/shared/union.go @@ -166,9 +166,6 @@ func (UnionString) ImplementsOriginPostQuantumEncryptionOriginPostQuantumEncrypt } func (UnionString) ImplementsHostnamesSettingValueUnionParam() {} func (UnionString) ImplementsHostnamesSettingValueUnion() {} -func (UnionString) ImplementsCloudforceOneRequestDeleteResponseUnion() {} -func (UnionString) ImplementsCloudforceOneRequestMessageDeleteResponseUnion() {} -func (UnionString) ImplementsCloudforceOneRequestPriorityDeleteResponseUnion() {} func (UnionString) ImplementsEventNotificationsR2ConfigurationQueueDeleteResponseUnion() {} type UnionInt int64 diff --git a/workers/ai.go b/workers/ai.go index a19742b0f1..274b13f36f 100644 --- a/workers/ai.go +++ b/workers/ai.go @@ -55,8 +55,7 @@ func (r *AIService) Run(ctx context.Context, modelName string, params AIRunParam } // Union satisfied by [workers.AIRunResponseTextClassification], -// [shared.UnionString], [shared.UnionString], -// [workers.AIRunResponseSentenceSimilarity], +// [shared.UnionString], [workers.AIRunResponseSentenceSimilarity], // [workers.AIRunResponseTextEmbeddings], [workers.AIRunResponseSpeechRecognition], // [workers.AIRunResponseImageClassification], // [workers.AIRunResponseObjectDetection], [workers.AIRunResponseObject], @@ -78,10 +77,6 @@ func init() { TypeFilter: gjson.String, Type: reflect.TypeOf(shared.UnionString("")), }, - apijson.UnionVariant{ - TypeFilter: gjson.String, - Type: reflect.TypeOf(shared.UnionString("")), - }, apijson.UnionVariant{ TypeFilter: gjson.JSON, Type: reflect.TypeOf(AIRunResponseSentenceSimilarity{}),