mirror of
https://git.vectorsigma.ru/public/atlantis.git
synced 2026-08-03 13:58:32 +00:00
We should only allow project names (which are specified in an atlantis.yaml file) that don't need to be url escaped. The one exceptional character is '/' which we allow because users like to name their projects to match the directory they're in. We use the same rule that Terraform uses for workspace names. I've also changed the characters that are replaced when writing out the plan filename to only remove invalid filename characters instead of just allowing alphanumeric. This is the smallest amount of change required to ensure the filename is valid.
43 lines
1.4 KiB
Go
43 lines
1.4 KiB
Go
// Package runtime holds code for actually running commands vs. preparing
|
|
// and constructing.
|
|
package runtime
|
|
|
|
import (
|
|
"fmt"
|
|
"regexp"
|
|
|
|
"github.com/hashicorp/go-version"
|
|
"github.com/runatlantis/atlantis/server/events/yaml/valid"
|
|
"github.com/runatlantis/atlantis/server/logging"
|
|
)
|
|
|
|
type TerraformExec interface {
|
|
RunCommandWithVersion(log *logging.SimpleLogger, path string, args []string, v *version.Version, workspace string) (string, error)
|
|
}
|
|
|
|
// MustConstraint returns a constraint. It panics on error.
|
|
func MustConstraint(constraint string) version.Constraints {
|
|
c, err := version.NewConstraint(constraint)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return c
|
|
}
|
|
|
|
// invalidFilenameChars matches chars that are invalid for linux and windows
|
|
// filenames.
|
|
// From https://www.oreilly.com/library/view/regular-expressions-cookbook/9781449327453/ch08s25.html
|
|
var invalidFilenameChars = regexp.MustCompile(`[\\/:"*?<>|]`)
|
|
|
|
// GetPlanFilename returns the filename (not the path) of the generated tf plan
|
|
// given a workspace and maybe a project's config.
|
|
func GetPlanFilename(workspace string, maybeCfg *valid.Project) string {
|
|
var unescapedFilename string
|
|
if maybeCfg == nil || maybeCfg.Name == nil {
|
|
unescapedFilename = fmt.Sprintf("%s.tfplan", workspace)
|
|
} else {
|
|
unescapedFilename = fmt.Sprintf("%s-%s.tfplan", *maybeCfg.Name, workspace)
|
|
}
|
|
return invalidFilenameChars.ReplaceAllLiteralString(unescapedFilename, "-")
|
|
}
|