common

package
v0.0.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 19, 2022 License: MPL-2.0 Imports: 39 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TerraformProviderName    = "terraform-provider-vestack"
	TerraformProviderVersion = "0.0.5"
)

Variables

This section is empty.

Functions

func Acquire

func Acquire()

func CallProcess

func CallProcess(calls []SdkCall, d *schema.ResourceData, client *SdkClient, service ResourceService) (err error)

func CheckResourceUtilRemoved added in v0.0.3

func CheckResourceUtilRemoved(d *schema.ResourceData, readResourceFunc ReadResourceFunc, timeout time.Duration) error

func ClbAclEntryHash

func ClbAclEntryHash(v interface{}) int

func Convert

func Convert(d *schema.ResourceData, k string, v interface{}, t RequestConvert, index int, req *map[string]interface{}, chain string, forceGet bool, contentType RequestContentType) (err error)

func DataSourceToRequest

func DataSourceToRequest(d *schema.ResourceData, r *schema.Resource, info DataSourceInfo) (req map[string]interface{}, err error)

func DownLineToFilter

func DownLineToFilter(s string) string

DownLineToFilter instance_name ->instance-name

func DownLineToHump

func DownLineToHump(s string) string

DownLineToHump Convert instance_name -> InstanceName

func DownLineToHumpAndFirstLower

func DownLineToHumpAndFirstLower(s string) string

DownLineToHumpAndFirstLower Convert instance_name -> instanceName

func DownLineToSpace

func DownLineToSpace(s string) string

DownLineToSpace instance_name ->instance name

func EcsInstanceImportDiffSuppress

func EcsInstanceImportDiffSuppress(k, old, new string, d *schema.ResourceData) bool

func GetFinalKey

func GetFinalKey(t RequestConvert, k string, isRoot bool) string

func GetSetDifference

func GetSetDifference(key string, d *schema.ResourceData, f schema.SchemaSetFunc, supportUpdate bool) (add *schema.Set, remove *schema.Set, modify *schema.Set, cache map[int]interface{})

func HumpToDownLine

func HumpToDownLine(s string) string

HumpToDownLine Convert InstanceName -> instance_name

func InitLocks

func InitLocks()

func InitSyncLimit

func InitSyncLimit()

func MergeDateSourceToResource

func MergeDateSourceToResource(source map[string]*schema.Schema, target *map[string]*schema.Schema)

func ObtainSdkValue

func ObtainSdkValue(keyPattern string, obj interface{}) (interface{}, error)

func Release

func Release()

func ReleaseLock

func ReleaseLock(key string)

func RequestConvertDefault

func RequestConvertDefault(v interface{}, k string, t RequestConvert, req *map[string]interface{}, chain string) error

func RequestConvertListFilter

func RequestConvertListFilter(v interface{}, k string, t RequestConvert, index int, req *map[string]interface{}) (int, error)

func RequestConvertListN

func RequestConvertListN(v interface{}, k string, t RequestConvert, req *map[string]interface{}, chain string, d *schema.ResourceData, forceGet bool, single bool, contentType RequestContentType) error

func RequestConvertSingleN

func RequestConvertSingleN(v interface{}, k string, t RequestConvert, req *map[string]interface{}, chain string) error

func RequestConvertWithFilter

func RequestConvertWithFilter(v interface{}, k string, t RequestConvert, index int, req *map[string]interface{}) (int, error)

func RequestConvertWithN

func RequestConvertWithN(v interface{}, k string, t RequestConvert, req *map[string]interface{}, chain string) error

func RequestCreateConvert

func RequestCreateConvert(d *schema.ResourceData, k string, t RequestConvert, index int, req *map[string]interface{}, forceGet bool, contentType RequestContentType) (int, error)

func RequestUpdateConvert

func RequestUpdateConvert(d *schema.ResourceData, k string, t RequestConvert, index int, req *map[string]interface{}, contentType RequestContentType) (int, error)

func ResourceDateToRequest

func ResourceDateToRequest(d *schema.ResourceData, resource *schema.Resource, isUpdate bool, convert map[string]RequestConvert, mode RequestConvertMode, contentType RequestContentType) (map[string]interface{}, error)

func ResourceNotFoundError

func ResourceNotFoundError(err error) bool

func ResponseToDataSource

