Skip to content

[WIRE-419] Update iot-client to latest generated artifact #155

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Jun 21, 2024
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 0 additions & 19 deletions .licenses/go/github.com/antihax/optional.dep.yml

This file was deleted.

2 changes: 1 addition & 1 deletion .licenses/go/github.com/arduino/iot-client-go.dep.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
name: github.com/arduino/iot-client-go
version: v1.4.4
version: v1.4.5-0.20240416140423-fb8fda8a47af
type: go
summary:
homepage: https://pkg.go.dev/github.com/arduino/iot-client-go
Expand Down
10 changes: 9 additions & 1 deletion cli/device/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,16 +92,24 @@ func (r listResult) String() string {
return "No devices found."
}
t := table.New()
t.SetHeader("Name", "ID", "Board", "FQBN", "SerialNumber", "Tags")
t.SetHeader("Name", "ID", "Board", "FQBN", "SerialNumber", "Status", "Tags")
for _, device := range r.devices {
t.AddRow(
device.Name,
device.ID,
device.Board,
device.FQBN,
device.Serial,
dereferenceString(device.Status),
strings.Join(device.Tags, ","),
)
}
return t.Render()
}

func dereferenceString(s *string) string {
if s == nil {
return ""
}
return *s
}
4 changes: 2 additions & 2 deletions command/dashboard/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ func Create(ctx context.Context, params *CreateParams, cred *config.Credentials)

// Name passed as parameter has priority over name from template
if params.Name != nil {
dashboard.Name = *params.Name
dashboard.Name = params.Name
}
// If name is not specified in the template, it should be passed as parameter
if dashboard.Name == "" {
if dashboard.Name == nil || *dashboard.Name == "" {
return nil, errors.New("dashboard name not specified")
}

Expand Down
4 changes: 3 additions & 1 deletion command/dashboard/dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ type DashboardInfo struct {
func getDashboardInfo(dashboard *iotclient.ArduinoDashboardv2) *DashboardInfo {
var widgets []string
for _, w := range dashboard.Widgets {
widgets = append(widgets, w.Name)
if w.Name != nil {
widgets = append(widgets, *w.Name)
}
}
info := &DashboardInfo{
Name: dashboard.Name,
Expand Down
9 changes: 8 additions & 1 deletion command/device/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,14 @@ func Create(ctx context.Context, params *CreateParams, cred *config.Credentials)
ID: dev.Id,
Board: dev.Type,
Serial: dev.Serial,
FQBN: dev.Fqbn,
FQBN: dereferenceString(dev.Fqbn),
}
return devInfo, nil
}

func dereferenceString(s *string) string {
if s == nil {
return ""
}
return *s
}
4 changes: 2 additions & 2 deletions command/device/creategeneric.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ func CreateGeneric(ctx context.Context, params *CreateGenericParams, cred *confi
ID: dev.Id,
Board: dev.Type,
Serial: dev.Serial,
FQBN: dev.Fqbn,
FQBN: dereferenceString(dev.Fqbn),
},
Password: pass.SuggestedPassword,
Password: dereferenceString(pass.SuggestedPassword),
}
return devInfo, nil
}
2 changes: 1 addition & 1 deletion command/device/createlora.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ func getDeviceLoraInfo(ctx context.Context, iotClient *iot.Client, loraDev *iotc
ID: dev.Id,
Board: dev.Type,
Serial: dev.Serial,
FQBN: dev.Fqbn,
FQBN: dereferenceString(dev.Fqbn),
},
AppEUI: loraDev.AppEui,
AppKey: loraDev.AppKey,
Expand Down
4 changes: 3 additions & 1 deletion command/device/device.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ type DeviceInfo struct {
Serial string `json:"serial_number"`
FQBN string `json:"fqbn"`
Tags []string `json:"tags,omitempty"`
Status *string `json:"status,omitempty"`
}

func getDeviceInfo(device *iotclient.ArduinoDevicev2) (*DeviceInfo, error) {
Expand All @@ -45,8 +46,9 @@ func getDeviceInfo(device *iotclient.ArduinoDevicev2) (*DeviceInfo, error) {
ID: device.Id,
Board: device.Type,
Serial: device.Serial,
FQBN: device.Fqbn,
FQBN: dereferenceString(device.Fqbn),
Tags: tags,
Status: device.DeviceStatus,
}
return dev, nil
}
2 changes: 1 addition & 1 deletion command/device/provision.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ func (p provision) configBoard(ctx context.Context) error {
}

logrus.Info("Sending certificate authority key")
b, err = hex.DecodeString(cert.AuthorityKeyIdentifier)
b, err = hex.DecodeString(dereferenceString(cert.AuthorityKeyIdentifier))
if err != nil {
return fmt.Errorf("decoding certificate authority key id: %w", err)
}
Expand Down
7 changes: 7 additions & 0 deletions command/ota/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,10 @@ func Generate(binFile string, outFile string, fqbn string) error {

return nil
}

