Skip to content

Commit

Permalink
- redownload the remote-config if it is not exists or if file has not…
Browse files Browse the repository at this point in the history
… the required fields
  • Loading branch information
zakharenkodmytro committed Nov 6, 2024
1 parent d1e2b4d commit df713e7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
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

0 comments on commit df713e7

Please sign in to comment.