@@ -23,6 +23,7 @@ import (
23
23
"os"
24
24
25
25
"github.com/antihax/optional"
26
+ "github.com/arduino/arduino-cloud-cli/internal/config"
26
27
iotclient "github.com/arduino/iot-client-go"
27
28
)
28
29
@@ -33,10 +34,10 @@ type Client struct {
33
34
}
34
35
35
36
// NewClient returns a new client implementing the Client interface.
36
- // It needs a ClientID and SecretID for cloud authentication.
37
- func NewClient (clientID , secretID string ) (* Client , error ) {
37
+ // It needs client Credentials for cloud authentication.
38
+ func NewClient (cred * config. Credentials ) (* Client , error ) {
38
39
cl := & Client {}
39
- err := cl .setup (clientID , secretID )
40
+ err := cl .setup (cred . Client , cred . Secret , cred . Organization )
40
41
if err != nil {
41
42
err = fmt .Errorf ("instantiate new iot client: %w" , err )
42
43
return nil , err
@@ -350,7 +351,7 @@ func (cl *Client) DashboardDelete(id string) error {
350
351
return nil
351
352
}
352
353
353
- func (cl * Client ) setup (client , secret string ) error {
354
+ func (cl * Client ) setup (client , secret , organization string ) error {
354
355
// Get the access token in exchange of client_id and client_secret
355
356
tok , err := token (client , secret )
356
357
if err != nil {
@@ -363,7 +364,11 @@ func (cl *Client) setup(client, secret string) error {
363
364
364
365
// Create an instance of the iot-api Go client, we pass an empty config
365
366
// because defaults are ok
366
- cl .api = iotclient .NewAPIClient (iotclient .NewConfiguration ())
367
+ config := iotclient .NewConfiguration ()
368
+ if organization != "" {
369
+ config .DefaultHeader = map [string ]string {"X-Organization" : organization }
370
+ }
371
+ cl .api = iotclient .NewAPIClient (config )
367
372
368
373
return nil
369
374
}
0 commit comments