/
validate.go
238 lines (205 loc) · 7.94 KB
/
validate.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
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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
package logpush
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/internal/shared"
"github.com/cloudflare/cloudflare-go/v2/option"
)
// ValidateService 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 [NewValidateService] method instead.
type ValidateService struct {
Options []option.RequestOption
}
// NewValidateService 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 NewValidateService(opts ...option.RequestOption) (r *ValidateService) {
r = &ValidateService{}
r.Options = opts
return
}
// Checks if there is an existing job with a destination.
func (r *ValidateService) Destination(ctx context.Context, params ValidateDestinationParams, opts ...option.RequestOption) (res *ValidateDestinationResponse, err error) {
opts = append(r.Options[:], opts...)
var env ValidateDestinationResponseEnvelope
var accountOrZone string
var accountOrZoneID param.Field[string]
if params.AccountID.Present {
accountOrZone = "accounts"
accountOrZoneID = params.AccountID
} else {
accountOrZone = "zones"
accountOrZoneID = params.ZoneID
}
path := fmt.Sprintf("%s/%s/logpush/validate/destination/exists", accountOrZone, accountOrZoneID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, params, &env, opts...)
if err != nil {
return
}
res = &env.Result
return
}
// Validates logpull origin with logpull_options.
func (r *ValidateService) Origin(ctx context.Context, params ValidateOriginParams, opts ...option.RequestOption) (res *ValidateOriginResponse, err error) {
opts = append(r.Options[:], opts...)
var env ValidateOriginResponseEnvelope
var accountOrZone string
var accountOrZoneID param.Field[string]
if params.AccountID.Present {
accountOrZone = "accounts"
accountOrZoneID = params.AccountID
} else {
accountOrZone = "zones"
accountOrZoneID = params.ZoneID
}
path := fmt.Sprintf("%s/%s/logpush/validate/origin", accountOrZone, accountOrZoneID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, params, &env, opts...)
if err != nil {
return
}
res = &env.Result
return
}
type ValidateDestinationResponse struct {
Exists bool `json:"exists"`
JSON validateDestinationResponseJSON `json:"-"`
}
// validateDestinationResponseJSON contains the JSON metadata for the struct
// [ValidateDestinationResponse]
type validateDestinationResponseJSON struct {
Exists apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *ValidateDestinationResponse) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r validateDestinationResponseJSON) RawJSON() string {
return r.raw
}
type ValidateOriginResponse struct {
Message string `json:"message"`
Valid bool `json:"valid"`
JSON validateOriginResponseJSON `json:"-"`
}
// validateOriginResponseJSON contains the JSON metadata for the struct
// [ValidateOriginResponse]
type validateOriginResponseJSON struct {
Message apijson.Field
Valid apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *ValidateOriginResponse) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r validateOriginResponseJSON) RawJSON() string {
return r.raw
}
type ValidateDestinationParams struct {
// Uniquely identifies a resource (such as an s3 bucket) where data will be pushed.
// Additional configuration parameters supported by the destination may be
// included.
DestinationConf param.Field[string] `json:"destination_conf,required" format:"uri"`
// The Account ID to use for this endpoint. Mutually exclusive with the Zone ID.
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"`
}
func (r ValidateDestinationParams) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
type ValidateDestinationResponseEnvelope struct {
Errors []shared.ResponseInfo `json:"errors,required"`
Messages []shared.ResponseInfo `json:"messages,required"`
// Whether the API call was successful
Success ValidateDestinationResponseEnvelopeSuccess `json:"success,required"`
Result ValidateDestinationResponse `json:"result,nullable"`
JSON validateDestinationResponseEnvelopeJSON `json:"-"`
}
// validateDestinationResponseEnvelopeJSON contains the JSON metadata for the
// struct [ValidateDestinationResponseEnvelope]
type validateDestinationResponseEnvelopeJSON struct {
Errors apijson.Field
Messages apijson.Field
Success apijson.Field
Result apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *ValidateDestinationResponseEnvelope) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r validateDestinationResponseEnvelopeJSON) RawJSON() string {
return r.raw
}
// Whether the API call was successful
type ValidateDestinationResponseEnvelopeSuccess bool
const (
ValidateDestinationResponseEnvelopeSuccessTrue ValidateDestinationResponseEnvelopeSuccess = true
)
func (r ValidateDestinationResponseEnvelopeSuccess) IsKnown() bool {
switch r {
case ValidateDestinationResponseEnvelopeSuccessTrue:
return true
}
return false
}
type ValidateOriginParams struct {
// 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,required" format:"uri-reference"`
// The Account ID to use for this endpoint. Mutually exclusive with the Zone ID.
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"`
}
func (r ValidateOriginParams) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
type ValidateOriginResponseEnvelope struct {
Errors []shared.ResponseInfo `json:"errors,required"`
Messages []shared.ResponseInfo `json:"messages,required"`
// Whether the API call was successful
Success ValidateOriginResponseEnvelopeSuccess `json:"success,required"`
Result ValidateOriginResponse `json:"result,nullable"`
JSON validateOriginResponseEnvelopeJSON `json:"-"`
}
// validateOriginResponseEnvelopeJSON contains the JSON metadata for the struct
// [ValidateOriginResponseEnvelope]
type validateOriginResponseEnvelopeJSON struct {
Errors apijson.Field
Messages apijson.Field
Success apijson.Field
Result apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *ValidateOriginResponseEnvelope) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r validateOriginResponseEnvelopeJSON) RawJSON() string {
return r.raw
}
// Whether the API call was successful
type ValidateOriginResponseEnvelopeSuccess bool
const (
ValidateOriginResponseEnvelopeSuccessTrue ValidateOriginResponseEnvelopeSuccess = true
)
func (r ValidateOriginResponseEnvelopeSuccess) IsKnown() bool {
switch r {
case ValidateOriginResponseEnvelopeSuccessTrue:
return true
}
return false
}