diff --git a/internal/command/delta.go b/internal/command/delta.go index b9ee701..6c7457d 100644 --- a/internal/command/delta.go +++ b/internal/command/delta.go @@ -15,6 +15,7 @@ import ( "net/http" "os" "path/filepath" + "regexp" "github.com/score-spec/score-humanitec/internal/humanitec" api "github.com/score-spec/score-humanitec/internal/humanitec_go/client" @@ -74,6 +75,11 @@ func delta(cmd *cobra.Command, args []string) error { return err } + // Validate the ID + if err := validateIDs(); err != nil { + return err + } + // Prepare a new deployment // log.Print("Preparing a new deployment...\n") @@ -124,3 +130,22 @@ func delta(cmd *cobra.Command, args []string) error { return nil } + +var validID = regexp.MustCompile(`^[a-z0-9](?:-?[a-z0-9]+)+$`) + +func validateIDs() error { + ids := []struct { + name string + id string + }{ + {"organization", orgID}, {"application", appID}, {"environment", envID}, + } + + for _, e := range ids { + if !validID.MatchString(e.id) { + return fmt.Errorf("invalid %s id '%s'. Did you use the %s name instead of the id?", e.name, e.id, e.name) + } + } + + return nil +}