Added a name validator to the push command
This commit is contained in:
parent
0d973145f5
commit
c834a00e22
|
@ -6,6 +6,7 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/hashicorp/atlas-go/archive"
|
"github.com/hashicorp/atlas-go/archive"
|
||||||
|
@ -16,6 +17,11 @@ import (
|
||||||
// archiveTemplateEntry is the name the template always takes within the slug.
|
// archiveTemplateEntry is the name the template always takes within the slug.
|
||||||
const archiveTemplateEntry = ".packer-template"
|
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 {
|
type PushCommand struct {
|
||||||
Meta
|
Meta
|
||||||
|
|
||||||
|
@ -88,6 +94,11 @@ func (c *PushCommand) Run(args []string) int {
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !reName.MatchString(name) {
|
||||||
|
c.Ui.Error(errInvalidName.Error())
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
// Determine our token
|
// Determine our token
|
||||||
if token == "" {
|
if token == "" {
|
||||||
token = push.Token
|
token = push.Token
|
||||||
|
|
|
@ -39,7 +39,7 @@ each category, the available configuration keys are alphabetized.
|
||||||
|
|
||||||
- `name` (string) - Name of the build configuration in the build service. If
|
- `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
|
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
|
### Optional
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue