Skip to content

Commit

Permalink
feat(api): OpenAPI spec update via Stainless API (#1878)
Browse files Browse the repository at this point in the history
  • Loading branch information
stainless-app[bot] authored and stainless-bot committed May 7, 2024
1 parent e1bbcc9 commit a6cc625
Show file tree
Hide file tree
Showing 3 changed files with 182 additions and 48 deletions.
2 changes: 1 addition & 1 deletion .stats.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
configured_endpoints: 1259
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/cloudflare%2Fcloudflare-9e7278b59ca6d3312a49ec919b139cdc626476b556f93923d70aeaf39c5c7bcf.yml
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/cloudflare%2Fcloudflare-66dffe82f1ae82ccb13bf0b382257be6906f416a22d1ca4ea74464cfff324775.yml
192 changes: 159 additions & 33 deletions logpush/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,8 @@ func (r *JobService) Get(ctx context.Context, jobID int64, query JobGetParams, o
type LogpushJob struct {
// Unique id of the job.
ID int64 `json:"id"`
// Name of the dataset.
// Name of the dataset. A list of supported datasets can be found on the
// [Developer Docs](https://developers.cloudflare.com/logs/reference/log-fields/).
Dataset string `json:"dataset,nullable"`
// Uniquely identifies a resource (such as an s3 bucket) where data will be pushed.
// Additional configuration parameters supported by the destination may be
Expand All @@ -169,10 +170,15 @@ type LogpushJob struct {
// is recorded. On successful execution of a job the error_message and last_error
// are set to null.
ErrorMessage time.Time `json:"error_message,nullable" format:"date-time"`
// The frequency at which Cloudflare sends batches of logs to your destination.
// Setting frequency to high sends your logs in larger quantities of smaller files.
// Setting frequency to low sends logs in smaller quantities of larger files.
// This field is deprecated. Please use `max_upload_*` parameters instead. The
// frequency at which Cloudflare sends batches of logs to your destination. Setting
// frequency to high sends your logs in larger quantities of smaller files. Setting
// frequency to low sends logs in smaller quantities of larger files.
Frequency LogpushJobFrequency `json:"frequency,nullable"`
// The kind parameter (optional) is used to differentiate between Logpush and Edge
// Log Delivery jobs. Currently, Edge Log Delivery is only supported for the
// `http_requests` dataset.
Kind LogpushJobKind `json:"kind,nullable"`
// Records the last time for which logs have been successfully pushed. If the last
// successful push was for logs range 2018-07-23T10:00:00Z to 2018-07-23T10:01:00Z
// then the value of this field will be 2018-07-23T10:01:00Z. If the job has never
Expand All @@ -188,6 +194,23 @@ type LogpushJob struct {
// here, and logpush will keep on making this call for you, setting start and end
// times appropriately.
LogpullOptions string `json:"logpull_options,nullable" format:"uri-reference"`
// The maximum uncompressed file size of a batch of logs. This setting value must
// be between `5 MB` and `1 GB`, or `0` to disable it. Note that you cannot set a
// minimum file size; this means that log files may be much smaller than this batch
// size. This parameter is not available for jobs with `edge` as its kind.
MaxUploadBytes int64 `json:"max_upload_bytes,nullable"`
// The maximum interval in seconds for log batches. This setting must be between 30
// and 300 seconds (5 minutes), or `0` to disable it. Note that you cannot specify
// a minimum interval for log batches; this means that log files may be sent in
// shorter intervals than this. This parameter is only used for jobs with `edge` as
// its kind.
MaxUploadIntervalSeconds int64 `json:"max_upload_interval_seconds,nullable"`
// The maximum number of log lines per batch. This setting must be between 1000 and
// 1,000,000 lines, or `0` to disable it. Note that you cannot specify a minimum
// number of log lines per batch; this means that log files may contain many fewer
// lines than this. This parameter is not available for jobs with `edge` as its
// kind.
MaxUploadRecords int64 `json:"max_upload_records,nullable"`
// Optional human readable job name. Not unique. Cloudflare suggests that you set
// this to a meaningful string, like the domain name, to make it easier to identify
// your job.
Expand All @@ -200,19 +223,23 @@ type LogpushJob struct {

// logpushJobJSON contains the JSON metadata for the struct [LogpushJob]
type logpushJobJSON struct {
ID apijson.Field
Dataset apijson.Field
DestinationConf apijson.Field
Enabled apijson.Field
ErrorMessage apijson.Field
Frequency apijson.Field
LastComplete apijson.Field
LastError apijson.Field
LogpullOptions apijson.Field
Name apijson.Field
OutputOptions apijson.Field
raw string
ExtraFields map[string]apijson.Field
ID apijson.Field
Dataset apijson.Field
DestinationConf apijson.Field
Enabled apijson.Field
ErrorMessage apijson.Field
Frequency apijson.Field
Kind apijson.Field
LastComplete apijson.Field
LastError apijson.Field
LogpullOptions apijson.Field
MaxUploadBytes apijson.Field
MaxUploadIntervalSeconds apijson.Field
MaxUploadRecords apijson.Field
Name apijson.Field
OutputOptions apijson.Field
raw string
ExtraFields map[string]apijson.Field
}

func (r *LogpushJob) UnmarshalJSON(data []byte) (err error) {
Expand All @@ -223,9 +250,10 @@ func (r logpushJobJSON) RawJSON() string {
return r.raw
}

// The frequency at which Cloudflare sends batches of logs to your destination.
// Setting frequency to high sends your logs in larger quantities of smaller files.
// Setting frequency to low sends logs in smaller quantities of larger files.
// This field is deprecated. Please use `max_upload_*` parameters instead. The
// frequency at which Cloudflare sends batches of logs to your destination. Setting
// frequency to high sends your logs in larger quantities of smaller files. Setting
// frequency to low sends logs in smaller quantities of larger files.
type LogpushJobFrequency string

const (
Expand All @@ -241,6 +269,23 @@ func (r LogpushJobFrequency) IsKnown() bool {
return false
}

// The kind parameter (optional) is used to differentiate between Logpush and Edge
// Log Delivery jobs. Currently, Edge Log Delivery is only supported for the
// `http_requests` dataset.
type LogpushJobKind string

const (
LogpushJobKindEdge LogpushJobKind = "edge"
)

func (r LogpushJobKind) IsKnown() bool {
switch r {
case LogpushJobKindEdge:
return true
}
return false
}

// The structured replacement for `logpull_options`. When including this field, the
// `logpull_option` field will be ignored.
type OutputOptions struct {
Expand Down Expand Up @@ -397,20 +442,43 @@ type JobNewParams struct {
AccountID param.Field[string] `path:"account_id"`
// The Zone ID to use for this endpoint. Mutually exclusive with the Account ID.
ZoneID param.Field[string] `path:"zone_id"`
// Name of the dataset.
// Name of the dataset. A list of supported datasets can be found on the
// [Developer Docs](https://developers.cloudflare.com/logs/reference/log-fields/).
Dataset param.Field[string] `json:"dataset"`
// Flag that indicates if the job is enabled.
Enabled param.Field[bool] `json:"enabled"`
// The frequency at which Cloudflare sends batches of logs to your destination.
// Setting frequency to high sends your logs in larger quantities of smaller files.
// Setting frequency to low sends logs in smaller quantities of larger files.
// This field is deprecated. Please use `max_upload_*` parameters instead. The
// frequency at which Cloudflare sends batches of logs to your destination. Setting
// frequency to high sends your logs in larger quantities of smaller files. Setting
// frequency to low sends logs in smaller quantities of larger files.
Frequency param.Field[JobNewParamsFrequency] `json:"frequency"`
// The kind parameter (optional) is used to differentiate between Logpush and Edge
// Log Delivery jobs. Currently, Edge Log Delivery is only supported for the
// `http_requests` dataset.
Kind param.Field[JobNewParamsKind] `json:"kind"`
// This field is deprecated. Use `output_options` instead. Configuration string. It
// specifies things like requested fields and timestamp formats. If migrating from
// the logpull api, copy the url (full url or just the query string) of your call
// here, and logpush will keep on making this call for you, setting start and end
// times appropriately.
LogpullOptions param.Field[string] `json:"logpull_options" format:"uri-reference"`
// The maximum uncompressed file size of a batch of logs. This setting value must
// be between `5 MB` and `1 GB`, or `0` to disable it. Note that you cannot set a
// minimum file size; this means that log files may be much smaller than this batch
// size. This parameter is not available for jobs with `edge` as its kind.
MaxUploadBytes param.Field[int64] `json:"max_upload_bytes"`
// The maximum interval in seconds for log batches. This setting must be between 30
// and 300 seconds (5 minutes), or `0` to disable it. Note that you cannot specify
// a minimum interval for log batches; this means that log files may be sent in
// shorter intervals than this. This parameter is only used for jobs with `edge` as
// its kind.
MaxUploadIntervalSeconds param.Field[int64] `json:"max_upload_interval_seconds"`
// The maximum number of log lines per batch. This setting must be between 1000 and
// 1,000,000 lines, or `0` to disable it. Note that you cannot specify a minimum
// number of log lines per batch; this means that log files may contain many fewer
// lines than this. This parameter is not available for jobs with `edge` as its
// kind.
MaxUploadRecords param.Field[int64] `json:"max_upload_records"`
// Optional human readable job name. Not unique. Cloudflare suggests that you set
// this to a meaningful string, like the domain name, to make it easier to identify
// your job.
Expand All @@ -426,9 +494,10 @@ func (r JobNewParams) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}

// The frequency at which Cloudflare sends batches of logs to your destination.
// Setting frequency to high sends your logs in larger quantities of smaller files.
// Setting frequency to low sends logs in smaller quantities of larger files.
// This field is deprecated. Please use `max_upload_*` parameters instead. The
// frequency at which Cloudflare sends batches of logs to your destination. Setting
// frequency to high sends your logs in larger quantities of smaller files. Setting
// frequency to low sends logs in smaller quantities of larger files.
type JobNewParamsFrequency string

const (
Expand All @@ -444,6 +513,23 @@ func (r JobNewParamsFrequency) IsKnown() bool {
return false
}

// The kind parameter (optional) is used to differentiate between Logpush and Edge
// Log Delivery jobs. Currently, Edge Log Delivery is only supported for the
// `http_requests` dataset.
type JobNewParamsKind string

const (
JobNewParamsKindEdge JobNewParamsKind = "edge"
)

func (r JobNewParamsKind) IsKnown() bool {
switch r {
case JobNewParamsKindEdge:
return true
}
return false
}

type JobNewResponseEnvelope struct {
Errors []shared.ResponseInfo `json:"errors,required"`
Messages []shared.ResponseInfo `json:"messages,required"`
Expand Down Expand Up @@ -498,16 +584,38 @@ type JobUpdateParams struct {
DestinationConf param.Field[string] `json:"destination_conf" format:"uri"`
// Flag that indicates if the job is enabled.
Enabled param.Field[bool] `json:"enabled"`
// The frequency at which Cloudflare sends batches of logs to your destination.
// Setting frequency to high sends your logs in larger quantities of smaller files.
// Setting frequency to low sends logs in smaller quantities of larger files.
// This field is deprecated. Please use `max_upload_*` parameters instead. The
// frequency at which Cloudflare sends batches of logs to your destination. Setting
// frequency to high sends your logs in larger quantities of smaller files. Setting
// frequency to low sends logs in smaller quantities of larger files.
Frequency param.Field[JobUpdateParamsFrequency] `json:"frequency"`
// The kind parameter (optional) is used to differentiate between Logpush and Edge
// Log Delivery jobs. Currently, Edge Log Delivery is only supported for the
// `http_requests` dataset.
Kind param.Field[JobUpdateParamsKind] `json:"kind"`
// This field is deprecated. Use `output_options` instead. Configuration string. It
// specifies things like requested fields and timestamp formats. If migrating from
// the logpull api, copy the url (full url or just the query string) of your call
// here, and logpush will keep on making this call for you, setting start and end
// times appropriately.
LogpullOptions param.Field[string] `json:"logpull_options" format:"uri-reference"`
// The maximum uncompressed file size of a batch of logs. This setting value must
// be between `5 MB` and `1 GB`, or `0` to disable it. Note that you cannot set a
// minimum file size; this means that log files may be much smaller than this batch
// size. This parameter is not available for jobs with `edge` as its kind.
MaxUploadBytes param.Field[int64] `json:"max_upload_bytes"`
// The maximum interval in seconds for log batches. This setting must be between 30
// and 300 seconds (5 minutes), or `0` to disable it. Note that you cannot specify
// a minimum interval for log batches; this means that log files may be sent in
// shorter intervals than this. This parameter is only used for jobs with `edge` as
// its kind.
MaxUploadIntervalSeconds param.Field[int64] `json:"max_upload_interval_seconds"`
// The maximum number of log lines per batch. This setting must be between 1000 and
// 1,000,000 lines, or `0` to disable it. Note that you cannot specify a minimum
// number of log lines per batch; this means that log files may contain many fewer
// lines than this. This parameter is not available for jobs with `edge` as its
// kind.
MaxUploadRecords param.Field[int64] `json:"max_upload_records"`
// The structured replacement for `logpull_options`. When including this field, the
// `logpull_option` field will be ignored.
OutputOptions param.Field[OutputOptionsParam] `json:"output_options"`
Expand All @@ -519,9 +627,10 @@ func (r JobUpdateParams) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}

// The frequency at which Cloudflare sends batches of logs to your destination.
// Setting frequency to high sends your logs in larger quantities of smaller files.
// Setting frequency to low sends logs in smaller quantities of larger files.
// This field is deprecated. Please use `max_upload_*` parameters instead. The
// frequency at which Cloudflare sends batches of logs to your destination. Setting
// frequency to high sends your logs in larger quantities of smaller files. Setting
// frequency to low sends logs in smaller quantities of larger files.
type JobUpdateParamsFrequency string

const (
Expand All @@ -537,6 +646,23 @@ func (r JobUpdateParamsFrequency) IsKnown() bool {
return false
}

// The kind parameter (optional) is used to differentiate between Logpush and Edge
// Log Delivery jobs. Currently, Edge Log Delivery is only supported for the
// `http_requests` dataset.
type JobUpdateParamsKind string

const (
JobUpdateParamsKindEdge JobUpdateParamsKind = "edge"
)

func (r JobUpdateParamsKind) IsKnown() bool {
switch r {
case JobUpdateParamsKindEdge:
return true
}
return false
}

type JobUpdateResponseEnvelope struct {
Errors []shared.ResponseInfo `json:"errors,required"`
Messages []shared.ResponseInfo `json:"messages,required"`
Expand Down
36 changes: 22 additions & 14 deletions logpush/job_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,18 @@ func TestJobNewWithOptionalParams(t *testing.T) {
option.WithAPIEmail("user@example.com"),
)
_, err := client.Logpush.Jobs.New(context.TODO(), logpush.JobNewParams{
DestinationConf: cloudflare.F("s3://mybucket/logs?region=us-west-2"),
AccountID: cloudflare.F("string"),
ZoneID: cloudflare.F("string"),
Dataset: cloudflare.F("http_requests"),
Enabled: cloudflare.F(false),
Frequency: cloudflare.F(logpush.JobNewParamsFrequencyHigh),
LogpullOptions: cloudflare.F("fields=RayID,ClientIP,EdgeStartTimestamp&timestamps=rfc3339"),
Name: cloudflare.F("example.com"),
DestinationConf: cloudflare.F("s3://mybucket/logs?region=us-west-2"),
AccountID: cloudflare.F("string"),
ZoneID: cloudflare.F("string"),
Dataset: cloudflare.F("http_requests"),
Enabled: cloudflare.F(false),
Frequency: cloudflare.F(logpush.JobNewParamsFrequencyHigh),
Kind: cloudflare.F(logpush.JobNewParamsKindEdge),
LogpullOptions: cloudflare.F("fields=RayID,ClientIP,EdgeStartTimestamp&timestamps=rfc3339"),
MaxUploadBytes: cloudflare.F(int64(5000000)),
MaxUploadIntervalSeconds: cloudflare.F(int64(30)),
MaxUploadRecords: cloudflare.F(int64(1000)),
Name: cloudflare.F("example.com"),
OutputOptions: cloudflare.F(logpush.OutputOptionsParam{
Cve2021_4428: cloudflare.F(true),
BatchPrefix: cloudflare.F("string"),
Expand Down Expand Up @@ -80,12 +84,16 @@ func TestJobUpdateWithOptionalParams(t *testing.T) {
context.TODO(),
int64(1),
logpush.JobUpdateParams{
AccountID: cloudflare.F("string"),
ZoneID: cloudflare.F("string"),
DestinationConf: cloudflare.F("s3://mybucket/logs?region=us-west-2"),
Enabled: cloudflare.F(false),
Frequency: cloudflare.F(logpush.JobUpdateParamsFrequencyHigh),
LogpullOptions: cloudflare.F("fields=RayID,ClientIP,EdgeStartTimestamp&timestamps=rfc3339"),
AccountID: cloudflare.F("string"),
ZoneID: cloudflare.F("string"),
DestinationConf: cloudflare.F("s3://mybucket/logs?region=us-west-2"),
Enabled: cloudflare.F(false),
Frequency: cloudflare.F(logpush.JobUpdateParamsFrequencyHigh),
Kind: cloudflare.F(logpush.JobUpdateParamsKindEdge),
LogpullOptions: cloudflare.F("fields=RayID,ClientIP,EdgeStartTimestamp&timestamps=rfc3339"),
MaxUploadBytes: cloudflare.F(int64(5000000)),
MaxUploadIntervalSeconds: cloudflare.F(int64(30)),
MaxUploadRecords: cloudflare.F(int64(1000)),
OutputOptions: cloudflare.F(logpush.OutputOptionsParam{
Cve2021_4428: cloudflare.F(true),
BatchPrefix: cloudflare.F("string"),
Expand Down

0 comments on commit a6cc625

Please sign in to comment.