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 1 commit
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
Prev Previous commit
Next Next commit
adding chars to regex and adding silent analytics messages
  • Loading branch information
Jordan Singer committed Jan 13, 2023
commit af58a848bf32e77cd9f71565f5650fc569b097a3
10 changes: 6 additions & 4 deletions cmd/klotho/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,14 +220,16 @@ func run(cmd *cobra.Command, args []string) (err error) {

if appCfg.AppName == "" {
return errors.New("'app' required")
} else if len(appCfg.AppName) > 20 {
return fmt.Errorf("'app' must be less than 20 characters in length. 'app' was %s", cfg.appName)
} else if len(appCfg.AppName) > 25 {
zap.S().With(logging.SilentAnalytics(fmt.Sprintf("'app' must be less than 20 characters in length. 'app' was %s", cfg.appName)))
return fmt.Errorf("'app' must be less than 25 characters in length. 'app' was %s", cfg.appName)
}
match, err := regexp.MatchString(`^[A-Za-z0-9-_]+$`, cfg.appName)
match, err := regexp.MatchString(`^[\w-.:/]+$`, cfg.appName)
if err != nil {
return err
} else if !match {
return fmt.Errorf("'app' can only contain alphanumeric, -, and _. 'app' was %s", cfg.appName)
zap.S().With(logging.SilentAnalytics(fmt.Sprintf("'app' can only contain alphanumeric, -, and _. 'app' was %s", cfg.appName)))
return fmt.Errorf("'app' can only contain alphanumeric, -, _, ., :, and /. 'app' was %s", cfg.appName)
}

if appCfg.Provider == "" {
Expand Down
8 changes: 4 additions & 4 deletions pkg/annotation/capability.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ func ParseCapability(s string) (*Capability, error) {
}
id, _ := cap.Directives.String("id")
if id != "" {
if len(id) > 20 {
return cap, fmt.Errorf("'id' must be less than 20 characters in length. 'id' was %s", 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(`^[A-Za-z0-9-_]+$`, 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)
return cap, fmt.Errorf("'id' can only contain alphanumeric, -, _, ., :, and /. 'id' was %s", id)
}
}
cap.ID = id
Expand Down
4 changes: 4 additions & 0 deletions pkg/logging/fields.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ type astNodeField struct {
content string
}

func SilentAnalytics(message string) zap.Field {
return zap.String("silentAnalytics", message)
}

// DescribeKlothoFields is intended for unit testing expected log lines.
//
// This returns a map whose keys are the field keys, and whose values are descriptions of the Klotho-provided zap fields.
Expand Down