func dereferenceString(s *string) string {
if s == nil {
return ""
}
return *s
}
7 changes: 4 additions & 3 deletions command/ota/massupload.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ import (
"context"
"errors"
"fmt"
"github.com/sirupsen/logrus"
"os"
"path/filepath"

"github.com/sirupsen/logrus"

"github.com/arduino/arduino-cloud-cli/config"
"github.com/arduino/arduino-cloud-cli/internal/iot"
"github.com/arduino/arduino-cloud-cli/internal/ota"
Expand Down Expand Up @@ -179,8 +180,8 @@ func validateDevices(ctx context.Context, lister deviceLister, ids []string, fqb
continue
}
// Device FQBN doesn't match the passed one
if found.Fqbn != fqbn {
inv := Result{ID: id, Err: fmt.Errorf("has FQBN '%s' instead of '%s'", found.Fqbn, fqbn)}
if dereferenceString(found.Fqbn) != fqbn {
inv := Result{ID: id, Err: fmt.Errorf("has FQBN '%s' instead of '%s'", dereferenceString(found.Fqbn), fqbn)}
invalid = append(invalid, inv)
continue
}
Expand Down
6 changes: 3 additions & 3 deletions command/ota/massupload_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,9 @@ func TestValidateDevices(t *testing.T) {

mockDeviceList := deviceListerTest{
list: []iotclient.ArduinoDevicev2{
{Id: idCorrect1, Fqbn: correctFQBN},
{Id: idCorrect2, Fqbn: correctFQBN},
{Id: idNotValid, Fqbn: wrongFQBN},
{Id: idCorrect1, Fqbn: &correctFQBN},
{Id: idCorrect2, Fqbn: &correctFQBN},
{Id: idNotValid, Fqbn: &wrongFQBN},
},
}

Expand Down
2 changes: 1 addition & 1 deletion command/ota/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func Upload(ctx context.Context, params *UploadParams, cred *config.Credentials)
otaFile = filepath.Join(otaDir, "temp.ota")
defer os.RemoveAll(otaDir)

err = Generate(params.File, otaFile, dev.Fqbn)
err = Generate(params.File, otaFile, dereferenceString(dev.Fqbn))
if err != nil {
return fmt.Errorf("%s: %w", "cannot generate .ota file", err)
}
Expand Down
9 changes: 8 additions & 1 deletion command/thing/bind.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func Bind(ctx context.Context, params *BindParams, cred *config.Credentials) err
}

thing := &iotclient.ThingUpdate{
DeviceId: params.DeviceID,
DeviceId: &params.DeviceID,
}

err = iotClient.ThingUpdate(ctx, params.ID, thing, true)
Expand All @@ -52,3 +52,10 @@ func Bind(ctx context.Context, params *BindParams, cred *config.Credentials) err

return nil
}

func dereferenceString(s *string) string {
if s == nil {
return ""
}
return *s
}
39 changes: 2 additions & 37 deletions command/thing/clone.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (

"github.com/arduino/arduino-cloud-cli/config"
"github.com/arduino/arduino-cloud-cli/internal/iot"
iotclient "github.com/arduino/iot-client-go"
)

// CloneParams contains the parameters needed to clone a thing.
Expand All @@ -39,16 +38,9 @@ func Clone(ctx context.Context, params *CloneParams, cred *config.Credentials) (
return nil, err
}

thing, err := retrieve(ctx, iotClient, params.CloneID)
newThing, err := iotClient.ThingClone(ctx, params.CloneID, params.Name)
if err != nil {
return nil, err
}

thing.Name = params.Name
force := true
newThing, err := iotClient.ThingCreate(ctx, thing, force)
if err != nil {
return nil, err
return nil, fmt.Errorf("cloning thing %s: %w", params.CloneID, err)
}

t, err := getThingInfo(newThing)
Expand All @@ -57,30 +49,3 @@ func Clone(ctx context.Context, params *CloneParams, cred *config.Credentials) (
}
return t, nil
}

type thingFetcher interface {
ThingShow(ctx context.Context, id string) (*iotclient.ArduinoThing, error)
}

func retrieve(ctx context.Context, fetcher thingFetcher, thingID string) (*iotclient.ThingCreate, error) {
clone, err := fetcher.ThingShow(ctx, thingID)
if err != nil {
return nil, fmt.Errorf("%s: %w", "retrieving the thing to be cloned", err)
}

thing := &iotclient.ThingCreate{}

// Copy variables
for _, p := range clone.Properties {
thing.Properties = append(thing.Properties, iotclient.Property{
Name: p.Name,
Permission: p.Permission,
UpdateParameter: p.UpdateParameter,
UpdateStrategy: p.UpdateStrategy,
Type: p.Type,
VariableName: p.VariableName,
})
}

return thing, nil
}
4 changes: 2 additions & 2 deletions command/thing/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ func Create(ctx context.Context, params *CreateParams, cred *config.Credentials)

