Skip to content

Commit aa10bab

Browse files
zxxf18陆丹峰
authored andcommitted
bce-iot-10546: Set BAETYL_HOST_SN (baetyl#392)
1 parent 75a6d9b commit aa10bab

File tree

4 files changed

+14
-0
lines changed

4 files changed

+14
-0
lines changed

master/config.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package master
22

33
import (
44
"fmt"
5+
"io/ioutil"
56
"os"
67
"path/filepath"
78
"runtime"
@@ -55,6 +56,16 @@ func (c *Config) Validate() error {
5556
utils.SetEnv(baetyl.EnvMasterAPIKey, addr)
5657
}
5758

59+
if c.SNFile != "" {
60+
snByte, err := ioutil.ReadFile(c.SNFile)
61+
if err != nil {
62+
fmt.Printf("failed to load SN file: %s", err.Error())
63+
} else {
64+
sn := strings.TrimSpace(string(snByte))
65+
utils.SetEnv(baetyl.EnvKeyHostSN, sn)
66+
}
67+
}
68+
5869
utils.SetEnv(baetyl.EnvKeyMasterAPIVersion, "v1")
5970
utils.SetEnv(baetyl.EnvKeyHostOS, runtime.GOOS)
6071
utils.SetEnv(baetyl.EnvKeyServiceMode, c.Mode)

master/config_linux.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ type Config struct {
1616
Logger logger.LogInfo `yaml:"logger" json:"logger" default:"{\"path\":\"var/log/baetyl/baetyl.log\"}"`
1717
OTALog logger.LogInfo `yaml:"otalog" json:"otalog" default:"{\"path\":\"var/db/baetyl/ota.log\",\"format\":\"json\"}"`
1818
Grace time.Duration `yaml:"grace" json:"grace" default:"30s"`
19+
SNFile string `yaml:"snfile" json:"snfile"`
1920

2021
// cache config file path
2122
File string

master/config_others.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ type Config struct {
1616
Logger logger.LogInfo `yaml:"logger" json:"logger" default:"{\"path\":\"var/log/baetyl/baetyl.log\"}"`
1717
OTALog logger.LogInfo `yaml:"otalog" json:"otalog" default:"{\"path\":\"var/db/baetyl/ota.log\",\"format\":\"json\"}"`
1818
Grace time.Duration `yaml:"grace" json:"grace" default:"30s"`
19+
SNFile string `yaml:"snfile" json:"snfile"`
1920

2021
// cache config file path
2122
File string

sdk/baetyl-go/context.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ const (
6060
// new envs
6161
EnvKeyHostID = "BAETYL_HOST_ID"
6262
EnvKeyHostOS = "BAETYL_HOST_OS"
63+
EnvKeyHostSN = "BAETYL_HOST_SN"
6364
EnvKeyMasterAPISocket = "BAETYL_MASTER_API_SOCKET"
6465
EnvKeyMasterAPIAddress = "BAETYL_MASTER_API_ADDRESS"
6566
EnvKeyMasterAPIVersion = "BAETYL_MASTER_API_VERSION"

0 commit comments

Comments
 (0)