Skip to content

Commit 48b6616

Browse files
committed
Read Cloud client/secret from environment variables
1 parent 8034348 commit 48b6616

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

internal/config/config.go

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package config
1919

2020
import (
2121
"fmt"
22+
"os"
2223

2324
"github.com/spf13/viper"
2425
)
@@ -39,10 +40,24 @@ func Retrieve() (*Config, error) {
3940
v.AddConfigPath(".")
4041
err := v.ReadInConfig()
4142
if err != nil {
42-
err = fmt.Errorf("%s: %w", "retrieving config file", err)
43+
fmt.Errorf("%s: %w", "retrieving config file", err)
44+
} else {
45+
v.Unmarshal(conf)
46+
}
47+
48+
client, found := os.LookupEnv("ARDUINO_CLOUD_CLIENT")
49+
if !found {
50+
err = fmt.Errorf("%s: %w", "Unable to retrieve token client", err)
51+
return nil, err
52+
53+
}
54+
secret, found := os.LookupEnv("ARDUINO_CLOUD_SECRET")
55+
if !found {
56+
err = fmt.Errorf("%s: %w", "Unable to retrieve token secret", err)
4357
return nil, err
4458
}
4559

46-
v.Unmarshal(conf)
60+
conf.Client = client
61+
conf.Secret = secret
4762
return conf, nil
4863
}

0 commit comments

Comments
 (0)