Target for cheking not commited config files.

Signed-off-by: laurentiuNiculae <themelopeus@gmail.com>

Separated updateDistSpec functionality

Removed rewriting of config when distSpecVersion was wrong
This commit is contained in:
laurentiuNiculae
2022-03-30 16:02:03 +03:00
committed by Ramkumar Chinchani
parent efc55b013e
commit 0d4cc8736d
4 changed files with 79 additions and 90 deletions
+17 -15
View File
@@ -354,24 +354,23 @@ func applyDefaultValues(config *config.Config, viperInstance *viper.Viper) {
}
}
if config.DistSpecVersion != distspec.Version {
log.Warn().Err(errors.ErrBadConfig).
Msgf("config dist-spec version: %s differs from version actually used: %s, will be corrected automatically",
config.DistSpecVersion, distspec.Version)
// rewrite the config file
viperInstance.Set("distSpecVersion", distspec.Version)
err := viperInstance.WriteConfig()
if err != nil {
log.Warn().Err(errors.ErrBadConfig).
Msg("can't rewrite the config file")
}
config.DistSpecVersion = distspec.Version
if !config.Storage.GC && viperInstance.Get("storage::gcdelay") == nil {
config.Storage.GCDelay = 0
}
}
func updateDistSpecVersion(config *config.Config) {
if config.DistSpecVersion == distspec.Version {
return
}
log.Warn().
Msgf("config dist-spec version: %s differs from version actually used: %s",
config.DistSpecVersion, distspec.Version)
config.DistSpecVersion = distspec.Version
}
func LoadConfiguration(config *config.Config, configPath string) error {
// Default is dot (.) but because we allow glob patterns in authz
// we need another key delimiter.
@@ -413,5 +412,8 @@ func LoadConfiguration(config *config.Config, configPath string) error {
return err
}
// update distSpecVersion
updateDistSpecVersion(config)
return nil
}