Added a name validator to the push command

This commit is contained in:
Chris Bednarski 2015-08-26 12:16:18 -07:00
parent 0d973145f5
commit c834a00e22
2 changed files with 12 additions and 1 deletions

View File

@ -6,6 +6,7 @@ import (
"os"
"os/signal"
"path/filepath"
"regexp"
"strings"
"github.com/hashicorp/atlas-go/archive"
@ -16,6 +17,11 @@ import (
// archiveTemplateEntry is the name the template always takes within the slug.
const archiveTemplateEntry = ".packer-template"
var (
reName = regexp.MustCompile("^[a-zA-Z0-9-_/]+$")
errInvalidName = fmt.Errorf("Your build name can only contain these characters: [a-zA-Z0-9-_]+")
)
type PushCommand struct {
Meta
@ -88,6 +94,11 @@ func (c *PushCommand) Run(args []string) int {
return 1
}
if !reName.MatchString(name) {
c.Ui.Error(errInvalidName.Error())
return 1
}
// Determine our token
if token == "" {
token = push.Token

View File

@ -39,7 +39,7 @@ each category, the available configuration keys are alphabetized.
- `name` (string) - Name of the build configuration in the build service. If
this doesn't exist, it will be created (by default). Note that the name can
cannot contain dots. `[a-zA-Z0-9-_]+` are safe.
cannot contain dots. `[a-zA-Z0-9-_/]+` are safe.
### Optional