Skip to content

Commit

Permalink
app name and id directive limits (#71)
Browse files Browse the repository at this point in the history
  • Loading branch information
jhsinger-klotho authored Jan 13, 2023
1 parent 72c9c60 commit 5151d94
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
1 change: 1 addition & 0 deletions cmd/klotho/main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (

"github.com/klothoplatform/klotho/pkg/cli"
"github.com/klothoplatform/klotho/pkg/updater"
)
Expand Down
15 changes: 14 additions & 1 deletion pkg/annotation/capability.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package annotation

import (
"fmt"
"regexp"

"github.com/pkg/errors"
Expand Down Expand Up @@ -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
Expand Down
15 changes: 14 additions & 1 deletion pkg/cli/klothomain.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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")
}
Expand Down

0 comments on commit 5151d94

Please sign in to comment.