-
Notifications
You must be signed in to change notification settings - Fork 50
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
Fix semver validation #590
Conversation
The existing validation prevented from specifying a pre-release version which is a valid semver. The PR changes it to utilize the go-version library helper which follows the SemVer spec.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@@ -95,8 +96,7 @@ func validateStringInSlice(valid []string, ignoreCase bool) schema.SchemaValidat | |||
// validateSemVer ensures a specified string is a SemVer. | |||
func validateSemVer(v interface{}, path cty.Path) diag.Diagnostics { | |||
var diagnostics diag.Diagnostics | |||
|
|||
if !regexp.MustCompile(`^v?\d+.\d+.\d+$`).MatchString(v.(string)) { | |||
if _, err := version.NewSemver(v.(string)); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good to me. Given that go-version is used in the provider but not for the validation I want to confirm before merging that the consul resource is okay with a user specifying a pre-release version. In other words, is there a reason why the original implementor chose only to support official release versions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Disregard.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I want to confirm before merging that the consul resource is okay with a user specifying a pre-release version
Might have been a miss. But we do publicly release pre-release versions of our products (can be found here). On the Consul side, we optionally enable testing out these pre-release versions on HCP for certain customers to unblock their testing/validation processes.
The existing validation prevented from specifying a pre-release version which is also a valid semver.
The PR changes it to utilize the go-version library helper which follows the SemVer spec.