Skip to content
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

SM-1172: download remote config if not valid #116

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
11 changes: 9 additions & 2 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,15 @@ func GetRemoteConfig(configURL string, filePathOnDisk string) (*Config, error) {

// Check if the file already exists
_, err := os.Stat(filePathOnDisk)
if !os.IsNotExist(err) && err == nil {
return ReadConfigFromPath(filePathOnDisk)
if err == nil {
conf, err := ReadConfigFromPath(filePathOnDisk)
if err != nil {
return nil, fmt.Errorf("failed to read config file: %w", err)
}
// check if the config file has the required fields
if conf != nil && conf.Services.Auth.ClientID != "" && conf.Services.Auth.ClientSecret != "" && conf.Services.Ca.CaFingerprint != "" {
return conf, nil
}
}

if configURL == "" {
Expand Down
8 changes: 5 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,6 @@ func main() {
// will retry for about 1 hour in case if no internet connection, so we are not interrupt device pairing process
config, confErr := dimoConfig.ReadConfig(logger, configFiles, configURL, confFileName)
logger.Debug().Msgf("Config: %+v\n", config)
if confErr != nil {
logger.Fatal().Err(confErr).Msg("unable to read config file")
}

logger.Info().Msgf("Starting DIMO Edge Network, with log level: %s", zerolog.GlobalLevel())

Expand All @@ -179,6 +176,11 @@ func main() {
fh := hooks.NewLogRateLimiterHook(ds)
logger = logger.Hook(&hooks.LogHook{DataSender: ds}).Hook(fh)

// log certificate errors
if confErr != nil {
logger.Fatal().Err(confErr).Msg("unable to read config file")
}

// log certificate errors
if certErr != nil {
logger.Error().Ctx(context.WithValue(context.Background(), hooks.LogToMqtt, "true")).Msgf("Error from SignWeb3Certificate : %s", certErr.Error())
Expand Down
Loading