func ResponseToDataSource(d *schema.ResourceData, r *schema.Resource, info DataSourceInfo, collection []interface{}) (err error)

func ResponseToResourceData

func ResponseToResourceData(d *schema.ResourceData, resource *schema.Resource, data interface{}, extra map[string]ResponseConvert, start ...bool) (rd interface{}, err error)

func TryLock

func TryLock(key string)

func WithNextTokenQuery

func WithNextTokenQuery(condition map[string]interface{}, maxResultsParam string, nextTokenParam string, maxResults int, decode DecodeNextToken, call NextTokenCall) (data []interface{}, err error)

func WithPageNumberQuery

func WithPageNumberQuery(condition map[string]interface{}, pageSizeParam string, pageNumParam string, pageSize int, initPageNumber int, call PageCall) (data []interface{}, err error)

func WithPageOffsetQuery

func WithPageOffsetQuery(condition map[string]interface{}, limitParam string, pageParam string, limit int, start int, call PageCall) (data []interface{}, err error)

func WithSimpleQuery

func WithSimpleQuery(condition map[string]interface{}, call PageCall) (data []interface{}, err error)

Types

type AfterCallFunc

type AfterCallFunc func(d *schema.ResourceData, client *SdkClient, resp *map[string]interface{}, call SdkCall) error

type BeforeCallFunc

type BeforeCallFunc func(d *schema.ResourceData, client *SdkClient, call SdkCall) (bool, error)

type CallErrorFunc

type CallErrorFunc func(d *schema.ResourceData, client *SdkClient, call SdkCall, baseErr error) error

type Callback

type Callback struct {
	Call SdkCall
	Err  error
}

type Config

type Config struct {
	AccessKey    string
	SecretKey    string
	SessionToken string
	Region       string
	Endpoint     string
	DisableSSL   bool
}

func (*Config) Client

func (c *Config) Client() (*SdkClient, error)

type ContentType added in v0.0.3

type ContentType int
const (
	Default ContentType = iota
	ApplicationJSON
)

type DataSourceInfo

type DataSourceInfo struct {
	RequestConverts  map[string]RequestConvert
	ResponseConverts map[string]ResponseConvert
	NameField        string
	IdField          string
	CollectField     string
	ContentType      RequestContentType
	ExtraData        ExtraData
}

type DecodeNextToken

type DecodeNextToken func(source string) string

type Dispatcher

type Dispatcher struct {
}

func (*Dispatcher) Create

func (d *Dispatcher) Create(resourceService ResourceService, resourceDate *schema.ResourceData, resource *schema.Resource) (err error)

func (*Dispatcher) Data

func (d *Dispatcher) Data(resourceService ResourceService, resourceDate *schema.ResourceData, resource *schema.Resource) (err error)

func (*Dispatcher) Delete

func (d *Dispatcher) Delete(resourceService ResourceService, resourceDate *schema.ResourceData, resource *schema.Resource) (err error)

func (*Dispatcher) Read

func (d *Dispatcher) Read(resourceService ResourceService, resourceDate *schema.ResourceData, resource *schema.Resource) (err error)

func (*Dispatcher) Update

func (d *Dispatcher) Update(resourceService ResourceService, resourceDate *schema.ResourceData, resource *schema.Resource) (err error)

type ExecuteCallFunc

type ExecuteCallFunc func(d *schema.ResourceData, client *SdkClient, call SdkCall) (*map[string]interface{}, error)

type ExtraData

type ExtraData func([]interface{}) ([]interface{}, error)

type FieldRequestConvert

type FieldRequestConvert func(*schema.ResourceData, interface{}) interface{}

type FieldResponseConvert

type FieldResponseConvert func(interface{}) interface{}

type HttpMethod added in v0.0.3

type HttpMethod int
const (
	GET HttpMethod = iota
	POST
	PUT
	DELETE
)

type LockId

type LockId func(d *schema.ResourceData) string

type NextTokenCall

type NextTokenCall func(map[string]interface{}) ([]interface{}, string, error)

type PageCall

type PageCall func(map[string]interface{}) ([]interface{}, error)

type ReadResourceFunc added in v0.0.3

type ReadResourceFunc func(d *schema.ResourceData, resourceId string) (map[string]interface{}, error)

type RequestContentType

type RequestContentType int
const (
	ContentTypeDefault RequestContentType = iota
	ContentTypeJson
)

