@@ -22,7 +22,6 @@ import (
22
22
"fmt"
23
23
"os"
24
24
25
- "github.com/antihax/optional"
26
25
"github.com/arduino/arduino-cloud-cli/config"
27
26
iotclient "github.com/arduino/iot-client-go"
28
27
"golang.org/x/oauth2"
@@ -118,21 +117,23 @@ func (cl *Client) DevicePassSet(ctx context.Context, id string) (*iotclient.Ardu
118
117
}
119
118
120
119
// Fetch suggested password
121
- opts := & iotclient.DevicesV2PassGetOpts {SuggestedPassword : optional .NewBool (true )}
122
- pass , _ , err := cl .api .DevicesV2PassApi .DevicesV2PassGet (ctx , id , opts )
120
+ req := cl .api .DevicesV2PassApi .DevicesV2PassGet (ctx , id )
121
+ req = req .SuggestedPassword (true )
122
+ pass , _ , err := cl .api .DevicesV2PassApi .DevicesV2PassGetExecute (req )
123
123
if err != nil {
124
124
err = fmt .Errorf ("fetching device suggested password: %w" , errorDetail (err ))
125
125
return nil , err
126
126
}
127
127
128
128
// Set password to the suggested one
129
- p := iotclient.Devicev2Pass {Password : pass .SuggestedPassword }
130
- pass , _ , err = cl .api .DevicesV2PassApi .DevicesV2PassSet (ctx , id , p )
129
+ reqSet := cl .api .DevicesV2PassApi .DevicesV2PassSet (ctx , id )
130
+ reqSet = reqSet .Devicev2Pass (iotclient.Devicev2Pass {Password : pass .SuggestedPassword })
131
+ pass , _ , err = cl .api .DevicesV2PassApi .DevicesV2PassSetExecute (reqSet )
131
132
if err != nil {
132
133
err = fmt .Errorf ("setting device password: %w" , errorDetail (err ))
133
134
return nil , err
134
135
}
135
- return & pass , nil
136
+ return pass , nil
136
137
}
137
138
138
139
// DeviceDelete deletes the device corresponding to the passed ID
@@ -160,17 +161,16 @@ func (cl *Client) DeviceList(ctx context.Context, tags map[string]string) ([]iot
160
161
return nil , err
161
162
}
162
163
163
- opts := & iotclient. DevicesV2ListOpts {}
164
+ req := cl . api . DevicesV2Api . DevicesV2List ( ctx )
164
165
if tags != nil {
165
166
t := make ([]string , 0 , len (tags ))
166
167
for key , val := range tags {
167
168
// Use the 'key:value' format required from the backend
168
169
t = append (t , key + ":" + val )
169
170
}
170
- opts . Tags = optional . NewInterface (t )
171
+ req = req . Tags (t )
171
172
}
172
-
173
- devices , _ , err := cl .api .DevicesV2Api .DevicesV2List (ctx , opts )
173
+ devices , _ , err := cl .api .DevicesV2Api .DevicesV2ListExecute (req )
174
174
if err != nil {
175
175
err = fmt .Errorf ("listing devices: %w" , errorDetail (err ))
176
176
return nil , err
@@ -186,12 +186,13 @@ func (cl *Client) DeviceShow(ctx context.Context, id string) (*iotclient.Arduino
186
186
return nil , err
187
187
}
188
188
189
- dev , _ , err := cl .api .DevicesV2Api .DevicesV2Show (ctx , id , nil )
189
+ req := cl .api .DevicesV2Api .DevicesV2Show (ctx , id )
190
+ dev , _ , err := cl .api .DevicesV2Api .DevicesV2ShowExecute (req )
190
191
if err != nil {
191
192
err = fmt .Errorf ("retrieving device, %w" , errorDetail (err ))
192
193
return nil , err
193
194
}
194
- return & dev , nil
195
+ return dev , nil
195
196
}
196
197
197
198
// DeviceOTA performs an OTA upload request to Arduino IoT Cloud, passing
@@ -202,11 +203,10 @@ func (cl *Client) DeviceOTA(ctx context.Context, id string, file *os.File, expir
202
203
return err
203
204
}
204
205
205
- opt := & iotclient.DevicesV2OtaUploadOpts {
206
- ExpireInMins : optional .NewInt32 (int32 (expireMins )),
207
- Async : optional .NewBool (true ),
208
- }
209
- resp , err := cl .api .DevicesV2OtaApi .DevicesV2OtaUpload (ctx , id , file , opt )
206
+ req := cl .api .DevicesV2OtaApi .DevicesV2OtaUpload (ctx , id )
207
+ req = req .ExpireInMins (int32 (expireMins ))
208
+ req = req .Async (true )
209
+ _ , resp , err := cl .api .DevicesV2OtaApi .DevicesV2OtaUploadExecute (req )
210
210
if err != nil {
211
211
// 409 (Conflict) is the status code for an already existing OTA in progress for the same device. Handling it in a different way.
212
212
if resp .StatusCode == 409 {
@@ -225,8 +225,9 @@ func (cl *Client) DeviceTagsCreate(ctx context.Context, id string, tags map[stri
225
225
}
226
226
227
227
for key , val := range tags {
228
- t := iotclient.Tag {Key : key , Value : val }
229
- _ , err := cl .api .DevicesV2TagsApi .DevicesV2TagsUpsert (ctx , id , t )
228
+ req := cl .api .DevicesV2TagsApi .DevicesV2TagsUpsert (ctx , id )
229
+ req = req .Tag (iotclient.Tag {Key : key , Value : val })
230
+ _ , err := cl .api .DevicesV2TagsApi .DevicesV2TagsUpsertExecute (req )
230
231
if err != nil {
231
232
err = fmt .Errorf ("cannot create tag %s: %w" , key , errorDetail (err ))
232
233
return err
@@ -244,7 +245,8 @@ func (cl *Client) DeviceTagsDelete(ctx context.Context, id string, keys []string
244
245
}
245
246
246
247
for _ , key := range keys {
247
- _ , err := cl .api .DevicesV2TagsApi .DevicesV2TagsDelete (ctx , id , key )
248
+ req := cl .api .DevicesV2TagsApi .DevicesV2TagsDelete (ctx , id , key )
249
+ _ , err := cl .api .DevicesV2TagsApi .DevicesV2TagsDeleteExecute (req )
248
250
if err != nil {
249
251
err = fmt .Errorf ("cannot delete tag %s: %w" , key , errorDetail (err ))
250
252
return err
@@ -261,7 +263,8 @@ func (cl *Client) LoraFrequencyPlansList(ctx context.Context) ([]iotclient.Ardui
261
263
return nil , err
262
264
}
263
265
264
- freqs , _ , err := cl .api .LoraFreqPlanV1Api .LoraFreqPlanV1List (ctx )
266
+ req := cl .api .LoraFreqPlanV1Api .LoraFreqPlanV1List (ctx )
267
+ freqs , _ , err := cl .api .LoraFreqPlanV1Api .LoraFreqPlanV1ListExecute (req )
265
268
if err != nil {
266
269
err = fmt .Errorf ("listing lora frequency plans: %w" , errorDetail (err ))
267
270
return nil , err
@@ -278,12 +281,14 @@ func (cl *Client) CertificateCreate(ctx context.Context, id, csr string) (*iotcl
278
281
}
279
282
280
283
cert := iotclient.CreateDevicesV2CertsPayload {
281
- Ca : "Arduino" ,
284
+ Ca : toStringPointer ( "Arduino" ) ,
282
285
Csr : csr ,
283
286
Enabled : true ,
284
287
}
285
288
286
- newCert , _ , err := cl .api .DevicesV2CertsApi .DevicesV2CertsCreate (ctx , id , cert )
289
+ req := cl .api .DevicesV2CertsApi .DevicesV2CertsCreate (ctx , id )
290
+ req = req .CreateDevicesV2CertsPayload (cert )
291
+ newCert , _ , err := cl .api .DevicesV2CertsApi .DevicesV2CertsCreateExecute (req )
287
292
if err != nil {
288
293
err = fmt .Errorf ("creating certificate, %w" , errorDetail (err ))
289
294
return nil , err
@@ -299,12 +304,14 @@ func (cl *Client) ThingCreate(ctx context.Context, thing *iotclient.ThingCreate,
299
304
return nil , err
300
305
}
301
306
302
- opt := & iotclient.ThingsV2CreateOpts {Force : optional .NewBool (force )}
303
- newThing , _ , err := cl .api .ThingsV2Api .ThingsV2Create (ctx , * thing , opt )
307
+ req := cl .api .ThingsV2Api .ThingsV2Create (ctx )
308
+ req = req .ThingCreate (* thing )
309
+ req = req .Force (force )
310
+ newThing , _ , err := cl .api .ThingsV2Api .ThingsV2CreateExecute (req )
304
311
if err != nil {
305
312
return nil , fmt .Errorf ("%s: %w" , "adding new thing" , errorDetail (err ))
306
313
}
307
- return & newThing , nil
314
+ return newThing , nil
308
315
}
309
316
310
317
// ThingUpdate updates a thing on Arduino IoT Cloud.
@@ -314,8 +321,10 @@ func (cl *Client) ThingUpdate(ctx context.Context, id string, thing *iotclient.T
314
321
return err
315
322
}
316
323
317
- opt := & iotclient.ThingsV2UpdateOpts {Force : optional .NewBool (force )}
318
- _ , _ , err = cl .api .ThingsV2Api .ThingsV2Update (ctx , id , * thing , opt )
324
+ req := cl .api .ThingsV2Api .ThingsV2Update (ctx , id )
325
+ req = req .Force (force )
326
+ req = req .ThingUpdate (* thing )
327
+ _ , _ , err = cl .api .ThingsV2Api .ThingsV2UpdateExecute (req )
319
328
if err != nil {
320
329
return fmt .Errorf ("%s: %v" , "updating thing" , errorDetail (err ))
321
330
}
@@ -329,7 +338,8 @@ func (cl *Client) ThingDelete(ctx context.Context, id string) error {
329
338
return err
330
339
}
331
340
332
- _ , err = cl .api .ThingsV2Api .ThingsV2Delete (ctx , id , nil )
341
+ req := cl .api .ThingsV2Api .ThingsV2Delete (ctx , id )
342
+ _ , err = cl .api .ThingsV2Api .ThingsV2DeleteExecute (req )
333
343
if err != nil {
334
344
err = fmt .Errorf ("deleting thing: %w" , errorDetail (err ))
335
345
return err
@@ -345,12 +355,12 @@ func (cl *Client) ThingShow(ctx context.Context, id string) (*iotclient.ArduinoT
345
355
return nil , err
346
356
}
347
357
348
- thing , _ , err := cl .api .ThingsV2Api .ThingsV2Show (ctx , id , nil )
358
+ thing , _ , err := cl .api .ThingsV2Api .ThingsV2ShowExecute ( cl . api . ThingsV2Api . ThingsV2Show (ctx , id ) )
349
359
if err != nil {
350
360
err = fmt .Errorf ("retrieving thing, %w" , errorDetail (err ))
351
361
return nil , err
352
362
}
353
- return & thing , nil
363
+ return thing , nil
354
364
}
355
365
356
366
// ThingList returns a list of things on Arduino IoT Cloud.
@@ -360,15 +370,14 @@ func (cl *Client) ThingList(ctx context.Context, ids []string, device *string, p
360
370
return nil , err
361
371
}
362
372
363
- opts := & iotclient.ThingsV2ListOpts {}
364
- opts .ShowProperties = optional .NewBool (props )
365
-
373
+ req := cl .api .ThingsV2Api .ThingsV2List (ctx )
374
+ req = req .ShowProperties (props )
366
375
if ids != nil {
367
- opts . Ids = optional . NewInterface (ids )
376
+ req = req . Ids (ids )
368
377
}
369
378
370
379
if device != nil {
371
- opts . DeviceId = optional . NewString (* device )
380
+ req = req . DeviceId (* device )
372
381
}
373
382
374
383
if tags != nil {
@@ -377,10 +386,9 @@ func (cl *Client) ThingList(ctx context.Context, ids []string, device *string, p
377
386
// Use the 'key:value' format required from the backend
378
387
t = append (t , key + ":" + val )
379
388
}
380
- opts . Tags = optional . NewInterface (t )
389
+ req = req . Tags (t )
381
390
}
382
-
383
- things , _ , err := cl .api .ThingsV2Api .ThingsV2List (ctx , opts )
391
+ things , _ , err := cl .api .ThingsV2Api .ThingsV2ListExecute (req )
384
392
if err != nil {
385
393
err = fmt .Errorf ("retrieving things, %w" , errorDetail (err ))
386
394
return nil , err
@@ -396,8 +404,9 @@ func (cl *Client) ThingTagsCreate(ctx context.Context, id string, tags map[strin
396
404
}
397
405
398
406
for key , val := range tags {
399
- t := iotclient.Tag {Key : key , Value : val }
400
- _ , err := cl .api .ThingsV2TagsApi .ThingsV2TagsUpsert (ctx , id , t )
407
+ req := cl .api .ThingsV2TagsApi .ThingsV2TagsUpsert (ctx , id )
408
+ req = req .Tag (iotclient.Tag {Key : key , Value : val })
409
+ _ , err := cl .api .ThingsV2TagsApi .ThingsV2TagsUpsertExecute (req )
401
410
if err != nil {
402
411
err = fmt .Errorf ("cannot create tag %s: %w" , key , errorDetail (err ))
403
412
return err
@@ -415,7 +424,8 @@ func (cl *Client) ThingTagsDelete(ctx context.Context, id string, keys []string)
415
424
}
416
425
417
426
for _ , key := range keys {
418
- _ , err := cl .api .ThingsV2TagsApi .ThingsV2TagsDelete (ctx , id , key )
427
+ req := cl .api .ThingsV2TagsApi .ThingsV2TagsDelete (ctx , id , key )
428
+ _ , err := cl .api .ThingsV2TagsApi .ThingsV2TagsDeleteExecute (req )
419
429
if err != nil {
420
430
err = fmt .Errorf ("cannot delete tag %s: %w" , key , errorDetail (err ))
421
431
return err
@@ -431,11 +441,13 @@ func (cl *Client) DashboardCreate(ctx context.Context, dashboard *iotclient.Dash
431
441
return nil , err
432
442
}
433
443
434
- newDashboard , _ , err := cl .api .DashboardsV2Api .DashboardsV2Create (ctx , * dashboard , nil )
444
+ req := cl .api .DashboardsV2Api .DashboardsV2Create (ctx )
445
+ req = req .Dashboardv2 (* dashboard )
446
+ newDashboard , _ , err := cl .api .DashboardsV2Api .DashboardsV2CreateExecute (req )
435
447
if err != nil {
436
448
return nil , fmt .Errorf ("%s: %w" , "adding new dashboard" , errorDetail (err ))
437
449
}
438
- return & newDashboard , nil
450
+ return newDashboard , nil
439
451
}
440
452
441
453
// DashboardShow allows to retrieve a specific dashboard, given its id,
@@ -446,12 +458,13 @@ func (cl *Client) DashboardShow(ctx context.Context, id string) (*iotclient.Ardu
446
458
return nil , err
447
459
}
448
460
449
- dashboard , _ , err := cl .api .DashboardsV2Api .DashboardsV2Show (ctx , id , nil )
461
+ req := cl .api .DashboardsV2Api .DashboardsV2Show (ctx , id )
462
+ dashboard , _ , err := cl .api .DashboardsV2Api .DashboardsV2ShowExecute (req )
450
463
if err != nil {
451
464
err = fmt .Errorf ("retrieving dashboard, %w" , errorDetail (err ))
452
465
return nil , err
453
466
}
454
- return & dashboard , nil
467
+ return dashboard , nil
455
468
}
456
469
457
470
// DashboardList returns a list of dashboards on Arduino IoT Cloud.
@@ -460,8 +473,9 @@ func (cl *Client) DashboardList(ctx context.Context) ([]iotclient.ArduinoDashboa
460
473
if err != nil {
461
474
return nil , err
462
475
}
463
-
464
- dashboards , _ , err := cl .api .DashboardsV2Api .DashboardsV2List (ctx , nil )
476
+
477
+ req := cl .api .DashboardsV2Api .DashboardsV2List (ctx )
478
+ dashboards , _ , err := cl .api .DashboardsV2Api .DashboardsV2ListExecute (req )
465
479
if err != nil {
466
480
err = fmt .Errorf ("listing dashboards: %w" , errorDetail (err ))
467
481
return nil , err
@@ -476,7 +490,8 @@ func (cl *Client) DashboardDelete(ctx context.Context, id string) error {
476
490
return err
477
491
}
478
492
479
- _ , err = cl .api .DashboardsV2Api .DashboardsV2Delete (ctx , id , nil )
493
+ req := cl .api .DashboardsV2Api .DashboardsV2Delete (ctx , id )
494
+ _ , err = cl .api .DashboardsV2Api .DashboardsV2DeleteExecute (req )
480
495
if err != nil {
481
496
err = fmt .Errorf ("deleting dashboard: %w" , errorDetail (err ))
482
497
return err
@@ -492,9 +507,15 @@ func (cl *Client) setup(client, secret, organization string) error {
492
507
493
508
config := iotclient .NewConfiguration ()
494
509
if organization != "" {
495
- config .DefaultHeader = map [string ]string {"X-Organization" : organization }
510
+ config .AddDefaultHeader ("X-Organization" , organization )
511
+ }
512
+ config .Host = baseURL + "/iot"
513
+ config .Servers = iotclient.ServerConfigurations {
514
+ {
515
+ URL : config .Host ,
516
+ Description : "No description provided" ,
517
+ },
496
518
}
497
- config .BasePath = baseURL + "/iot"
498
519
cl .api = iotclient .NewAPIClient (config )
499
520
500
521
return nil
0 commit comments