提交 1acdc9ab 编写于 作者: O openeuler-ci-bot 提交者: Gitee

!34 config: check files in configuration.toml

Merge pull request !34 from Vanient/conf
......@@ -192,6 +192,10 @@ func loadConfig(path string) (config.TomlConfig, error) {
}
_, err = toml.Decode(string(configData), &conf)
if err = checkFilesInConf(conf); err != nil {
return conf, err
}
return conf, err
}
......@@ -276,3 +280,29 @@ func setupWorkingDirectories(dirs []string) error {
return nil
}
func checkFilesInConf(conf config.TomlConfig) error {
confFiles := []string{conf.Storage.ConfigPath, conf.Image.RegistryConfigPath, conf.Image.SignaturePolicyPath}
for _, file := range confFiles {
if file != "" {
if !filepath.IsAbs(file) {
return errors.Errorf("file path %q in configuration is not an absolute path", file)
}
fi, err := os.Stat(file)
if err != nil {
return errors.Wrapf(err, "stat file %q in configuration failed", file)
}
if !fi.Mode().IsRegular() {
return errors.Errorf("file %s in configuration should be a regular file", fi.Name())
}
if err := util.CheckFileSize(file, constant.MaxFileSize); err != nil {
return err
}
}
}
return nil
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册