-
Notifications
You must be signed in to change notification settings - Fork 8
/
cli.go
297 lines (276 loc) · 8.15 KB
/
cli.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
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
// Code generated by goa v3.13.2, DO NOT EDIT.
//
// collection HTTP client CLI support package
//
// Command:
// $ goa gen github.com/artefactual-labs/enduro/internal/api/design -o
// internal/api
package client
import (
"encoding/json"
"fmt"
"strconv"
collection "github.com/artefactual-labs/enduro/internal/api/gen/collection"
goa "goa.design/goa/v3/pkg"
)
// BuildListPayload builds the payload for the collection list endpoint from
// CLI flags.
func BuildListPayload(collectionListName string, collectionListOriginalID string, collectionListTransferID string, collectionListAipID string, collectionListPipelineID string, collectionListEarliestCreatedTime string, collectionListLatestCreatedTime string, collectionListStatus string, collectionListCursor string) (*collection.ListPayload, error) {
var err error
var name *string
{
if collectionListName != "" {
name = &collectionListName
}
}
var originalID *string
{
if collectionListOriginalID != "" {
originalID = &collectionListOriginalID
}
}
var transferID *string
{
if collectionListTransferID != "" {
transferID = &collectionListTransferID
err = goa.MergeErrors(err, goa.ValidateFormat("transfer_id", *transferID, goa.FormatUUID))
if err != nil {
return nil, err
}
}
}
var aipID *string
{
if collectionListAipID != "" {
aipID = &collectionListAipID
err = goa.MergeErrors(err, goa.ValidateFormat("aip_id", *aipID, goa.FormatUUID))
if err != nil {
return nil, err
}
}
}
var pipelineID *string
{
if collectionListPipelineID != "" {
pipelineID = &collectionListPipelineID
err = goa.MergeErrors(err, goa.ValidateFormat("pipeline_id", *pipelineID, goa.FormatUUID))
if err != nil {
return nil, err
}
}
}
var earliestCreatedTime *string
{
if collectionListEarliestCreatedTime != "" {
earliestCreatedTime = &collectionListEarliestCreatedTime
err = goa.MergeErrors(err, goa.ValidateFormat("earliest_created_time", *earliestCreatedTime, goa.FormatDateTime))
if err != nil {
return nil, err
}
}
}
var latestCreatedTime *string
{
if collectionListLatestCreatedTime != "" {
latestCreatedTime = &collectionListLatestCreatedTime
err = goa.MergeErrors(err, goa.ValidateFormat("latest_created_time", *latestCreatedTime, goa.FormatDateTime))
if err != nil {
return nil, err
}
}
}
var status *string
{
if collectionListStatus != "" {
status = &collectionListStatus
if !(*status == "new" || *status == "in progress" || *status == "done" || *status == "error" || *status == "unknown" || *status == "queued" || *status == "pending" || *status == "abandoned") {
err = goa.MergeErrors(err, goa.InvalidEnumValueError("status", *status, []any{"new", "in progress", "done", "error", "unknown", "queued", "pending", "abandoned"}))
}
if err != nil {
return nil, err
}
}
}
var cursor *string
{
if collectionListCursor != "" {
cursor = &collectionListCursor
}
}
v := &collection.ListPayload{}
v.Name = name
v.OriginalID = originalID
v.TransferID = transferID
v.AipID = aipID
v.PipelineID = pipelineID
v.EarliestCreatedTime = earliestCreatedTime
v.LatestCreatedTime = latestCreatedTime
v.Status = status
v.Cursor = cursor
return v, nil
}
// BuildShowPayload builds the payload for the collection show endpoint from
// CLI flags.
func BuildShowPayload(collectionShowID string) (*collection.ShowPayload, error) {
var err error
var id uint
{
var v uint64
v, err = strconv.ParseUint(collectionShowID, 10, strconv.IntSize)
id = uint(v)
if err != nil {
return nil, fmt.Errorf("invalid value for id, must be UINT")
}
}
v := &collection.ShowPayload{}
v.ID = id
return v, nil
}
// BuildDeletePayload builds the payload for the collection delete endpoint
// from CLI flags.
func BuildDeletePayload(collectionDeleteID string) (*collection.DeletePayload, error) {
var err error
var id uint
{
var v uint64
v, err = strconv.ParseUint(collectionDeleteID, 10, strconv.IntSize)
id = uint(v)
if err != nil {
return nil, fmt.Errorf("invalid value for id, must be UINT")
}
}
v := &collection.DeletePayload{}
v.ID = id
return v, nil
}
// BuildCancelPayload builds the payload for the collection cancel endpoint
// from CLI flags.
func BuildCancelPayload(collectionCancelID string) (*collection.CancelPayload, error) {
var err error
var id uint
{
var v uint64
v, err = strconv.ParseUint(collectionCancelID, 10, strconv.IntSize)
id = uint(v)
if err != nil {
return nil, fmt.Errorf("invalid value for id, must be UINT")
}
}
v := &collection.CancelPayload{}
v.ID = id
return v, nil
}
// BuildRetryPayload builds the payload for the collection retry endpoint from
// CLI flags.
func BuildRetryPayload(collectionRetryID string) (*collection.RetryPayload, error) {
var err error
var id uint
{
var v uint64
v, err = strconv.ParseUint(collectionRetryID, 10, strconv.IntSize)
id = uint(v)
if err != nil {
return nil, fmt.Errorf("invalid value for id, must be UINT")
}
}
v := &collection.RetryPayload{}
v.ID = id
return v, nil
}
// BuildWorkflowPayload builds the payload for the collection workflow endpoint
// from CLI flags.
func BuildWorkflowPayload(collectionWorkflowID string) (*collection.WorkflowPayload, error) {
var err error
var id uint
{
var v uint64
v, err = strconv.ParseUint(collectionWorkflowID, 10, strconv.IntSize)
id = uint(v)
if err != nil {
return nil, fmt.Errorf("invalid value for id, must be UINT")
}
}
v := &collection.WorkflowPayload{}
v.ID = id
return v, nil
}
// BuildDownloadPayload builds the payload for the collection download endpoint
// from CLI flags.
func BuildDownloadPayload(collectionDownloadID string) (*collection.DownloadPayload, error) {
var err error
var id uint
{
var v uint64
v, err = strconv.ParseUint(collectionDownloadID, 10, strconv.IntSize)
id = uint(v)
if err != nil {
return nil, fmt.Errorf("invalid value for id, must be UINT")
}
}
v := &collection.DownloadPayload{}
v.ID = id
return v, nil
}
// BuildDecidePayload builds the payload for the collection decide endpoint
// from CLI flags.
func BuildDecidePayload(collectionDecideBody string, collectionDecideID string) (*collection.DecidePayload, error) {
var err error
var body struct {
// Decision option to proceed with
Option *string `form:"option" json:"option" xml:"option"`
}
{
err = json.Unmarshal([]byte(collectionDecideBody), &body)
if err != nil {
return nil, fmt.Errorf("invalid JSON for body, \nerror: %s, \nexample of valid JSON:\n%s", err, "'{\n \"option\": \"abc123\"\n }'")
}
}
var id uint
{
var v uint64
v, err = strconv.ParseUint(collectionDecideID, 10, strconv.IntSize)
id = uint(v)
if err != nil {
return nil, fmt.Errorf("invalid value for id, must be UINT")
}
}
v := &collection.DecidePayload{}
if body.Option != nil {
v.Option = *body.Option
}
v.ID = id
return v, nil
}
// BuildBulkPayload builds the payload for the collection bulk endpoint from
// CLI flags.
func BuildBulkPayload(collectionBulkBody string) (*collection.BulkPayload, error) {
var err error
var body BulkRequestBody
{
err = json.Unmarshal([]byte(collectionBulkBody), &body)
if err != nil {
return nil, fmt.Errorf("invalid JSON for body, \nerror: %s, \nexample of valid JSON:\n%s", err, "'{\n \"operation\": \"cancel\",\n \"size\": 1,\n \"status\": \"in progress\"\n }'")
}
if !(body.Operation == "retry" || body.Operation == "cancel" || body.Operation == "abandon") {
err = goa.MergeErrors(err, goa.InvalidEnumValueError("body.operation", body.Operation, []any{"retry", "cancel", "abandon"}))
}
if !(body.Status == "new" || body.Status == "in progress" || body.Status == "done" || body.Status == "error" || body.Status == "unknown" || body.Status == "queued" || body.Status == "pending" || body.Status == "abandoned") {
err = goa.MergeErrors(err, goa.InvalidEnumValueError("body.status", body.Status, []any{"new", "in progress", "done", "error", "unknown", "queued", "pending", "abandoned"}))
}
if err != nil {
return nil, err
}
}
v := &collection.BulkPayload{
Operation: body.Operation,
Status: body.Status,
Size: body.Size,
}
{
var zero uint
if v.Size == zero {
v.Size = 100
}
}
return v, nil
}