Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

app name and id directive limits #71

Merged
merged 5 commits into from
Jan 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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