github.com/nathanielks/terraform@v0.6.1-0.20170509030759-13e1a62319dc/builtin/providers/gitlab/util.go (about)

     1  package gitlab
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"github.com/hashicorp/terraform/helper/schema"
     7  	gitlab "github.com/xanzy/go-gitlab"
     8  )
     9  
    10  // copied from ../github/util.go
    11  func validateValueFunc(values []string) schema.SchemaValidateFunc {
    12  	return func(v interface{}, k string) (we []string, errors []error) {
    13  		value := v.(string)
    14  		valid := false
    15  		for _, role := range values {
    16  			if value == role {
    17  				valid = true
    18  				break
    19  			}
    20  		}
    21  
    22  		if !valid {
    23  			errors = append(errors, fmt.Errorf("%s is an invalid value for argument %s", value, k))
    24  		}
    25  		return
    26  	}
    27  }
    28  
    29  func stringToVisibilityLevel(s string) *gitlab.VisibilityLevelValue {
    30  	lookup := map[string]gitlab.VisibilityLevelValue{
    31  		"private":  gitlab.PrivateVisibility,
    32  		"internal": gitlab.InternalVisibility,
    33  		"public":   gitlab.PublicVisibility,
    34  	}
    35  
    36  	value, ok := lookup[s]
    37  	if !ok {
    38  		return nil
    39  	}
    40  	return &value
    41  }
    42  
    43  func visibilityLevelToString(v gitlab.VisibilityLevelValue) *string {
    44  	lookup := map[gitlab.VisibilityLevelValue]string{
    45  		gitlab.PrivateVisibility:  "private",
    46  		gitlab.InternalVisibility: "internal",
    47  		gitlab.PublicVisibility:   "public",
    48  	}
    49  	value, ok := lookup[v]
    50  	if !ok {
    51  		return nil
    52  	}
    53  	return &value
    54  }