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

Log warning when atlantis.yml is used as config #816

Merged
merged 1 commit into from
Oct 30, 2019
Merged
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
15 changes: 11 additions & 4 deletions server/events/yaml/parser_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
11 changes: 11 additions & 0 deletions server/events/yaml/parser_validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, "")
Expand Down