github.com/vtorhonen/terraform@v0.9.0-beta2.0.20170307220345-5d894e4ffda7/builtin/providers/pagerduty/util.go (about) 1 package pagerduty 2 3 import ( 4 "fmt" 5 6 pagerduty "github.com/PagerDuty/go-pagerduty" 7 "github.com/hashicorp/terraform/helper/schema" 8 ) 9 10 // Validate a value against a set of possible values 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 _, val := range values { 16 if value == val { 17 valid = true 18 break 19 } 20 } 21 22 if !valid { 23 errors = append(errors, fmt.Errorf("%#v is an invalid value for argument %s. Must be one of %#v", value, k, values)) 24 } 25 return 26 } 27 } 28 29 // getVendors retrieves all PagerDuty vendors and returns a list of []pagerduty.Vendor 30 func getVendors(client *pagerduty.Client) ([]pagerduty.Vendor, error) { 31 var offset uint 32 var totalCount int 33 var vendors []pagerduty.Vendor 34 35 for { 36 o := &pagerduty.ListVendorOptions{ 37 APIListObject: pagerduty.APIListObject{ 38 Limit: 100, 39 Total: 1, 40 Offset: offset, 41 }, 42 } 43 44 resp, err := client.ListVendors(*o) 45 46 if err != nil { 47 return nil, err 48 } 49 50 for _, v := range resp.Vendors { 51 totalCount++ 52 vendors = append(vendors, v) 53 } 54 55 rOffset := uint(resp.Offset) 56 returnedCount := uint(len(resp.Vendors)) 57 rTotal := uint(resp.Total) 58 59 if resp.More && uint(totalCount) != uint(rTotal) { 60 offset = returnedCount + rOffset 61 continue 62 } 63 64 break 65 } 66 67 return vendors, nil 68 }