-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ignore] Add utils function in mso/utils.go and rename from util.go t…
…o utils.go
- Loading branch information
Showing
2 changed files
with
65 additions
and
12 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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,65 @@ | ||
package mso | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"regexp" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/helper/schema" | ||
) | ||
|
||
const version = 1 | ||
|
||
func toStringList(configured interface{}) []string { | ||
vs := make([]string, 0, 1) | ||
val, ok := configured.(string) | ||
if ok && val != "" { | ||
vs = append(vs, val) | ||
} | ||
return vs | ||
} | ||
|
||
func makeTestVariable(s string) string { | ||
return fmt.Sprintf("acctest_%s", s) | ||
} | ||
|
||
func epgRefValidation() schema.SchemaValidateFunc { | ||
return func(i interface{}, k string) (s []string, es []error) { | ||
v, ok := i.(string) | ||
if !ok { | ||
es = append(es, fmt.Errorf("expected type of %s to be string", k)) | ||
return | ||
} | ||
res, err := regexp.MatchString(`^\/schemas\/(.)+\/templates\/(.)+\/anps\/(.)+\/epgs\/(.)+$`, v) | ||
if !res { | ||
log.Printf("err: %v\n", err) | ||
es = append(es, fmt.Errorf("invalid epg reference:expected format /schema/{schema_id}/templates/{template_name}/anps/{anp_name}/epgs/{epg_name}")) | ||
} | ||
return | ||
} | ||
} | ||
|
||
func externalEpgRefValidation() schema.SchemaValidateFunc { | ||
return func(i interface{}, k string) (s []string, es []error) { | ||
v, ok := i.(string) | ||
if !ok { | ||
es = append(es, fmt.Errorf("expected type of %s to be string", k)) | ||
return | ||
} | ||
res, err := regexp.MatchString(`^\/schemas\/(.)+\/templates\/(.)+\/externalEpgs\/(.)+$`, v) | ||
if !res { | ||
log.Printf("err: %v\n", err) | ||
es = append(es, fmt.Errorf("invalid external epg reference:expected format /schema/{schema_id}/template/{template_name}/externalEpgs/{external_epg_name}")) | ||
} | ||
return | ||
} | ||
} | ||
|
||
func StringInSlice(a string, list []string) bool { | ||
for _, b := range list { | ||
if b == a { | ||
return true | ||
} | ||
} | ||
return false | ||
} |