mirror of
https://github.com/opentofu/opentofu.git
synced 2025-02-25 18:45:20 -06:00
Remove underscores from private identifiers that were not to be exported and strictly use lowercase letters instead.
This commit is contained in:
parent
0d5ee1e953
commit
5567732814
@ -2,16 +2,16 @@ package consul
|
|||||||
|
|
||||||
import "time"
|
import "time"
|
||||||
|
|
||||||
type _AttrReader interface {
|
type attrReader interface {
|
||||||
GetBool(_SchemaAttr) bool
|
GetBool(schemaAttr) bool
|
||||||
GetBoolOK(_SchemaAttr) (b, ok bool)
|
GetBoolOK(schemaAttr) (b, ok bool)
|
||||||
GetDurationOK(_SchemaAttr) (time.Duration, bool)
|
GetDurationOK(schemaAttr) (time.Duration, bool)
|
||||||
GetFloat64OK(_SchemaAttr) (float64, bool)
|
GetFloat64OK(schemaAttr) (float64, bool)
|
||||||
GetIntOK(_SchemaAttr) (int, bool)
|
GetIntOK(schemaAttr) (int, bool)
|
||||||
GetIntPtr(_SchemaAttr) *int
|
GetIntPtr(schemaAttr) *int
|
||||||
GetString(_SchemaAttr) string
|
GetString(schemaAttr) string
|
||||||
GetStringOK(_SchemaAttr) (string, bool)
|
GetStringOK(schemaAttr) (string, bool)
|
||||||
GetStringPtr(_SchemaAttr) *string
|
GetStringPtr(schemaAttr) *string
|
||||||
GetStringSlice(attrName _SchemaAttr) []string
|
GetStringSlice(attrName schemaAttr) []string
|
||||||
BackingType() string
|
BackingType() string
|
||||||
}
|
}
|
||||||
|
@ -6,21 +6,21 @@ import (
|
|||||||
"github.com/hashicorp/terraform/helper/schema"
|
"github.com/hashicorp/terraform/helper/schema"
|
||||||
)
|
)
|
||||||
|
|
||||||
type _ConfigReader struct {
|
type configReader struct {
|
||||||
d *schema.ResourceData
|
d *schema.ResourceData
|
||||||
}
|
}
|
||||||
|
|
||||||
func _NewConfigReader(d *schema.ResourceData) *_ConfigReader {
|
func newConfigReader(d *schema.ResourceData) *configReader {
|
||||||
return &_ConfigReader{
|
return &configReader{
|
||||||
d: d,
|
d: d,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *_ConfigReader) BackingType() string {
|
func (r *configReader) BackingType() string {
|
||||||
return "config"
|
return "config"
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *_ConfigReader) GetBool(attrName _SchemaAttr) bool {
|
func (r *configReader) GetBool(attrName schemaAttr) bool {
|
||||||
if v, ok := r.d.GetOk(string(attrName)); ok {
|
if v, ok := r.d.GetOk(string(attrName)); ok {
|
||||||
return v.(bool)
|
return v.(bool)
|
||||||
}
|
}
|
||||||
@ -28,7 +28,7 @@ func (r *_ConfigReader) GetBool(attrName _SchemaAttr) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *_ConfigReader) GetBoolOK(attrName _SchemaAttr) (b, ok bool) {
|
func (r *configReader) GetBoolOK(attrName schemaAttr) (b, ok bool) {
|
||||||
if v, ok := r.d.GetOk(string(attrName)); ok {
|
if v, ok := r.d.GetOk(string(attrName)); ok {
|
||||||
return v.(bool), true
|
return v.(bool), true
|
||||||
}
|
}
|
||||||
@ -36,7 +36,7 @@ func (r *_ConfigReader) GetBoolOK(attrName _SchemaAttr) (b, ok bool) {
|
|||||||
return false, false
|
return false, false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *_ConfigReader) GetDurationOK(attrName _SchemaAttr) (time.Duration, bool) {
|
func (r *configReader) GetDurationOK(attrName schemaAttr) (time.Duration, bool) {
|
||||||
if v, ok := r.d.GetOk(string(attrName)); ok {
|
if v, ok := r.d.GetOk(string(attrName)); ok {
|
||||||
d, err := time.ParseDuration(v.(string))
|
d, err := time.ParseDuration(v.(string))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -48,7 +48,7 @@ func (r *_ConfigReader) GetDurationOK(attrName _SchemaAttr) (time.Duration, bool
|
|||||||
return time.Duration(0), false
|
return time.Duration(0), false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *_ConfigReader) GetFloat64OK(attrName _SchemaAttr) (float64, bool) {
|
func (r *configReader) GetFloat64OK(attrName schemaAttr) (float64, bool) {
|
||||||
if v, ok := r.d.GetOk(string(attrName)); ok {
|
if v, ok := r.d.GetOk(string(attrName)); ok {
|
||||||
return v.(float64), true
|
return v.(float64), true
|
||||||
}
|
}
|
||||||
@ -56,7 +56,7 @@ func (r *_ConfigReader) GetFloat64OK(attrName _SchemaAttr) (float64, bool) {
|
|||||||
return 0.0, false
|
return 0.0, false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *_ConfigReader) GetIntOK(attrName _SchemaAttr) (int, bool) {
|
func (r *configReader) GetIntOK(attrName schemaAttr) (int, bool) {
|
||||||
if v, ok := r.d.GetOk(string(attrName)); ok {
|
if v, ok := r.d.GetOk(string(attrName)); ok {
|
||||||
return v.(int), true
|
return v.(int), true
|
||||||
}
|
}
|
||||||
@ -64,7 +64,7 @@ func (r *_ConfigReader) GetIntOK(attrName _SchemaAttr) (int, bool) {
|
|||||||
return 0, false
|
return 0, false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *_ConfigReader) GetIntPtr(attrName _SchemaAttr) *int {
|
func (r *configReader) GetIntPtr(attrName schemaAttr) *int {
|
||||||
if v, ok := r.d.GetOk(string(attrName)); ok {
|
if v, ok := r.d.GetOk(string(attrName)); ok {
|
||||||
i := v.(int)
|
i := v.(int)
|
||||||
return &i
|
return &i
|
||||||
@ -73,7 +73,7 @@ func (r *_ConfigReader) GetIntPtr(attrName _SchemaAttr) *int {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *_ConfigReader) GetString(attrName _SchemaAttr) string {
|
func (r *configReader) GetString(attrName schemaAttr) string {
|
||||||
if v, ok := r.d.GetOk(string(attrName)); ok {
|
if v, ok := r.d.GetOk(string(attrName)); ok {
|
||||||
return v.(string)
|
return v.(string)
|
||||||
}
|
}
|
||||||
@ -81,7 +81,7 @@ func (r *_ConfigReader) GetString(attrName _SchemaAttr) string {
|
|||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *_ConfigReader) GetStringOK(attrName _SchemaAttr) (string, bool) {
|
func (r *configReader) GetStringOK(attrName schemaAttr) (string, bool) {
|
||||||
if v, ok := r.d.GetOk(string(attrName)); ok {
|
if v, ok := r.d.GetOk(string(attrName)); ok {
|
||||||
return v.(string), true
|
return v.(string), true
|
||||||
}
|
}
|
||||||
@ -89,7 +89,7 @@ func (r *_ConfigReader) GetStringOK(attrName _SchemaAttr) (string, bool) {
|
|||||||
return "", false
|
return "", false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *_ConfigReader) GetStringPtr(attrName _SchemaAttr) *string {
|
func (r *configReader) GetStringPtr(attrName schemaAttr) *string {
|
||||||
if v, ok := r.d.GetOk(string(attrName)); ok {
|
if v, ok := r.d.GetOk(string(attrName)); ok {
|
||||||
switch v.(type) {
|
switch v.(type) {
|
||||||
case string:
|
case string:
|
||||||
@ -103,7 +103,7 @@ func (r *_ConfigReader) GetStringPtr(attrName _SchemaAttr) *string {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *_ConfigReader) GetStringSlice(attrName _SchemaAttr) []string {
|
func (r *configReader) GetStringSlice(attrName schemaAttr) []string {
|
||||||
if listRaw, ok := r.d.GetOk(string(attrName)); ok {
|
if listRaw, ok := r.d.GetOk(string(attrName)); ok {
|
||||||
return listRaw.([]string)
|
return listRaw.([]string)
|
||||||
}
|
}
|
||||||
|
@ -2,13 +2,13 @@ package consul
|
|||||||
|
|
||||||
import "github.com/hashicorp/terraform/helper/schema"
|
import "github.com/hashicorp/terraform/helper/schema"
|
||||||
|
|
||||||
type _AttrWriter interface {
|
type attrWriter interface {
|
||||||
BackingType() string
|
BackingType() string
|
||||||
|
|
||||||
SetBool(_SchemaAttr, bool) error
|
SetBool(schemaAttr, bool) error
|
||||||
SetFloat64(_SchemaAttr, float64) error
|
SetFloat64(schemaAttr, float64) error
|
||||||
SetList(_SchemaAttr, []interface{}) error
|
SetList(schemaAttr, []interface{}) error
|
||||||
SetMap(_SchemaAttr, map[string]interface{}) error
|
SetMap(schemaAttr, map[string]interface{}) error
|
||||||
SetSet(_SchemaAttr, *schema.Set) error
|
SetSet(schemaAttr, *schema.Set) error
|
||||||
SetString(_SchemaAttr, string) error
|
SetString(schemaAttr, string) error
|
||||||
}
|
}
|
||||||
|
@ -7,21 +7,21 @@ import (
|
|||||||
"github.com/hashicorp/terraform/helper/schema"
|
"github.com/hashicorp/terraform/helper/schema"
|
||||||
)
|
)
|
||||||
|
|
||||||
type _AttrWriterMap struct {
|
type attrWriterMap struct {
|
||||||
m map[string]interface{}
|
m map[string]interface{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func _NewMapWriter(m map[string]interface{}) *_AttrWriterMap {
|
func newMapWriter(m map[string]interface{}) *attrWriterMap {
|
||||||
return &_AttrWriterMap{
|
return &attrWriterMap{
|
||||||
m: m,
|
m: m,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *_AttrWriterMap) BackingType() string {
|
func (w *attrWriterMap) BackingType() string {
|
||||||
return "map"
|
return "map"
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *_AttrWriterMap) Set(name _SchemaAttr, v interface{}) error {
|
func (w *attrWriterMap) Set(name schemaAttr, v interface{}) error {
|
||||||
switch u := v.(type) {
|
switch u := v.(type) {
|
||||||
case string:
|
case string:
|
||||||
return w.SetString(name, u)
|
return w.SetString(name, u)
|
||||||
@ -36,35 +36,35 @@ func (w *_AttrWriterMap) Set(name _SchemaAttr, v interface{}) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *_AttrWriterMap) SetBool(name _SchemaAttr, b bool) error {
|
func (w *attrWriterMap) SetBool(name schemaAttr, b bool) error {
|
||||||
w.m[string(name)] = fmt.Sprintf("%t", b)
|
w.m[string(name)] = fmt.Sprintf("%t", b)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *_AttrWriterMap) SetFloat64(name _SchemaAttr, f float64) error {
|
func (w *attrWriterMap) SetFloat64(name schemaAttr, f float64) error {
|
||||||
w.m[string(name)] = strconv.FormatFloat(f, 'g', -1, 64)
|
w.m[string(name)] = strconv.FormatFloat(f, 'g', -1, 64)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *_AttrWriterMap) SetList(name _SchemaAttr, l []interface{}) error {
|
func (w *attrWriterMap) SetList(name schemaAttr, l []interface{}) error {
|
||||||
panic(fmt.Sprintf("PROVIDER BUG: Cat set a list within a map for %s", name))
|
panic(fmt.Sprintf("PROVIDER BUG: Cat set a list within a map for %s", name))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *_AttrWriterMap) SetMap(name _SchemaAttr, m map[string]interface{}) error {
|
func (w *attrWriterMap) SetMap(name schemaAttr, m map[string]interface{}) error {
|
||||||
w.m[string(name)] = m
|
w.m[string(name)] = m
|
||||||
return nil
|
return nil
|
||||||
panic(fmt.Sprintf("PROVIDER BUG: Cat set a map within a map for %s", name))
|
panic(fmt.Sprintf("PROVIDER BUG: Cat set a map within a map for %s", name))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *_AttrWriterMap) SetSet(name _SchemaAttr, s *schema.Set) error {
|
func (w *attrWriterMap) SetSet(name schemaAttr, s *schema.Set) error {
|
||||||
panic(fmt.Sprintf("PROVIDER BUG: Cat set a set within a map for %s", name))
|
panic(fmt.Sprintf("PROVIDER BUG: Cat set a set within a map for %s", name))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *_AttrWriterMap) SetString(name _SchemaAttr, s string) error {
|
func (w *attrWriterMap) SetString(name schemaAttr, s string) error {
|
||||||
w.m[string(name)] = s
|
w.m[string(name)] = s
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *_AttrWriterMap) ToMap() map[string]interface{} {
|
func (w *attrWriterMap) ToMap() map[string]interface{} {
|
||||||
return w.m
|
return w.m
|
||||||
}
|
}
|
||||||
|
@ -2,44 +2,44 @@ package consul
|
|||||||
|
|
||||||
import "github.com/hashicorp/terraform/helper/schema"
|
import "github.com/hashicorp/terraform/helper/schema"
|
||||||
|
|
||||||
type _AttrWriterState struct {
|
type attrWriterState struct {
|
||||||
d *schema.ResourceData
|
d *schema.ResourceData
|
||||||
}
|
}
|
||||||
|
|
||||||
func _NewStateWriter(d *schema.ResourceData) *_AttrWriterState {
|
func newStateWriter(d *schema.ResourceData) *attrWriterState {
|
||||||
return &_AttrWriterState{
|
return &attrWriterState{
|
||||||
d: d,
|
d: d,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *_AttrWriterState) BackingType() string {
|
func (w *attrWriterState) BackingType() string {
|
||||||
return "state"
|
return "state"
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *_AttrWriterState) SetBool(name _SchemaAttr, b bool) error {
|
func (w *attrWriterState) SetBool(name schemaAttr, b bool) error {
|
||||||
return _StateSet(w.d, name, b)
|
return stateSet(w.d, name, b)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *_AttrWriterState) SetID(id string) {
|
func (w *attrWriterState) SetID(id string) {
|
||||||
w.d.SetId(id)
|
w.d.SetId(id)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *_AttrWriterState) SetFloat64(name _SchemaAttr, f float64) error {
|
func (w *attrWriterState) SetFloat64(name schemaAttr, f float64) error {
|
||||||
return _StateSet(w.d, name, f)
|
return stateSet(w.d, name, f)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *_AttrWriterState) SetList(name _SchemaAttr, l []interface{}) error {
|
func (w *attrWriterState) SetList(name schemaAttr, l []interface{}) error {
|
||||||
return _StateSet(w.d, name, l)
|
return stateSet(w.d, name, l)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *_AttrWriterState) SetMap(name _SchemaAttr, m map[string]interface{}) error {
|
func (w *attrWriterState) SetMap(name schemaAttr, m map[string]interface{}) error {
|
||||||
return _StateSet(w.d, name, m)
|
return stateSet(w.d, name, m)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *_AttrWriterState) SetSet(name _SchemaAttr, s *schema.Set) error {
|
func (w *attrWriterState) SetSet(name schemaAttr, s *schema.Set) error {
|
||||||
return _StateSet(w.d, name, []interface{}{s})
|
return stateSet(w.d, name, []interface{}{s})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *_AttrWriterState) SetString(name _SchemaAttr, s string) error {
|
func (w *attrWriterState) SetString(name schemaAttr, s string) error {
|
||||||
return _StateSet(w.d, name, s)
|
return stateSet(w.d, name, s)
|
||||||
}
|
}
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -11,41 +11,41 @@ import (
|
|||||||
|
|
||||||
// Top-level consul_catalog_nodes attributes
|
// Top-level consul_catalog_nodes attributes
|
||||||
const (
|
const (
|
||||||
_CatalogNodes _TypeKey = iota
|
catalogNodes typeKey = iota
|
||||||
_CatalogNodesAllowStale
|
catalogNodesAllowStale
|
||||||
_CatalogNodesDatacenter
|
catalogNodesDatacenter
|
||||||
_CatalogNodesNear
|
catalogNodesNear
|
||||||
_CatalogNodesRequireConsistent
|
catalogNodesRequireConsistent
|
||||||
_CatalogNodesToken
|
catalogNodesToken
|
||||||
_CatalogNodesWaitIndex
|
catalogNodesWaitIndex
|
||||||
_CatalogNodesWaitTime
|
catalogNodesWaitTime
|
||||||
)
|
)
|
||||||
|
|
||||||
// node.* attributes
|
// node.* attributes
|
||||||
const (
|
const (
|
||||||
_CatalogNodeID _TypeKey = iota
|
catalogNodeID typeKey = iota
|
||||||
_CatalogNodeName
|
catalogNodeName
|
||||||
_CatalogNodeAddress
|
catalogNodeAddress
|
||||||
_CatalogNodeTaggedAddresses
|
catalogNodeTaggedAddresses
|
||||||
_CatalogNodeMeta
|
catalogNodeMeta
|
||||||
)
|
)
|
||||||
|
|
||||||
// node.tagged_addresses.* attributes
|
// node.tagged_addresses.* attributes
|
||||||
const (
|
const (
|
||||||
_CatalogNodeTaggedAddressesLAN _TypeKey = iota
|
catalogNodeTaggedAddressesLAN typeKey = iota
|
||||||
_CatalogNodeTaggedAddressesWAN
|
catalogNodeTaggedAddressesWAN
|
||||||
)
|
)
|
||||||
|
|
||||||
var _CatalogNodeAttrs = map[_TypeKey]*_TypeEntry{
|
var catalogNodeAttrs = map[typeKey]*typeEntry{
|
||||||
_CatalogNodeID: {
|
catalogNodeID: {
|
||||||
APIName: "ID",
|
APIName: "ID",
|
||||||
SchemaName: "id",
|
SchemaName: "id",
|
||||||
Source: _SourceAPIResult,
|
Source: sourceAPIResult,
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
ValidateFuncs: []interface{}{
|
ValidateFuncs: []interface{}{
|
||||||
_ValidateRegexp(`^[\S]+$`),
|
validateRegexp(`^[\S]+$`),
|
||||||
},
|
},
|
||||||
APITest: func(e *_TypeEntry, v interface{}) (interface{}, bool) {
|
APITest: func(e *typeEntry, v interface{}) (interface{}, bool) {
|
||||||
node := v.(*consulapi.Node)
|
node := v.(*consulapi.Node)
|
||||||
|
|
||||||
if id := node.ID; id != "" {
|
if id := node.ID; id != "" {
|
||||||
@ -61,15 +61,15 @@ var _CatalogNodeAttrs = map[_TypeKey]*_TypeEntry{
|
|||||||
return "", false
|
return "", false
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
_CatalogNodeName: {
|
catalogNodeName: {
|
||||||
APIName: "Name",
|
APIName: "Name",
|
||||||
SchemaName: "name",
|
SchemaName: "name",
|
||||||
Source: _SourceAPIResult,
|
Source: sourceAPIResult,
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
ValidateFuncs: []interface{}{
|
ValidateFuncs: []interface{}{
|
||||||
_ValidateRegexp(`^[\S]+$`),
|
validateRegexp(`^[\S]+$`),
|
||||||
},
|
},
|
||||||
APITest: func(e *_TypeEntry, v interface{}) (interface{}, bool) {
|
APITest: func(e *typeEntry, v interface{}) (interface{}, bool) {
|
||||||
node := v.(*consulapi.Node)
|
node := v.(*consulapi.Node)
|
||||||
|
|
||||||
if name := node.Node; name != "" {
|
if name := node.Node; name != "" {
|
||||||
@ -79,12 +79,12 @@ var _CatalogNodeAttrs = map[_TypeKey]*_TypeEntry{
|
|||||||
return "", false
|
return "", false
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
_CatalogNodeAddress: {
|
catalogNodeAddress: {
|
||||||
APIName: "Address",
|
APIName: "Address",
|
||||||
SchemaName: "address",
|
SchemaName: "address",
|
||||||
Source: _SourceAPIResult,
|
Source: sourceAPIResult,
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
APITest: func(e *_TypeEntry, v interface{}) (interface{}, bool) {
|
APITest: func(e *typeEntry, v interface{}) (interface{}, bool) {
|
||||||
node := v.(*consulapi.Node)
|
node := v.(*consulapi.Node)
|
||||||
|
|
||||||
if addr := node.Address; addr != "" {
|
if addr := node.Address; addr != "" {
|
||||||
@ -94,18 +94,18 @@ var _CatalogNodeAttrs = map[_TypeKey]*_TypeEntry{
|
|||||||
return "", false
|
return "", false
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
_CatalogNodeTaggedAddresses: {
|
catalogNodeTaggedAddresses: {
|
||||||
APIName: "TaggedAddresses",
|
APIName: "TaggedAddresses",
|
||||||
SchemaName: "tagged_addresses",
|
SchemaName: "tagged_addresses",
|
||||||
Source: _SourceAPIResult,
|
Source: sourceAPIResult,
|
||||||
Type: schema.TypeMap,
|
Type: schema.TypeMap,
|
||||||
SetMembers: map[_TypeKey]*_TypeEntry{
|
SetMembers: map[typeKey]*typeEntry{
|
||||||
_CatalogNodeTaggedAddressesLAN: {
|
catalogNodeTaggedAddressesLAN: {
|
||||||
APIName: "LAN",
|
APIName: "LAN",
|
||||||
SchemaName: "lan",
|
SchemaName: "lan",
|
||||||
Source: _SourceAPIResult,
|
Source: sourceAPIResult,
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
APITest: func(e *_TypeEntry, v interface{}) (interface{}, bool) {
|
APITest: func(e *typeEntry, v interface{}) (interface{}, bool) {
|
||||||
m := v.(map[string]string)
|
m := v.(map[string]string)
|
||||||
|
|
||||||
if addr, found := m[string(e.SchemaName)]; found {
|
if addr, found := m[string(e.SchemaName)]; found {
|
||||||
@ -115,12 +115,12 @@ var _CatalogNodeAttrs = map[_TypeKey]*_TypeEntry{
|
|||||||
return nil, false
|
return nil, false
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
_CatalogNodeTaggedAddressesWAN: {
|
catalogNodeTaggedAddressesWAN: {
|
||||||
APIName: "WAN",
|
APIName: "WAN",
|
||||||
SchemaName: "wan",
|
SchemaName: "wan",
|
||||||
Source: _SourceAPIResult,
|
Source: sourceAPIResult,
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
APITest: func(e *_TypeEntry, v interface{}) (interface{}, bool) {
|
APITest: func(e *typeEntry, v interface{}) (interface{}, bool) {
|
||||||
m := v.(map[string]string)
|
m := v.(map[string]string)
|
||||||
|
|
||||||
if addr, found := m[string(e.SchemaName)]; found {
|
if addr, found := m[string(e.SchemaName)]; found {
|
||||||
@ -131,26 +131,26 @@ var _CatalogNodeAttrs = map[_TypeKey]*_TypeEntry{
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
APITest: func(e *_TypeEntry, v interface{}) (interface{}, bool) {
|
APITest: func(e *typeEntry, v interface{}) (interface{}, bool) {
|
||||||
node := v.(*consulapi.Node)
|
node := v.(*consulapi.Node)
|
||||||
|
|
||||||
if addrs := node.TaggedAddresses; len(addrs) > 0 {
|
if addrs := node.TaggedAddresses; len(addrs) > 0 {
|
||||||
return _MapStringToMapInterface(addrs), true
|
return mapStringToMapInterface(addrs), true
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil, false
|
return nil, false
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
_CatalogNodeMeta: {
|
catalogNodeMeta: {
|
||||||
APIName: "Meta",
|
APIName: "Meta",
|
||||||
SchemaName: "meta",
|
SchemaName: "meta",
|
||||||
Source: _SourceAPIResult,
|
Source: sourceAPIResult,
|
||||||
Type: schema.TypeMap,
|
Type: schema.TypeMap,
|
||||||
APITest: func(e *_TypeEntry, v interface{}) (interface{}, bool) {
|
APITest: func(e *typeEntry, v interface{}) (interface{}, bool) {
|
||||||
node := v.(*consulapi.Node)
|
node := v.(*consulapi.Node)
|
||||||
|
|
||||||
if meta := node.Meta; len(meta) > 0 {
|
if meta := node.Meta; len(meta) > 0 {
|
||||||
return _MapStringToMapInterface(meta), true
|
return mapStringToMapInterface(meta), true
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil, false
|
return nil, false
|
||||||
@ -158,13 +158,13 @@ var _CatalogNodeAttrs = map[_TypeKey]*_TypeEntry{
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
var _CatalogNodesAttrs = map[_TypeKey]*_TypeEntry{
|
var catalogNodesAttrs = map[typeKey]*typeEntry{
|
||||||
_CatalogNodesAllowStale: {
|
catalogNodesAllowStale: {
|
||||||
SchemaName: "allow_stale",
|
SchemaName: "allow_stale",
|
||||||
Source: _SourceLocalFilter,
|
Source: sourceLocalFilter,
|
||||||
Type: schema.TypeBool,
|
Type: schema.TypeBool,
|
||||||
Default: true,
|
Default: true,
|
||||||
ConfigRead: func(e *_TypeEntry, r _AttrReader) (interface{}, bool) {
|
ConfigRead: func(e *typeEntry, r attrReader) (interface{}, bool) {
|
||||||
b, ok := r.GetBoolOK(e.SchemaName)
|
b, ok := r.GetBoolOK(e.SchemaName)
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, false
|
return nil, false
|
||||||
@ -172,18 +172,18 @@ var _CatalogNodesAttrs = map[_TypeKey]*_TypeEntry{
|
|||||||
|
|
||||||
return b, true
|
return b, true
|
||||||
},
|
},
|
||||||
ConfigUse: func(e *_TypeEntry, v interface{}, target interface{}) error {
|
ConfigUse: func(e *typeEntry, v interface{}, target interface{}) error {
|
||||||
b := v.(bool)
|
b := v.(bool)
|
||||||
queryOpts := target.(*consulapi.QueryOptions)
|
queryOpts := target.(*consulapi.QueryOptions)
|
||||||
queryOpts.AllowStale = b
|
queryOpts.AllowStale = b
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
_CatalogNodesDatacenter: {
|
catalogNodesDatacenter: {
|
||||||
SchemaName: "datacenter",
|
SchemaName: "datacenter",
|
||||||
Source: _SourceLocalFilter,
|
Source: sourceLocalFilter,
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
ConfigRead: func(e *_TypeEntry, r _AttrReader) (interface{}, bool) {
|
ConfigRead: func(e *typeEntry, r attrReader) (interface{}, bool) {
|
||||||
s, ok := r.GetStringOK(e.SchemaName)
|
s, ok := r.GetStringOK(e.SchemaName)
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, false
|
return nil, false
|
||||||
@ -191,18 +191,18 @@ var _CatalogNodesAttrs = map[_TypeKey]*_TypeEntry{
|
|||||||
|
|
||||||
return s, true
|
return s, true
|
||||||
},
|
},
|
||||||
ConfigUse: func(e *_TypeEntry, v interface{}, target interface{}) error {
|
ConfigUse: func(e *typeEntry, v interface{}, target interface{}) error {
|
||||||
s := v.(string)
|
s := v.(string)
|
||||||
queryOpts := target.(*consulapi.QueryOptions)
|
queryOpts := target.(*consulapi.QueryOptions)
|
||||||
queryOpts.Datacenter = s
|
queryOpts.Datacenter = s
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
_CatalogNodesNear: {
|
catalogNodesNear: {
|
||||||
SchemaName: "near",
|
SchemaName: "near",
|
||||||
Source: _SourceLocalFilter,
|
Source: sourceLocalFilter,
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
ConfigRead: func(e *_TypeEntry, r _AttrReader) (interface{}, bool) {
|
ConfigRead: func(e *typeEntry, r attrReader) (interface{}, bool) {
|
||||||
s, ok := r.GetStringOK(e.SchemaName)
|
s, ok := r.GetStringOK(e.SchemaName)
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, false
|
return nil, false
|
||||||
@ -210,25 +210,25 @@ var _CatalogNodesAttrs = map[_TypeKey]*_TypeEntry{
|
|||||||
|
|
||||||
return s, true
|
return s, true
|
||||||
},
|
},
|
||||||
ConfigUse: func(e *_TypeEntry, v interface{}, target interface{}) error {
|
ConfigUse: func(e *typeEntry, v interface{}, target interface{}) error {
|
||||||
s := v.(string)
|
s := v.(string)
|
||||||
queryOpts := target.(*consulapi.QueryOptions)
|
queryOpts := target.(*consulapi.QueryOptions)
|
||||||
queryOpts.Near = s
|
queryOpts.Near = s
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
_CatalogNodes: {
|
catalogNodes: {
|
||||||
SchemaName: "nodes",
|
SchemaName: "nodes",
|
||||||
Source: _SourceAPIResult,
|
Source: sourceAPIResult,
|
||||||
Type: schema.TypeList,
|
Type: schema.TypeList,
|
||||||
ListSchema: _CatalogNodeAttrs,
|
ListSchema: catalogNodeAttrs,
|
||||||
},
|
},
|
||||||
_CatalogNodesRequireConsistent: {
|
catalogNodesRequireConsistent: {
|
||||||
SchemaName: "require_consistent",
|
SchemaName: "require_consistent",
|
||||||
Source: _SourceLocalFilter,
|
Source: sourceLocalFilter,
|
||||||
Type: schema.TypeBool,
|
Type: schema.TypeBool,
|
||||||
Default: false,
|
Default: false,
|
||||||
ConfigRead: func(e *_TypeEntry, r _AttrReader) (interface{}, bool) {
|
ConfigRead: func(e *typeEntry, r attrReader) (interface{}, bool) {
|
||||||
b, ok := r.GetBoolOK(e.SchemaName)
|
b, ok := r.GetBoolOK(e.SchemaName)
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, false
|
return nil, false
|
||||||
@ -236,18 +236,18 @@ var _CatalogNodesAttrs = map[_TypeKey]*_TypeEntry{
|
|||||||
|
|
||||||
return b, true
|
return b, true
|
||||||
},
|
},
|
||||||
ConfigUse: func(e *_TypeEntry, v interface{}, target interface{}) error {
|
ConfigUse: func(e *typeEntry, v interface{}, target interface{}) error {
|
||||||
b := v.(bool)
|
b := v.(bool)
|
||||||
queryOpts := target.(*consulapi.QueryOptions)
|
queryOpts := target.(*consulapi.QueryOptions)
|
||||||
queryOpts.RequireConsistent = b
|
queryOpts.RequireConsistent = b
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
_CatalogNodesToken: {
|
catalogNodesToken: {
|
||||||
SchemaName: "token",
|
SchemaName: "token",
|
||||||
Source: _SourceLocalFilter,
|
Source: sourceLocalFilter,
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
ConfigRead: func(e *_TypeEntry, r _AttrReader) (interface{}, bool) {
|
ConfigRead: func(e *typeEntry, r attrReader) (interface{}, bool) {
|
||||||
s, ok := r.GetStringOK(e.SchemaName)
|
s, ok := r.GetStringOK(e.SchemaName)
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, false
|
return nil, false
|
||||||
@ -255,21 +255,21 @@ var _CatalogNodesAttrs = map[_TypeKey]*_TypeEntry{
|
|||||||
|
|
||||||
return s, true
|
return s, true
|
||||||
},
|
},
|
||||||
ConfigUse: func(e *_TypeEntry, v interface{}, target interface{}) error {
|
ConfigUse: func(e *typeEntry, v interface{}, target interface{}) error {
|
||||||
s := v.(string)
|
s := v.(string)
|
||||||
queryOpts := target.(*consulapi.QueryOptions)
|
queryOpts := target.(*consulapi.QueryOptions)
|
||||||
queryOpts.Token = s
|
queryOpts.Token = s
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
_CatalogNodesWaitIndex: {
|
catalogNodesWaitIndex: {
|
||||||
SchemaName: "wait_index",
|
SchemaName: "wait_index",
|
||||||
Source: _SourceLocalFilter,
|
Source: sourceLocalFilter,
|
||||||
Type: schema.TypeInt,
|
Type: schema.TypeInt,
|
||||||
ValidateFuncs: []interface{}{
|
ValidateFuncs: []interface{}{
|
||||||
_ValidateIntMin(0),
|
validateIntMin(0),
|
||||||
},
|
},
|
||||||
ConfigRead: func(e *_TypeEntry, r _AttrReader) (interface{}, bool) {
|
ConfigRead: func(e *typeEntry, r attrReader) (interface{}, bool) {
|
||||||
i, ok := r.GetIntOK(e.SchemaName)
|
i, ok := r.GetIntOK(e.SchemaName)
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, false
|
return nil, false
|
||||||
@ -277,21 +277,21 @@ var _CatalogNodesAttrs = map[_TypeKey]*_TypeEntry{
|
|||||||
|
|
||||||
return uint64(i), true
|
return uint64(i), true
|
||||||
},
|
},
|
||||||
ConfigUse: func(e *_TypeEntry, v interface{}, target interface{}) error {
|
ConfigUse: func(e *typeEntry, v interface{}, target interface{}) error {
|
||||||
i := v.(uint64)
|
i := v.(uint64)
|
||||||
queryOpts := target.(*consulapi.QueryOptions)
|
queryOpts := target.(*consulapi.QueryOptions)
|
||||||
queryOpts.WaitIndex = i
|
queryOpts.WaitIndex = i
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
_CatalogNodesWaitTime: {
|
catalogNodesWaitTime: {
|
||||||
SchemaName: "wait_time",
|
SchemaName: "wait_time",
|
||||||
Source: _SourceLocalFilter,
|
Source: sourceLocalFilter,
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
ValidateFuncs: []interface{}{
|
ValidateFuncs: []interface{}{
|
||||||
_ValidateDurationMin("0ns"),
|
validateDurationMin("0ns"),
|
||||||
},
|
},
|
||||||
ConfigRead: func(e *_TypeEntry, r _AttrReader) (interface{}, bool) {
|
ConfigRead: func(e *typeEntry, r attrReader) (interface{}, bool) {
|
||||||
d, ok := r.GetDurationOK(e.SchemaName)
|
d, ok := r.GetDurationOK(e.SchemaName)
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, false
|
return nil, false
|
||||||
@ -299,7 +299,7 @@ var _CatalogNodesAttrs = map[_TypeKey]*_TypeEntry{
|
|||||||
|
|
||||||
return d, true
|
return d, true
|
||||||
},
|
},
|
||||||
ConfigUse: func(e *_TypeEntry, v interface{}, target interface{}) error {
|
ConfigUse: func(e *typeEntry, v interface{}, target interface{}) error {
|
||||||
d := v.(time.Duration)
|
d := v.(time.Duration)
|
||||||
queryOpts := target.(*consulapi.QueryOptions)
|
queryOpts := target.(*consulapi.QueryOptions)
|
||||||
queryOpts.WaitTime = d
|
queryOpts.WaitTime = d
|
||||||
@ -311,7 +311,7 @@ var _CatalogNodesAttrs = map[_TypeKey]*_TypeEntry{
|
|||||||
func dataSourceConsulCatalogNodes() *schema.Resource {
|
func dataSourceConsulCatalogNodes() *schema.Resource {
|
||||||
return &schema.Resource{
|
return &schema.Resource{
|
||||||
Read: dataSourceConsulCatalogNodesRead,
|
Read: dataSourceConsulCatalogNodesRead,
|
||||||
Schema: _TypeEntryMapToSchema(_CatalogNodesAttrs),
|
Schema: typeEntryMapToSchema(catalogNodesAttrs),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -327,12 +327,12 @@ func dataSourceConsulCatalogNodesRead(d *schema.ResourceData, meta interface{})
|
|||||||
Datacenter: dc,
|
Datacenter: dc,
|
||||||
}
|
}
|
||||||
|
|
||||||
cfgReader := _NewConfigReader(d)
|
cfgReader := newConfigReader(d)
|
||||||
|
|
||||||
// Construct the query options
|
// Construct the query options
|
||||||
for _, e := range _CatalogNodesAttrs[_CatalogNodes].ListSchema {
|
for _, e := range catalogNodesAttrs[catalogNodes].ListSchema {
|
||||||
// Only evaluate attributes that impact the state
|
// Only evaluate attributes that impact the state
|
||||||
if e.Source&_SourceLocalFilter == 0 {
|
if e.Source&sourceLocalFilter == 0 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -357,12 +357,12 @@ func dataSourceConsulCatalogNodesRead(d *schema.ResourceData, meta interface{})
|
|||||||
l := make([]interface{}, 0, len(nodes))
|
l := make([]interface{}, 0, len(nodes))
|
||||||
|
|
||||||
for _, node := range nodes {
|
for _, node := range nodes {
|
||||||
mWriter := _NewMapWriter(make(map[string]interface{}, len(_CatalogNodeAttrs)))
|
mWriter := newMapWriter(make(map[string]interface{}, len(catalogNodeAttrs)))
|
||||||
|
|
||||||
// /v1/catalog/nodes returns a list of node objects
|
// /v1/catalog/nodes returns a list of node objects
|
||||||
for _, e := range _CatalogNodesAttrs[_CatalogNodes].ListSchema {
|
for _, e := range catalogNodesAttrs[catalogNodes].ListSchema {
|
||||||
// Only evaluate attributes that impact the state
|
// Only evaluate attributes that impact the state
|
||||||
if e.Source&_ModifyState == 0 {
|
if e.Source&modifyState == 0 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -378,9 +378,9 @@ func dataSourceConsulCatalogNodesRead(d *schema.ResourceData, meta interface{})
|
|||||||
l = append(l, mWriter.ToMap())
|
l = append(l, mWriter.ToMap())
|
||||||
}
|
}
|
||||||
|
|
||||||
dataSourceWriter := _NewStateWriter(d)
|
dataSourceWriter := newStateWriter(d)
|
||||||
dataSourceWriter.SetList(_CatalogNodesAttrs[_CatalogNodes].SchemaName, l)
|
dataSourceWriter.SetList(catalogNodesAttrs[catalogNodes].SchemaName, l)
|
||||||
dataSourceWriter.SetString(_CatalogNodesAttrs[_CatalogNodesDatacenter].SchemaName, dc)
|
dataSourceWriter.SetString(catalogNodesAttrs[catalogNodesDatacenter].SchemaName, dc)
|
||||||
const idKeyFmt = "catalog-nodes-%s"
|
const idKeyFmt = "catalog-nodes-%s"
|
||||||
dataSourceWriter.SetID(fmt.Sprintf(idKeyFmt, dc))
|
dataSourceWriter.SetID(fmt.Sprintf(idKeyFmt, dc))
|
||||||
|
|
||||||
|
@ -13,132 +13,132 @@ import (
|
|||||||
"github.com/hashicorp/terraform/helper/schema"
|
"github.com/hashicorp/terraform/helper/schema"
|
||||||
)
|
)
|
||||||
|
|
||||||
// _APIAttr is the type used for constants representing well known keys within
|
// apiAttr is the type used for constants representing well known keys within
|
||||||
// the API that are transmitted back to a resource over an API.
|
// the API that are transmitted back to a resource over an API.
|
||||||
type _APIAttr string
|
type apiAttr string
|
||||||
|
|
||||||
// _SchemaAttr is the type used for constants representing well known keys
|
// schemaAttr is the type used for constants representing well known keys
|
||||||
// within the schema for a resource.
|
// within the schema for a resource.
|
||||||
type _SchemaAttr string
|
type schemaAttr string
|
||||||
|
|
||||||
// _SourceFlags represent the ways in which an attribute can be written. Some
|
// sourceFlags represent the ways in which an attribute can be written. Some
|
||||||
// sources are mutually exclusive, yet other flag combinations are composable.
|
// sources are mutually exclusive, yet other flag combinations are composable.
|
||||||
type _SourceFlags int
|
type sourceFlags int
|
||||||
|
|
||||||
// _TypeKey is the lookup mechanism for the generated schema.
|
// typeKey is the lookup mechanism for the generated schema.
|
||||||
type _TypeKey int
|
type typeKey int
|
||||||
|
|
||||||
// An array of inputs used as typed arguments and converted from their type into
|
// An array of inputs used as typed arguments and converted from their type into
|
||||||
// function objects that are dynamically constructed and executed.
|
// function objects that are dynamically constructed and executed.
|
||||||
type _ValidatorInputs []interface{}
|
type validatorInputs []interface{}
|
||||||
|
|
||||||
// _ValidateDurationMin is the minimum duration to accept as input
|
// validateDurationMin is the minimum duration to accept as input
|
||||||
type _ValidateDurationMin string
|
type validateDurationMin string
|
||||||
|
|
||||||
// _ValidateIntMin is the minimum integer value to accept as input
|
// validateIntMin is the minimum integer value to accept as input
|
||||||
type _ValidateIntMin int
|
type validateIntMin int
|
||||||
|
|
||||||
// _ValidateRegexp is a regexp pattern to use to validate schema input.
|
// validateRegexp is a regexp pattern to use to validate schema input.
|
||||||
type _ValidateRegexp string
|
type validateRegexp string
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// _SourceUserRequired indicates the parameter must be provided by the user in
|
// sourceUserRequired indicates the parameter must be provided by the user in
|
||||||
// their configuration.
|
// their configuration.
|
||||||
_SourceUserRequired _SourceFlags = 1 << iota
|
sourceUserRequired sourceFlags = 1 << iota
|
||||||
|
|
||||||
// _SourceUserOptional indicates the parameter may optionally be specified by
|
// sourceUserOptional indicates the parameter may optionally be specified by
|
||||||
// the user in their configuration.
|
// the user in their configuration.
|
||||||
_SourceUserOptional
|
sourceUserOptional
|
||||||
|
|
||||||
// _SourceAPIResult indicates the parameter may only be set by the return of
|
// sourceAPIResult indicates the parameter may only be set by the return of
|
||||||
// an API call.
|
// an API call.
|
||||||
_SourceAPIResult
|
sourceAPIResult
|
||||||
|
|
||||||
// _SourceLocalFilter indicates the parameter is only used as input to the
|
// sourceLocalFilter indicates the parameter is only used as input to the
|
||||||
// resource or data source and not to be entered into the state file.
|
// resource or data source and not to be entered into the state file.
|
||||||
_SourceLocalFilter
|
sourceLocalFilter
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// _ModifyState is a mask that selects all attribute sources that can modify
|
// modifyState is a mask that selects all attribute sources that can modify
|
||||||
// the state (i.e. everything but filters used in data sources).
|
// the state (i.e. everything but filters used in data sources).
|
||||||
_ModifyState = _SourceUserRequired | _SourceUserOptional | _SourceAPIResult
|
modifyState = sourceUserRequired | sourceUserOptional | sourceAPIResult
|
||||||
|
|
||||||
// _ComputedAttrMask is a mask that selects _Source*'s that are Computed in the
|
// computedAttrMask is a mask that selects source*'s that are Computed in the
|
||||||
// schema.
|
// schema.
|
||||||
_ComputedAttrMask = _SourceAPIResult
|
computedAttrMask = sourceAPIResult
|
||||||
|
|
||||||
// _OptionalAttrMask is a mask that selects _Source*'s that are Optional in the
|
// optionalAttrMask is a mask that selects source*'s that are Optional in the
|
||||||
// schema.
|
// schema.
|
||||||
_OptionalAttrMask = _SourceAPIResult | _SourceLocalFilter
|
optionalAttrMask = sourceAPIResult | sourceLocalFilter
|
||||||
|
|
||||||
// _RequiredAttrMask is a mask that selects _Source*'s that are Required in the
|
// requiredAttrMask is a mask that selects source*'s that are Required in the
|
||||||
// schema.
|
// schema.
|
||||||
_RequiredAttrMask = _SourceUserRequired
|
requiredAttrMask = sourceUserRequired
|
||||||
)
|
)
|
||||||
|
|
||||||
type _TypeEntry struct {
|
type typeEntry struct {
|
||||||
APIName _APIAttr
|
APIName apiAttr
|
||||||
APIAliases []_APIAttr
|
APIAliases []apiAttr
|
||||||
Source _SourceFlags
|
Source sourceFlags
|
||||||
Default interface{}
|
Default interface{}
|
||||||
Description string
|
Description string
|
||||||
SchemaName _SchemaAttr
|
SchemaName schemaAttr
|
||||||
Type schema.ValueType
|
Type schema.ValueType
|
||||||
ValidateFuncs []interface{}
|
ValidateFuncs []interface{}
|
||||||
SetMembers map[_TypeKey]*_TypeEntry
|
SetMembers map[typeKey]*typeEntry
|
||||||
ListSchema map[_TypeKey]*_TypeEntry
|
ListSchema map[typeKey]*typeEntry
|
||||||
|
|
||||||
// APITest, if returns true, will call APIToState. The if the value was
|
// APITest, if returns true, will call APIToState. The if the value was
|
||||||
// found, the second return parameter will include the value that should be
|
// found, the second return parameter will include the value that should be
|
||||||
// set in the state store.
|
// set in the state store.
|
||||||
APITest func(*_TypeEntry, interface{}) (interface{}, bool)
|
APITest func(*typeEntry, interface{}) (interface{}, bool)
|
||||||
|
|
||||||
// APIToState takes the value from APITest and writes it to the _AttrWriter
|
// APIToState takes the value from APITest and writes it to the attrWriter
|
||||||
APIToState func(*_TypeEntry, interface{}, _AttrWriter) error
|
APIToState func(*typeEntry, interface{}, attrWriter) error
|
||||||
|
|
||||||
// ConfigRead, if it returns true, returned a value that will be passed to its
|
// ConfigRead, if it returns true, returned a value that will be passed to its
|
||||||
// ConfigUse handler.
|
// ConfigUse handler.
|
||||||
ConfigRead func(*_TypeEntry, _AttrReader) (interface{}, bool)
|
ConfigRead func(*typeEntry, attrReader) (interface{}, bool)
|
||||||
|
|
||||||
// ConfigUse takes the value returned from ConfigRead as the second argument
|
// ConfigUse takes the value returned from ConfigRead as the second argument
|
||||||
// and a 3rd optional opaque context argument.
|
// and a 3rd optional opaque context argument.
|
||||||
ConfigUse func(e *_TypeEntry, v interface{}, target interface{}) error
|
ConfigUse func(e *typeEntry, v interface{}, target interface{}) error
|
||||||
}
|
}
|
||||||
|
|
||||||
type _TypeHandlers struct {
|
type typeHandlers struct {
|
||||||
APITest func(*_TypeEntry, interface{}) (interface{}, bool)
|
APITest func(*typeEntry, interface{}) (interface{}, bool)
|
||||||
APIToState func(*_TypeEntry, interface{}, _AttrWriter) error
|
APIToState func(*typeEntry, interface{}, attrWriter) error
|
||||||
}
|
}
|
||||||
|
|
||||||
var _TypeHandlerLookupMap = map[schema.ValueType]*_TypeHandlers{
|
var typeHandlerLookupMap = map[schema.ValueType]*typeHandlers{
|
||||||
schema.TypeBool: &_TypeHandlers{
|
schema.TypeBool: &typeHandlers{
|
||||||
APITest: _APITestBool,
|
APITest: apiTestBool,
|
||||||
APIToState: _APIToStateBool,
|
APIToState: apiToStateBool,
|
||||||
},
|
},
|
||||||
schema.TypeFloat: &_TypeHandlers{
|
schema.TypeFloat: &typeHandlers{
|
||||||
APITest: _APITestFloat64,
|
APITest: apiTestFloat64,
|
||||||
APIToState: _APIToStateFloat64,
|
APIToState: apiToStateFloat64,
|
||||||
},
|
},
|
||||||
schema.TypeList: &_TypeHandlers{
|
schema.TypeList: &typeHandlers{
|
||||||
APITest: _APITestList,
|
APITest: apiTestList,
|
||||||
APIToState: _APIToStateList,
|
APIToState: apiToStateList,
|
||||||
},
|
},
|
||||||
schema.TypeMap: &_TypeHandlers{
|
schema.TypeMap: &typeHandlers{
|
||||||
APITest: _APITestMap,
|
APITest: apiTestMap,
|
||||||
APIToState: _APIToStateMap,
|
APIToState: apiToStateMap,
|
||||||
},
|
},
|
||||||
schema.TypeSet: &_TypeHandlers{
|
schema.TypeSet: &typeHandlers{
|
||||||
APITest: _APITestSet,
|
APITest: apiTestSet,
|
||||||
APIToState: _APIToStateSet,
|
APIToState: apiToStateSet,
|
||||||
},
|
},
|
||||||
schema.TypeString: &_TypeHandlers{
|
schema.TypeString: &typeHandlers{
|
||||||
APITest: _APITestString,
|
APITest: apiTestString,
|
||||||
APIToState: _APIToStateString,
|
APIToState: apiToStateString,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
func _APITestBool(e *_TypeEntry, self interface{}) (interface{}, bool) {
|
func apiTestBool(e *typeEntry, self interface{}) (interface{}, bool) {
|
||||||
m := self.(map[string]interface{})
|
m := self.(map[string]interface{})
|
||||||
|
|
||||||
v, found := m[string(e.APIName)]
|
v, found := m[string(e.APIName)]
|
||||||
@ -153,7 +153,7 @@ func _APITestBool(e *_TypeEntry, self interface{}) (interface{}, bool) {
|
|||||||
return false, false
|
return false, false
|
||||||
}
|
}
|
||||||
|
|
||||||
func _APITestFloat64(e *_TypeEntry, self interface{}) (interface{}, bool) {
|
func apiTestFloat64(e *typeEntry, self interface{}) (interface{}, bool) {
|
||||||
m := self.(map[string]interface{})
|
m := self.(map[string]interface{})
|
||||||
|
|
||||||
v, found := m[string(e.APIName)]
|
v, found := m[string(e.APIName)]
|
||||||
@ -167,20 +167,20 @@ func _APITestFloat64(e *_TypeEntry, self interface{}) (interface{}, bool) {
|
|||||||
return 0.0, false
|
return 0.0, false
|
||||||
}
|
}
|
||||||
|
|
||||||
func _APITestID(e *_TypeEntry, self interface{}) (interface{}, bool) {
|
func apiTestID(e *typeEntry, self interface{}) (interface{}, bool) {
|
||||||
m := self.(map[string]interface{})
|
m := self.(map[string]interface{})
|
||||||
|
|
||||||
v, _ := _APITestString(e, m)
|
v, _ := apiTestString(e, m)
|
||||||
|
|
||||||
// Unconditionally return true so that the call to the APIToState handler can
|
// Unconditionally return true so that the call to the APIToState handler can
|
||||||
// return an error.
|
// return an error.
|
||||||
return v, true
|
return v, true
|
||||||
}
|
}
|
||||||
|
|
||||||
func _APITestList(e *_TypeEntry, self interface{}) (interface{}, bool) {
|
func apiTestList(e *typeEntry, self interface{}) (interface{}, bool) {
|
||||||
m := self.(map[string]interface{})
|
m := self.(map[string]interface{})
|
||||||
|
|
||||||
names := append([]_APIAttr{e.APIName}, e.APIAliases...)
|
names := append([]apiAttr{e.APIName}, e.APIAliases...)
|
||||||
const defaultListLen = 8
|
const defaultListLen = 8
|
||||||
l := make([]interface{}, 0, defaultListLen)
|
l := make([]interface{}, 0, defaultListLen)
|
||||||
|
|
||||||
@ -209,7 +209,7 @@ func _APITestList(e *_TypeEntry, self interface{}) (interface{}, bool) {
|
|||||||
return []interface{}{}, false
|
return []interface{}{}, false
|
||||||
}
|
}
|
||||||
|
|
||||||
func _APITestMap(e *_TypeEntry, selfRaw interface{}) (interface{}, bool) {
|
func apiTestMap(e *typeEntry, selfRaw interface{}) (interface{}, bool) {
|
||||||
self := selfRaw.(map[string]interface{})
|
self := selfRaw.(map[string]interface{})
|
||||||
|
|
||||||
v, found := self[string(e.APIName)]
|
v, found := self[string(e.APIName)]
|
||||||
@ -223,7 +223,7 @@ func _APITestMap(e *_TypeEntry, selfRaw interface{}) (interface{}, bool) {
|
|||||||
return "", false
|
return "", false
|
||||||
}
|
}
|
||||||
|
|
||||||
func _APITestSet(e *_TypeEntry, selfRaw interface{}) (interface{}, bool) {
|
func apiTestSet(e *typeEntry, selfRaw interface{}) (interface{}, bool) {
|
||||||
self := selfRaw.(map[string]interface{})
|
self := selfRaw.(map[string]interface{})
|
||||||
|
|
||||||
v, found := self[string(e.APIName)]
|
v, found := self[string(e.APIName)]
|
||||||
@ -237,7 +237,7 @@ func _APITestSet(e *_TypeEntry, selfRaw interface{}) (interface{}, bool) {
|
|||||||
return "", false
|
return "", false
|
||||||
}
|
}
|
||||||
|
|
||||||
func _APITestString(e *_TypeEntry, selfRaw interface{}) (interface{}, bool) {
|
func apiTestString(e *typeEntry, selfRaw interface{}) (interface{}, bool) {
|
||||||
self := selfRaw.(map[string]interface{})
|
self := selfRaw.(map[string]interface{})
|
||||||
|
|
||||||
v, found := self[string(e.APIName)]
|
v, found := self[string(e.APIName)]
|
||||||
@ -251,19 +251,19 @@ func _APITestString(e *_TypeEntry, selfRaw interface{}) (interface{}, bool) {
|
|||||||
return "", false
|
return "", false
|
||||||
}
|
}
|
||||||
|
|
||||||
func _APIToStateBool(e *_TypeEntry, v interface{}, w _AttrWriter) error {
|
func apiToStateBool(e *typeEntry, v interface{}, w attrWriter) error {
|
||||||
return w.SetBool(e.SchemaName, v.(bool))
|
return w.SetBool(e.SchemaName, v.(bool))
|
||||||
}
|
}
|
||||||
|
|
||||||
func _APIToStateID(e *_TypeEntry, v interface{}, w _AttrWriter) error {
|
func apiToStateID(e *typeEntry, v interface{}, w attrWriter) error {
|
||||||
s, ok := v.(string)
|
s, ok := v.(string)
|
||||||
if !ok || len(s) == 0 {
|
if !ok || len(s) == 0 {
|
||||||
return fmt.Errorf("Unable to set %q's ID to an empty or non-string value: %#v", e.SchemaName, v)
|
return fmt.Errorf("Unable to set %q's ID to an empty or non-string value: %#v", e.SchemaName, v)
|
||||||
}
|
}
|
||||||
|
|
||||||
stateWriter, ok := w.(*_AttrWriterState)
|
stateWriter, ok := w.(*attrWriterState)
|
||||||
if !ok {
|
if !ok {
|
||||||
return fmt.Errorf("PROVIDER BUG: unable to SetID with a non-_AttrWriterState")
|
return fmt.Errorf("PROVIDER BUG: unable to SetID with a non-attrWriterState")
|
||||||
}
|
}
|
||||||
|
|
||||||
stateWriter.SetID(s)
|
stateWriter.SetID(s)
|
||||||
@ -271,7 +271,7 @@ func _APIToStateID(e *_TypeEntry, v interface{}, w _AttrWriter) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func _APIToStateFloat64(e *_TypeEntry, v interface{}, w _AttrWriter) error {
|
func apiToStateFloat64(e *typeEntry, v interface{}, w attrWriter) error {
|
||||||
f, ok := v.(float64)
|
f, ok := v.(float64)
|
||||||
if !ok {
|
if !ok {
|
||||||
return fmt.Errorf("PROVIDER BUG: unable to cast %s to a float64", e.SchemaName)
|
return fmt.Errorf("PROVIDER BUG: unable to cast %s to a float64", e.SchemaName)
|
||||||
@ -280,7 +280,7 @@ func _APIToStateFloat64(e *_TypeEntry, v interface{}, w _AttrWriter) error {
|
|||||||
return w.SetFloat64(e.SchemaName, f)
|
return w.SetFloat64(e.SchemaName, f)
|
||||||
}
|
}
|
||||||
|
|
||||||
func _APIToStateList(e *_TypeEntry, v interface{}, w _AttrWriter) error {
|
func apiToStateList(e *typeEntry, v interface{}, w attrWriter) error {
|
||||||
l, ok := v.([]interface{})
|
l, ok := v.([]interface{})
|
||||||
if !ok {
|
if !ok {
|
||||||
return fmt.Errorf("PROVIDER BUG: unable to cast %s to a list", e.SchemaName)
|
return fmt.Errorf("PROVIDER BUG: unable to cast %s to a list", e.SchemaName)
|
||||||
@ -289,20 +289,20 @@ func _APIToStateList(e *_TypeEntry, v interface{}, w _AttrWriter) error {
|
|||||||
return w.SetList(e.SchemaName, l)
|
return w.SetList(e.SchemaName, l)
|
||||||
}
|
}
|
||||||
|
|
||||||
func _APIToStateMap(e *_TypeEntry, v interface{}, w _AttrWriter) error {
|
func apiToStateMap(e *typeEntry, v interface{}, w attrWriter) error {
|
||||||
rawMap, ok := v.(map[string]interface{})
|
rawMap, ok := v.(map[string]interface{})
|
||||||
if !ok {
|
if !ok {
|
||||||
return fmt.Errorf("PROVIDER BUG: unable to cast %s to a map", e.SchemaName)
|
return fmt.Errorf("PROVIDER BUG: unable to cast %s to a map", e.SchemaName)
|
||||||
}
|
}
|
||||||
|
|
||||||
mWriter := _NewMapWriter(make(map[string]interface{}, len(rawMap)))
|
mWriter := newMapWriter(make(map[string]interface{}, len(rawMap)))
|
||||||
|
|
||||||
// Make a lookup map by API Schema Name
|
// Make a lookup map by API Schema Name
|
||||||
var setMembersLen int
|
var setMembersLen int
|
||||||
if e.SetMembers != nil {
|
if e.SetMembers != nil {
|
||||||
setMembersLen = len(e.SetMembers)
|
setMembersLen = len(e.SetMembers)
|
||||||
}
|
}
|
||||||
apiLookup := make(map[string]*_TypeEntry, setMembersLen)
|
apiLookup := make(map[string]*typeEntry, setMembersLen)
|
||||||
for _, typeEntry := range e.SetMembers {
|
for _, typeEntry := range e.SetMembers {
|
||||||
apiLookup[string(e.SchemaName)] = typeEntry
|
apiLookup[string(e.SchemaName)] = typeEntry
|
||||||
}
|
}
|
||||||
@ -317,7 +317,7 @@ func _APIToStateMap(e *_TypeEntry, v interface{}, w _AttrWriter) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if !usedSchemaHandler {
|
if !usedSchemaHandler {
|
||||||
if err := mWriter.Set(_SchemaAttr(k), v); err != nil {
|
if err := mWriter.Set(schemaAttr(k), v); err != nil {
|
||||||
return errwrap.Wrapf("Unable to store map in state: {{err}}", err)
|
return errwrap.Wrapf("Unable to store map in state: {{err}}", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -326,7 +326,7 @@ func _APIToStateMap(e *_TypeEntry, v interface{}, w _AttrWriter) error {
|
|||||||
return w.SetMap(e.SchemaName, mWriter.ToMap())
|
return w.SetMap(e.SchemaName, mWriter.ToMap())
|
||||||
}
|
}
|
||||||
|
|
||||||
func _APIToStateSet(e *_TypeEntry, v interface{}, w _AttrWriter) error {
|
func apiToStateSet(e *typeEntry, v interface{}, w attrWriter) error {
|
||||||
s, ok := v.([]map[string]interface{})
|
s, ok := v.([]map[string]interface{})
|
||||||
if !ok {
|
if !ok {
|
||||||
return fmt.Errorf("PROVIDER BUG: unable to cast %s to a set", e.SchemaName)
|
return fmt.Errorf("PROVIDER BUG: unable to cast %s to a set", e.SchemaName)
|
||||||
@ -338,7 +338,7 @@ func _APIToStateSet(e *_TypeEntry, v interface{}, w _AttrWriter) error {
|
|||||||
return w.SetSet(e.SchemaName, set)
|
return w.SetSet(e.SchemaName, set)
|
||||||
}
|
}
|
||||||
|
|
||||||
func _APIToStateString(e *_TypeEntry, v interface{}, w _AttrWriter) error {
|
func apiToStateString(e *typeEntry, v interface{}, w attrWriter) error {
|
||||||
s, ok := v.(string)
|
s, ok := v.(string)
|
||||||
if !ok {
|
if !ok {
|
||||||
return fmt.Errorf("PROVIDER BUG: unable to cast %s to a float64", e.SchemaName)
|
return fmt.Errorf("PROVIDER BUG: unable to cast %s to a float64", e.SchemaName)
|
||||||
@ -347,7 +347,7 @@ func _APIToStateString(e *_TypeEntry, v interface{}, w _AttrWriter) error {
|
|||||||
return w.SetString(e.SchemaName, s)
|
return w.SetString(e.SchemaName, s)
|
||||||
}
|
}
|
||||||
|
|
||||||
func _HashMap(in interface{}) int {
|
func hashMap(in interface{}) int {
|
||||||
return 0
|
return 0
|
||||||
m, ok := in.(map[string]interface{})
|
m, ok := in.(map[string]interface{})
|
||||||
if !ok {
|
if !ok {
|
||||||
@ -362,8 +362,8 @@ func _HashMap(in interface{}) int {
|
|||||||
sort.Strings(keys)
|
sort.Strings(keys)
|
||||||
|
|
||||||
b := &bytes.Buffer{}
|
b := &bytes.Buffer{}
|
||||||
const _DefaultHashBufSize = 4096
|
const defaultHashBufSize = 4096
|
||||||
b.Grow(_DefaultHashBufSize)
|
b.Grow(defaultHashBufSize)
|
||||||
|
|
||||||
for _, k := range keys {
|
for _, k := range keys {
|
||||||
v, found := m[k]
|
v, found := m[k]
|
||||||
@ -390,7 +390,7 @@ func _HashMap(in interface{}) int {
|
|||||||
return hashcode.String(b.String())
|
return hashcode.String(b.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
func _Indirect(v interface{}) interface{} {
|
func indirect(v interface{}) interface{} {
|
||||||
switch v.(type) {
|
switch v.(type) {
|
||||||
case string:
|
case string:
|
||||||
return v
|
return v
|
||||||
@ -405,8 +405,8 @@ func _Indirect(v interface{}) interface{} {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *_TypeEntry) LookupDefaultTypeHandler() *_TypeHandlers {
|
func (e *typeEntry) LookupDefaultTypeHandler() *typeHandlers {
|
||||||
h, found := _TypeHandlerLookupMap[e.Type]
|
h, found := typeHandlerLookupMap[e.Type]
|
||||||
if !found {
|
if !found {
|
||||||
panic(fmt.Sprintf("PROVIDER BUG: unable to lookup %q's type (%#v)", e.SchemaName, e.Type))
|
panic(fmt.Sprintf("PROVIDER BUG: unable to lookup %q's type (%#v)", e.SchemaName, e.Type))
|
||||||
}
|
}
|
||||||
@ -414,8 +414,8 @@ func (e *_TypeEntry) LookupDefaultTypeHandler() *_TypeHandlers {
|
|||||||
return h
|
return h
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *_TypeEntry) MustLookupTypeHandler() *_TypeHandlers {
|
func (e *typeEntry) MustLookupTypeHandler() *typeHandlers {
|
||||||
h := &_TypeHandlers{
|
h := &typeHandlers{
|
||||||
APITest: e.APITest,
|
APITest: e.APITest,
|
||||||
APIToState: e.APIToState,
|
APIToState: e.APIToState,
|
||||||
}
|
}
|
||||||
@ -441,10 +441,10 @@ func (e *_TypeEntry) MustLookupTypeHandler() *_TypeHandlers {
|
|||||||
return h
|
return h
|
||||||
}
|
}
|
||||||
|
|
||||||
// _NegateBoolToState is a factory function that creates a new function that
|
// negateBoolToState is a factory function that creates a new function that
|
||||||
// negates whatever the bool is that's passed in as an argument.
|
// negates whatever the bool is that's passed in as an argument.
|
||||||
func _NegateBoolToState(fn func(*_TypeEntry, interface{}, _AttrWriter) error) func(*_TypeEntry, interface{}, _AttrWriter) error {
|
func negateBoolToState(fn func(*typeEntry, interface{}, attrWriter) error) func(*typeEntry, interface{}, attrWriter) error {
|
||||||
return func(e *_TypeEntry, v interface{}, w _AttrWriter) error {
|
return func(e *typeEntry, v interface{}, w attrWriter) error {
|
||||||
b, ok := v.(bool)
|
b, ok := v.(bool)
|
||||||
if !ok {
|
if !ok {
|
||||||
return fmt.Errorf("Unable to type assert non-bool value: %#v", v)
|
return fmt.Errorf("Unable to type assert non-bool value: %#v", v)
|
||||||
@ -454,29 +454,29 @@ func _NegateBoolToState(fn func(*_TypeEntry, interface{}, _AttrWriter) error) fu
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// _StateSet sets an attribute based on an attrName. Return an error if the
|
// stateSet sets an attribute based on an attrName. Return an error if the
|
||||||
// Set() to schema.ResourceData fails.
|
// Set() to schema.ResourceData fails.
|
||||||
func _StateSet(d *schema.ResourceData, attrName _SchemaAttr, v interface{}) error {
|
func stateSet(d *schema.ResourceData, attrName schemaAttr, v interface{}) error {
|
||||||
if err := d.Set(string(attrName), _Indirect(v)); err != nil {
|
if err := d.Set(string(attrName), indirect(v)); err != nil {
|
||||||
return fmt.Errorf("PROVIDER BUG: failed set schema attribute %s to value %#v: %v", attrName, v, err)
|
return fmt.Errorf("PROVIDER BUG: failed set schema attribute %s to value %#v: %v", attrName, v, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func _TypeEntryListToSchema(e *_TypeEntry) map[string]*schema.Schema {
|
func typeEntryListToSchema(e *typeEntry) map[string]*schema.Schema {
|
||||||
return map[string]*schema.Schema{
|
return map[string]*schema.Schema{
|
||||||
string(e.SchemaName): e.ToSchema(),
|
string(e.SchemaName): e.ToSchema(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func _TypeEntryMapToResource(in map[_TypeKey]*_TypeEntry) *schema.Resource {
|
func typeEntryMapToResource(in map[typeKey]*typeEntry) *schema.Resource {
|
||||||
return &schema.Resource{
|
return &schema.Resource{
|
||||||
Schema: _TypeEntryMapToSchema(in),
|
Schema: typeEntryMapToSchema(in),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func _TypeEntryMapToSchema(in map[_TypeKey]*_TypeEntry) map[string]*schema.Schema {
|
func typeEntryMapToSchema(in map[typeKey]*typeEntry) map[string]*schema.Schema {
|
||||||
out := make(map[string]*schema.Schema, len(in))
|
out := make(map[string]*schema.Schema, len(in))
|
||||||
for _, e := range in {
|
for _, e := range in {
|
||||||
out[string(e.SchemaName)] = e.ToSchema()
|
out[string(e.SchemaName)] = e.ToSchema()
|
||||||
@ -485,12 +485,12 @@ func _TypeEntryMapToSchema(in map[_TypeKey]*_TypeEntry) map[string]*schema.Schem
|
|||||||
return out
|
return out
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *_TypeEntry) Validate() {
|
func (e *typeEntry) Validate() {
|
||||||
if e.Source&_SourceAPIResult != 0 && e.Type == schema.TypeSet {
|
if e.Source&sourceAPIResult != 0 && e.Type == schema.TypeSet {
|
||||||
panic(fmt.Sprintf("PROVIDER BUG: %s can not be computed and of type Set", e.SchemaName))
|
panic(fmt.Sprintf("PROVIDER BUG: %s can not be computed and of type Set", e.SchemaName))
|
||||||
}
|
}
|
||||||
|
|
||||||
if e.Source&_SourceLocalFilter != 0 {
|
if e.Source&sourceLocalFilter != 0 {
|
||||||
if e.ConfigRead == nil {
|
if e.ConfigRead == nil {
|
||||||
panic(fmt.Sprintf("PROVIDER BUG: %s can not be configured as a local filter and be missing a config read handler", e.SchemaName))
|
panic(fmt.Sprintf("PROVIDER BUG: %s can not be configured as a local filter and be missing a config read handler", e.SchemaName))
|
||||||
}
|
}
|
||||||
@ -504,15 +504,15 @@ func (e *_TypeEntry) Validate() {
|
|||||||
panic(fmt.Sprintf("PROVIDER BUG: %s is not of type Set but has SetMembers set", e.SchemaName))
|
panic(fmt.Sprintf("PROVIDER BUG: %s is not of type Set but has SetMembers set", e.SchemaName))
|
||||||
}
|
}
|
||||||
|
|
||||||
if e.Source&(_SourceUserRequired|_SourceAPIResult) == (_SourceUserRequired | _SourceAPIResult) {
|
if e.Source&(sourceUserRequired|sourceAPIResult) == (sourceUserRequired | sourceAPIResult) {
|
||||||
panic(fmt.Sprintf("PROVIDER BUG: %#v and %#v are mutually exclusive Source flags", _SourceUserRequired, _SourceAPIResult))
|
panic(fmt.Sprintf("PROVIDER BUG: %#v and %#v are mutually exclusive Source flags", sourceUserRequired, sourceAPIResult))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// MakeValidateionFunc takes a list of typed validator inputs from the receiver
|
// MakeValidateionFunc takes a list of typed validator inputs from the receiver
|
||||||
// and creates a validation closure that calls each validator in serial until
|
// and creates a validation closure that calls each validator in serial until
|
||||||
// either a warning or error is returned from the first validation function.
|
// either a warning or error is returned from the first validation function.
|
||||||
func (e *_TypeEntry) MakeValidationFunc() func(v interface{}, key string) (warnings []string, errors []error) {
|
func (e *typeEntry) MakeValidationFunc() func(v interface{}, key string) (warnings []string, errors []error) {
|
||||||
if len(e.ValidateFuncs) == 0 {
|
if len(e.ValidateFuncs) == 0 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -520,12 +520,12 @@ func (e *_TypeEntry) MakeValidationFunc() func(v interface{}, key string) (warni
|
|||||||
fns := make([]func(v interface{}, key string) (warnings []string, errors []error), 0, len(e.ValidateFuncs))
|
fns := make([]func(v interface{}, key string) (warnings []string, errors []error), 0, len(e.ValidateFuncs))
|
||||||
for _, v := range e.ValidateFuncs {
|
for _, v := range e.ValidateFuncs {
|
||||||
switch u := v.(type) {
|
switch u := v.(type) {
|
||||||
case _ValidateDurationMin:
|
case validateDurationMin:
|
||||||
fns = append(fns, _ValidateDurationMinFactory(e, string(u)))
|
fns = append(fns, validateDurationMinFactory(e, string(u)))
|
||||||
case _ValidateIntMin:
|
case validateIntMin:
|
||||||
fns = append(fns, _ValidateIntMinFactory(e, int(u)))
|
fns = append(fns, validateIntMinFactory(e, int(u)))
|
||||||
case _ValidateRegexp:
|
case validateRegexp:
|
||||||
fns = append(fns, _ValidateRegexpFactory(e, string(u)))
|
fns = append(fns, validateRegexpFactory(e, string(u)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -540,15 +540,15 @@ func (e *_TypeEntry) MakeValidationFunc() func(v interface{}, key string) (warni
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *_TypeEntry) ToSchema() *schema.Schema {
|
func (e *typeEntry) ToSchema() *schema.Schema {
|
||||||
e.Validate()
|
e.Validate()
|
||||||
|
|
||||||
attr := &schema.Schema{
|
attr := &schema.Schema{
|
||||||
Computed: e.Source&_ComputedAttrMask != 0,
|
Computed: e.Source&computedAttrMask != 0,
|
||||||
Default: e.Default,
|
Default: e.Default,
|
||||||
Description: e.Description,
|
Description: e.Description,
|
||||||
Optional: e.Source&_OptionalAttrMask != 0,
|
Optional: e.Source&optionalAttrMask != 0,
|
||||||
Required: e.Source&_RequiredAttrMask != 0,
|
Required: e.Source&requiredAttrMask != 0,
|
||||||
Type: e.Type,
|
Type: e.Type,
|
||||||
ValidateFunc: e.MakeValidationFunc(),
|
ValidateFunc: e.MakeValidationFunc(),
|
||||||
}
|
}
|
||||||
@ -561,19 +561,19 @@ func (e *_TypeEntry) ToSchema() *schema.Schema {
|
|||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
attr.Elem = _TypeEntryMapToResource(e.ListSchema)
|
attr.Elem = typeEntryMapToResource(e.ListSchema)
|
||||||
}
|
}
|
||||||
|
|
||||||
case schema.TypeSet:
|
case schema.TypeSet:
|
||||||
attr.Elem = &schema.Resource{
|
attr.Elem = &schema.Resource{
|
||||||
Schema: _TypeEntryMapToSchema(e.SetMembers),
|
Schema: typeEntryMapToSchema(e.SetMembers),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return attr
|
return attr
|
||||||
}
|
}
|
||||||
|
|
||||||
func _MapStringToMapInterface(in map[string]string) map[string]interface{} {
|
func mapStringToMapInterface(in map[string]string) map[string]interface{} {
|
||||||
out := make(map[string]interface{}, len(in))
|
out := make(map[string]interface{}, len(in))
|
||||||
for k, v := range in {
|
for k, v := range in {
|
||||||
out[k] = v
|
out[k] = v
|
||||||
@ -581,7 +581,7 @@ func _MapStringToMapInterface(in map[string]string) map[string]interface{} {
|
|||||||
return out
|
return out
|
||||||
}
|
}
|
||||||
|
|
||||||
func _ValidateDurationMinFactory(e *_TypeEntry, minDuration string) func(v interface{}, key string) (warnings []string, errors []error) {
|
func validateDurationMinFactory(e *typeEntry, minDuration string) func(v interface{}, key string) (warnings []string, errors []error) {
|
||||||
dMin, err := time.ParseDuration(minDuration)
|
dMin, err := time.ParseDuration(minDuration)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(fmt.Sprintf("PROVIDER BUG: duration %q not valid: %#v", minDuration, err))
|
panic(fmt.Sprintf("PROVIDER BUG: duration %q not valid: %#v", minDuration, err))
|
||||||
@ -601,7 +601,7 @@ func _ValidateDurationMinFactory(e *_TypeEntry, minDuration string) func(v inter
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func _ValidateIntMinFactory(e *_TypeEntry, min int) func(v interface{}, key string) (warnings []string, errors []error) {
|
func validateIntMinFactory(e *typeEntry, min int) func(v interface{}, key string) (warnings []string, errors []error) {
|
||||||
return func(v interface{}, key string) (warnings []string, errors []error) {
|
return func(v interface{}, key string) (warnings []string, errors []error) {
|
||||||
if v.(int) < min {
|
if v.(int) < min {
|
||||||
errors = append(errors, fmt.Errorf("Invalid %s specified: %d less than the required minimum %d", e.SchemaName, v.(int), min))
|
errors = append(errors, fmt.Errorf("Invalid %s specified: %d less than the required minimum %d", e.SchemaName, v.(int), min))
|
||||||
@ -611,7 +611,7 @@ func _ValidateIntMinFactory(e *_TypeEntry, min int) func(v interface{}, key stri
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func _ValidateRegexpFactory(e *_TypeEntry, reString string) func(v interface{}, key string) (warnings []string, errors []error) {
|
func validateRegexpFactory(e *typeEntry, reString string) func(v interface{}, key string) (warnings []string, errors []error) {
|
||||||
re := regexp.MustCompile(reString)
|
re := regexp.MustCompile(reString)
|
||||||
|
|
||||||
return func(v interface{}, key string) (warnings []string, errors []error) {
|
return func(v interface{}, key string) (warnings []string, errors []error) {
|
||||||
|
Loading…
Reference in New Issue
Block a user