mirror of
https://git.vectorsigma.ru/public/atlantis.git
synced 2026-08-03 06:18:21 +00:00
Error out if atlantis.yml is used as config file
This commit is contained in:
@@ -27,7 +27,14 @@ type ParserValidator struct{}
|
||||
// for the repo at absRepoDir.
|
||||
// Returns an error if for some reason it can't read that directory.
|
||||
func (p *ParserValidator) HasRepoCfg(absRepoDir string) (bool, error) {
|
||||
_, err := os.Stat(p.repoCfgPath(absRepoDir))
|
||||
// Checks for a config file with an invalid extension (atlantis.yml)
|
||||
const invalidExtensionFilename = "atlantis.yml"
|
||||
_, err := os.Stat(p.repoCfgPath(absRepoDir, invalidExtensionFilename))
|
||||
if err == nil {
|
||||
return false, errors.Errorf("found %q as config file; rename using the .yaml extension - %q", invalidExtensionFilename, AtlantisYAMLFilename)
|
||||
}
|
||||
|
||||
_, err = os.Stat(p.repoCfgPath(absRepoDir, AtlantisYAMLFilename))
|
||||
if os.IsNotExist(err) {
|
||||
return false, nil
|
||||
}
|
||||
@@ -38,7 +45,7 @@ func (p *ParserValidator) HasRepoCfg(absRepoDir string) (bool, error) {
|
||||
// repo at absRepoDir.
|
||||
// If there was no config file, it will return an os.IsNotExist(error).
|
||||
func (p *ParserValidator) ParseRepoCfg(absRepoDir string, globalCfg valid.GlobalCfg, repoID string) (valid.RepoCfg, error) {
|
||||
configFile := p.repoCfgPath(absRepoDir)
|
||||
configFile := p.repoCfgPath(absRepoDir, AtlantisYAMLFilename)
|
||||
configData, err := ioutil.ReadFile(configFile) // nolint: gosec
|
||||
|
||||
if err != nil {
|
||||
@@ -122,8 +129,8 @@ func (p *ParserValidator) validateRawGlobalCfg(rawCfg raw.GlobalCfg, defaultCfg
|
||||
return validCfg, nil
|
||||
}
|
||||
|
||||
func (p *ParserValidator) repoCfgPath(repoDir string) string {
|
||||
return filepath.Join(repoDir, AtlantisYAMLFilename)
|
||||
func (p *ParserValidator) repoCfgPath(repoDir, cfgFilename string) string {
|
||||
return filepath.Join(repoDir, cfgFilename)
|
||||
}
|
||||
|
||||
func (p *ParserValidator) validateProjectNames(config valid.RepoCfg) error {
|
||||
|
||||
@@ -33,6 +33,17 @@ func TestHasRepoCfg_FileDoesNotExist(t *testing.T) {
|
||||
Equals(t, false, exists)
|
||||
}
|
||||
|
||||
func TestHasRepoCfg_InvalidFileExtension(t *testing.T) {
|
||||
tmpDir, cleanup := TempDir(t)
|
||||
defer cleanup()
|
||||
_, err := os.Create(filepath.Join(tmpDir, "atlantis.yml"))
|
||||
Ok(t, err)
|
||||
|
||||
r := yaml.ParserValidator{}
|
||||
_, err = r.HasRepoCfg(tmpDir)
|
||||
ErrContains(t, "found \"atlantis.yml\" as config file; rename using the .yaml extension - \"atlantis.yaml\"", err)
|
||||
}
|
||||
|
||||
func TestParseRepoCfg_DirDoesNotExist(t *testing.T) {
|
||||
r := yaml.ParserValidator{}
|
||||
_, err := r.ParseRepoCfg("/not/exist", globalCfg, "")
|
||||
|
||||
Reference in New Issue
Block a user