Skip to content

Commit

Permalink
Added ValidateFunc for sigsci_corp_list (#155)
Browse files Browse the repository at this point in the history
* chore: remove unnecessary double quote

* add: added validStringLength function

* add: added ValidateFunc for sigsci_corp_list

* Update provider/lib.go

Co-authored-by: Shawn Smith <[email protected]>

* Update provider/resource_corp_list.go

Co-authored-by: Shawn Smith <[email protected]>

---------

Co-authored-by: Shawn Smith <[email protected]>
  • Loading branch information
ponkio-o and shawnps authored Apr 4, 2023
1 parent eff8c04 commit 29d2536
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
6 changes: 6 additions & 0 deletions provider/lib.go
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,12 @@ func existsInRange(needle int, min, max int) bool {
return false
}

func validStringLength(needle string, min, max int) bool {
length := len(needle)

return length >= min && length <= max
}

func expandRuleConditions(conditionsResource *schema.Set) []sigsci.Condition {
var conditions []sigsci.Condition
for _, genericElement := range conditionsResource.List() {
Expand Down
2 changes: 1 addition & 1 deletion provider/resource_corp_integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func resourceCorpIntegration() *schema.Resource {
ForceNew: true,
ValidateFunc: func(val interface{}, key string) (warns []string, errs []error) {
if !existsInString(val.(string), "mailingList", "slack", "microsoftTeams") {
return nil, []error{fmt.Errorf(`"received type %q is invalid. should be "mailingList", "slack", or "microsoftTeams"`, val.(string))}
return nil, []error{fmt.Errorf(`received type %q is invalid. should be "mailingList", "slack", or "microsoftTeams"`, val.(string))}
}
return nil, nil
},
Expand Down
18 changes: 18 additions & 0 deletions provider/resource_corp_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,35 @@ func resourceCorpList() *schema.Resource {
Description: "Descriptive list name",
Required: true,
ForceNew: true,
ValidateFunc: func(val interface{}, key string) (warns []string, errs []error) {
if !validStringLength(val.(string), 3, 32) {
return nil, []error{fmt.Errorf(`received name %q is invalid. should be min len 3, max len 32`, val.(string))}
}
return nil, nil
},
},
"type": {
Type: schema.TypeString,
Description: "List types (string, ip, country, wildcard, signal)",
Required: true,
ForceNew: true,
ValidateFunc: func(val interface{}, key string) (warns []string, errs []error) {
if !existsInString(val.(string), "string", "ip", "country", "wildcard", "signal") {
return nil, []error{fmt.Errorf(`received type %q is invalid. should be "string", "ip", "country", "wildcard" or "signal"`, val.(string))}
}
return nil, nil
},
},
"description": {
Type: schema.TypeString,
Description: "Optional list description",
Optional: true,
ValidateFunc: func(val interface{}, key string) (warns []string, errs []error) {
if !validStringLength(val.(string), 0, 140) {
return nil, []error{fmt.Errorf(`received description %q is invalid. should be max len 140`, val.(string))}
}
return nil, nil
},
},
"entries": {
Type: schema.TypeSet,
Expand Down

0 comments on commit 29d2536

Please sign in to comment.