diff --git a/cmd/klotho/main.go b/cmd/klotho/main.go index d8591296a..7d9c57d27 100644 --- a/cmd/klotho/main.go +++ b/cmd/klotho/main.go @@ -1,6 +1,7 @@ package main import ( + "github.com/klothoplatform/klotho/pkg/cli" "github.com/klothoplatform/klotho/pkg/updater" ) diff --git a/pkg/annotation/capability.go b/pkg/annotation/capability.go index e8784f682..e807a0028 100644 --- a/pkg/annotation/capability.go +++ b/pkg/annotation/capability.go @@ -1,6 +1,7 @@ package annotation import ( + "fmt" "regexp" "github.com/pkg/errors" @@ -30,7 +31,19 @@ func ParseCapability(s string) (*Capability, error) { if err != nil { return cap, errors.Wrap(err, "could not parse directives") } - cap.ID, _ = cap.Directives.String("id") + id, _ := cap.Directives.String("id") + if id != "" { + if len(id) > 25 { + return cap, fmt.Errorf("'id' must be less than 25 characters in length. 'id' was %s", id) + } + match, err := regexp.MatchString(`^[\w-_.:/]+$`, id) + if err != nil { + return cap, errors.Wrap(err, "could not parse 'id' directive") + } else if !match { + return cap, fmt.Errorf("'id' can only contain alphanumeric, -, _, ., :, and /. 'id' was %s", id) + } + } + cap.ID = id } return cap, nil diff --git a/pkg/cli/klothomain.go b/pkg/cli/klothomain.go index 3f0283f30..0c90f6adf 100644 --- a/pkg/cli/klothomain.go +++ b/pkg/cli/klothomain.go @@ -2,8 +2,10 @@ package cli import ( "fmt" - "github.com/klothoplatform/klotho/pkg/cli_config" "os" + "regexp" + + "github.com/klothoplatform/klotho/pkg/cli_config" "github.com/klothoplatform/klotho/pkg/updater" @@ -238,7 +240,18 @@ func (km KlothoMain) run(cmd *cobra.Command, args []string) (err error) { if appCfg.AppName == "" { return errors.New("'app' required") + } else if len(appCfg.AppName) > 25 { + analyticsClient.Error("Klotho parameter check failed. 'app' must be less than 20 characters in length") + return fmt.Errorf("'app' must be less than 25 characters in length. 'app' was %s", cfg.appName) } + match, err := regexp.MatchString(`^[\w-.:/]+$`, cfg.appName) + if err != nil { + return err + } else if !match { + analyticsClient.Error("Klotho parameter check failed. 'app' can only contain alphanumeric, -, _, ., :, and /.") + return fmt.Errorf("'app' can only contain alphanumeric, -, _, ., :, and /. 'app' was %s", cfg.appName) + } + if appCfg.Provider == "" { return errors.New("'provider' required") }