Skip to content

Commit

Permalink
[ignore] Add utils function in mso/utils.go and rename from util.go t…
Browse files Browse the repository at this point in the history
…o utils.go
  • Loading branch information
lhercot committed Feb 11, 2023
1 parent 859c0ce commit b9e04d0
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 12 deletions.
12 changes: 0 additions & 12 deletions mso/util.go

This file was deleted.

65 changes: 65 additions & 0 deletions mso/utils.go
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
}

0 comments on commit b9e04d0

Please sign in to comment.