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

Add cron expression length validation #25

Merged
merged 3 commits into from
Jan 7, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 1.9.0 (January 6, 2023)

NEW FEATURES:

* added validation for the cron expression length to only allow 6-7 characters expressions. PR [#25](https://github.com/jfrog/terraform-provider-shared/pull/25)

## 1.8.0 (December 21, 2022)

BUG FIXES:
Expand Down
15 changes: 15 additions & 0 deletions validator/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,21 @@ func Cron(value interface{}, _ cty.Path) diag.Diagnostics {
return diags
}

func CronLength(value interface{}, _ cty.Path) diag.Diagnostics {
var diags diag.Diagnostics
cron := regexp.MustCompile("[^\\s]+").FindAllString(value.(string), -1)
danielmkn marked this conversation as resolved.
Show resolved Hide resolved

if len(cron) > 7 || len(cron) < 6 {
danielmkn marked this conversation as resolved.
Show resolved Hide resolved
diags = append(diags, diag.Diagnostic{
Severity: diag.Error,
Summary: "Invalid Cron expression, value should be between 6 and 7 characters long",
danielmkn marked this conversation as resolved.
Show resolved Hide resolved
Detail: fmt.Sprintf("%s is not a valid cron", value),
})
}

return diags
}

var CommaSeperatedList = validation.ToDiagFunc(
validation.StringMatch(regexp.MustCompile(`.+(?:,.+)*`), "must be comma separated string"),
)
Expand Down