type RequestConvert

type RequestConvert struct {
	ConvertType      RequestConvertType
	Convert          FieldRequestConvert
	Ignore           bool
	ForceGet         bool
	TargetField      string
	NextLevelConvert map[string]RequestConvert
	StartIndex       int
}

type RequestConvertMode

type RequestConvertMode int
const (
	RequestConvertAll RequestConvertMode = iota
	RequestConvertInConvert
	RequestConvertIgnore
)

type RequestConvertType

type RequestConvertType int
const (
	ConvertDefault RequestConvertType = iota
	ConvertWithN
	ConvertListUnique
	ConvertListN
	ConvertSingleN
	ConvertJsonObject
	ConvertJsonArray
	ConvertJsonObjectArray
)

type ResourceResponseHandler

type ResourceResponseHandler func() (map[string]interface{}, map[string]ResponseConvert, error)

type ResourceService

type ResourceService interface {
	//GetClient 获取客户端
	GetClient() *SdkClient
	// ReadResources 读取资源列表
	ReadResources(map[string]interface{}) ([]interface{}, error)
	// ReadResource 读取单个资源
	ReadResource(*schema.ResourceData, string) (map[string]interface{}, error)
	// RefreshResourceState 刷新资源状态
	RefreshResourceState(*schema.ResourceData, []string, time.Duration, string) *resource.StateChangeConf
	// WithResourceResponseHandlers 接口结果 -> terraform 映射
	WithResourceResponseHandlers(map[string]interface{}) []ResourceResponseHandler
	// CreateResource 创建资源
	CreateResource(*schema.ResourceData, *schema.Resource) []Callback
	// ModifyResource 修改资源
	ModifyResource(*schema.ResourceData, *schema.Resource) []Callback
	// RemoveResource 删除资源
	RemoveResource(*schema.ResourceData, *schema.Resource) []Callback
	// DatasourceResources data_source读取资源
	DatasourceResources(*schema.ResourceData, *schema.Resource) DataSourceInfo
	// ReadResourceId 获取资源ID
	ReadResourceId(string) string
}

type ResponseConvert

type ResponseConvert struct {
	TargetField string
	KeepDefault bool
	Convert     FieldResponseConvert
	Ignore      bool
}

type SdkCall

type SdkCall struct {
	Action         string
	BeforeCall     BeforeCallFunc
	ExecuteCall    ExecuteCallFunc
	CallError      CallErrorFunc
	AfterCall      AfterCallFunc
	Convert        map[string]RequestConvert
	ConvertMode    RequestConvertMode
	SdkParam       *map[string]interface{}
	RequestIdField string
	Refresh        *StateRefresh
	ExtraRefresh   map[ResourceService]*StateRefresh
	ContentType    RequestContentType
	LockId         LockId
}

func (*SdkCall) InitReadCall

func (c *SdkCall) InitReadCall(resourceData *schema.ResourceData, resource *schema.Resource) (err error)

func (*SdkCall) InitWriteCall

func (c *SdkCall) InitWriteCall(resourceData *schema.ResourceData, resource *schema.Resource, isUpdate bool) (err error)

type SdkClient

type SdkClient struct {
	Region            string
	VpcClient         *vpc.VPC
	ClbClient         *clb.CLB
	EcsClient         *ecs.ECS
	EbsClient         *storageebs.STORAGEEBS
	NatClient         *natgateway.NATGATEWAY
	VpnClient         *vpn.VPN
	AutoScalingClient *autoscaling.AUTOSCALING
	RdsClient         *rdsmysql.RDSMYSQL
	RdsClientV2       *rdsmysqlv2.RDSMYSQLV2
	UniversalClient   *Universal
}

type StateRefresh

type StateRefresh struct {
	Target     []string
	Timeout    time.Duration
	ResourceId string
}

type Universal added in v0.0.3

type Universal struct {
	Session *session.Session
}

func NewUniversalClient added in v0.0.3

func NewUniversalClient(session *session.Session) *Universal

func (*Universal) DoCall added in v0.0.3

func (u *Universal) DoCall(info UniversalInfo, input *map[string]interface{}) (output *map[string]interface{}, err error)

type UniversalInfo added in v0.0.3

type UniversalInfo struct {
	ServiceName string
	Action      string
	Version     string
	HttpMethod  HttpMethod
	ContentType ContentType
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL