Skip to content

Commit

Permalink
Merge pull request #25 from jfrog/cron-length
Browse files Browse the repository at this point in the history
Add cron expression length validation
  • Loading branch information
danielmkn committed Jan 7, 2023
2 parents 7b50824 + f7068e3 commit 337e4fb
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
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 parts 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 := strings.Split(value.(string), " ")

if len(cron) < 6 || len(cron) > 7 {
diags = append(diags, diag.Diagnostic{
Severity: diag.Error,
Summary: "Invalid Cron expression, value should be between 6 and 7 parts long",
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

0 comments on commit 337e4fb

Please sign in to comment.