-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Splitting `OneOf` and `NoneOf` by "case sensitivity" * `OneOf` and `NoneOf` are case sensitive * `OneOfCaseInsensitive` and `NoneOfCaseInsensitive` are ... case insensitive instead * Changelog entries
- Loading branch information
Ivan De Marino
authored
Jun 27, 2022
1 parent
668b4ce
commit 40680ac
Showing
7 changed files
with
366 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
```release-note:enhancement | ||
stringvalidator: 4 new validation functions, `OneOf()` and `NoneOf()` (case sensitive), and `OneOfCaseInsensitive()` and `NoneOfCaseInsensitive()` (case insensitive) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,28 @@ | ||
package stringvalidator | ||
|
||
import ( | ||
"github.com/hashicorp/terraform-plugin-framework-validators/internal/primitivevalidator" | ||
"github.com/hashicorp/terraform-plugin-framework/attr" | ||
"github.com/hashicorp/terraform-plugin-framework/tfsdk" | ||
"github.com/hashicorp/terraform-plugin-framework/types" | ||
) | ||
|
||
// NoneOf checks that the string held in the attribute | ||
// is none of the given `unacceptableStrings`. | ||
// | ||
// String comparison case sensitiveness is controlled by the `caseSensitive` argument. | ||
func NoneOf(caseSensitive bool, unacceptableStrings ...string) tfsdk.AttributeValidator { | ||
return &acceptableStringsAttributeValidator{ | ||
func NoneOf(unacceptableStrings ...string) tfsdk.AttributeValidator { | ||
unacceptableStringValues := make([]attr.Value, 0, len(unacceptableStrings)) | ||
for _, s := range unacceptableStrings { | ||
unacceptableStringValues = append(unacceptableStringValues, types.String{Value: s}) | ||
} | ||
|
||
return primitivevalidator.NoneOf(unacceptableStringValues...) | ||
} | ||
|
||
// NoneOfCaseInsensitive checks that the string held in the attribute | ||
// is none of the given `unacceptableStrings`, irrespective of case sensitivity. | ||
func NoneOfCaseInsensitive(unacceptableStrings ...string) tfsdk.AttributeValidator { | ||
return &acceptableStringsCaseInsensitiveAttributeValidator{ | ||
unacceptableStrings, | ||
caseSensitive, | ||
false, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,28 @@ | ||
package stringvalidator | ||
|
||
import ( | ||
"github.com/hashicorp/terraform-plugin-framework-validators/internal/primitivevalidator" | ||
"github.com/hashicorp/terraform-plugin-framework/attr" | ||
"github.com/hashicorp/terraform-plugin-framework/tfsdk" | ||
"github.com/hashicorp/terraform-plugin-framework/types" | ||
) | ||
|
||
// OneOf checks that the string held in the attribute | ||
// is one of the given `acceptableStrings`. | ||
// | ||
// String comparison case sensitiveness is controlled by the `caseSensitive` argument. | ||
func OneOf(caseSensitive bool, acceptableStrings ...string) tfsdk.AttributeValidator { | ||
return &acceptableStringsAttributeValidator{ | ||
func OneOf(acceptableStrings ...string) tfsdk.AttributeValidator { | ||
acceptableStringValues := make([]attr.Value, 0, len(acceptableStrings)) | ||
for _, s := range acceptableStrings { | ||
acceptableStringValues = append(acceptableStringValues, types.String{Value: s}) | ||
} | ||
|
||
return primitivevalidator.OneOf(acceptableStringValues...) | ||
} | ||
|
||
// OneOfCaseInsensitive checks that the string held in the attribute | ||
// is one of the given `acceptableStrings`, irrespective of case sensitivity. | ||
func OneOfCaseInsensitive(acceptableStrings ...string) tfsdk.AttributeValidator { | ||
return &acceptableStringsCaseInsensitiveAttributeValidator{ | ||
acceptableStrings, | ||
caseSensitive, | ||
true, | ||
} | ||
} |
Oops, something went wrong.