// Name passed as parameter has priority over name from template
if params.Name != nil {
thing.Name = *params.Name
thing.Name = params.Name
}
// If name is not specified in the template, it should be passed as parameter
if thing.Name == "" {
if dereferenceString(thing.Name) == "" {
return nil, errors.New("thing name not specified")
}

Expand Down
2 changes: 1 addition & 1 deletion command/thing/thing.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func getThingInfo(thing *iotclient.ArduinoThing) (*ThingInfo, error) {
info := &ThingInfo{
Name: thing.Name,
ID: thing.Id,
DeviceID: thing.DeviceId,
DeviceID: dereferenceString(thing.DeviceId),
Variables: vars,
Tags: tags,
}
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ require (
github.com/arduino/arduino-cli v0.0.0-20221116144942-76251df9241a
github.com/arduino/go-paths-helper v1.7.0
github.com/arduino/go-win32-utils v1.0.0
github.com/arduino/iot-client-go v1.4.4
github.com/arduino/iot-client-go v1.4.5-0.20240416140423-fb8fda8a47af
github.com/gofrs/uuid v4.2.0+incompatible
github.com/google/go-cmp v0.6.0
github.com/howeyc/crc16 v0.0.0-20171223171357-2b2a61e366a6
github.com/icza/bitio v1.1.0
github.com/manifoldco/promptui v0.9.0
github.com/sirupsen/logrus v1.9.0
github.com/spf13/cobra v1.3.0
Expand Down Expand Up @@ -43,7 +44,6 @@ require (
github.com/golang/protobuf v1.5.3 // indirect
github.com/h2non/filetype v1.1.3 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/icza/bitio v1.1.0 // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
github.com/josharian/intern v1.0.0 // indirect
Expand Down
5 changes: 3 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ github.com/arduino/go-properties-orderedmap v1.7.1 h1:HQ9Pn/mk3+XyfrE39EEvaZwJkr
github.com/arduino/go-properties-orderedmap v1.7.1/go.mod h1:DKjD2VXY/NZmlingh4lSFMEYCVubfeArCsGPGDwb2yk=
github.com/arduino/go-win32-utils v1.0.0 h1:/cXB86sOJxOsCHP7sQmXGLkdValwJt56mIwOHYxgQjQ=
github.com/arduino/go-win32-utils v1.0.0/go.mod h1:0jqM7doGEAs6DaJCxxhLBUDS5OawrqF48HqXkcEie/Q=
github.com/arduino/iot-client-go v1.4.4 h1:FICCXD5uCZ0scGG6RioOlpZamDqgSD1l/fQlFwKR284=
github.com/arduino/iot-client-go v1.4.4/go.mod h1:gYvpMt7Qw+OSScTLyIlCnpbvy9y96ey/2zhB4w6FoK0=
github.com/arduino/iot-client-go v1.4.5-0.20240416140423-fb8fda8a47af h1:/dbu5I3q09kOePrWbBVMrKEPDM8KKUIGATQpwWc/wWo=
github.com/arduino/iot-client-go v1.4.5-0.20240416140423-fb8fda8a47af/go.mod h1:aKaQRceeYIeMpyFyEUGJj4/5WFETZD1CrarYGn4v5Nc=
github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hCbHZ8TKRvWD2dDTCfh9M9ya+I9JpbB7O8o=
github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmVTwzkszR9V5SSuryQ31EELlFMUz1kKyl939pY=
github.com/armon/go-metrics v0.3.10/go.mod h1:4O98XIr/9W0sxpJ8UaYkvjk10Iff7SnFrb4QAOwNTFc=
Expand Down Expand Up @@ -287,6 +287,7 @@ github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:
github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
github.com/icza/bitio v1.1.0 h1:ysX4vtldjdi3Ygai5m1cWy4oLkhWTAi+SyO6HC8L9T0=
github.com/icza/bitio v1.1.0/go.mod h1:0jGnlLAx8MKMr9VGnn/4YrvZiprkvBelsVIbA9Jjr9A=
github.com/icza/mighty v0.0.0-20180919140131-cfd07d671de6 h1:8UsGZ2rr2ksmEru6lToqnXgA8Mz1DP11X4zSJ159C3k=
github.com/icza/mighty v0.0.0-20180919140131-cfd07d671de6/go.mod h1:xQig96I1VNBDIWGCdTt54nHt6EeI639SmHycLYL7FkA=
github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM=
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
Expand Down
Loading
Loading