packer-cn/vendor/github.com/denverdino/aliyungo/ecs/client.go

116 lines
3.9 KiB
Go
Raw Normal View History

2017-03-03 04:19:16 -05:00
package ecs
import (
"os"
2017-03-04 05:06:32 -05:00
"github.com/denverdino/aliyungo/common"
2017-03-03 04:19:16 -05:00
)
// Interval for checking status in WaitForXXX method
const DefaultWaitForInterval = 5
// Default timeout value for WaitForXXX method
const DefaultTimeout = 60
type Client struct {
common.Client
}
const (
// ECSDefaultEndpoint is the default API endpoint of ECS services
ECSDefaultEndpoint = "https://ecs-cn-hangzhou.aliyuncs.com"
ECSAPIVersion = "2014-05-26"
ECSServiceCode = "ecs"
VPCDefaultEndpoint = "https://vpc.aliyuncs.com"
VPCAPIVersion = "2016-04-28"
VPCServiceCode = "vpc"
2017-03-03 04:19:16 -05:00
)
// NewClient creates a new instance of ECS client
func NewClient(accessKeyId, accessKeySecret string) *Client {
endpoint := os.Getenv("ECS_ENDPOINT")
if endpoint == "" {
endpoint = ECSDefaultEndpoint
}
return NewClientWithEndpoint(endpoint, accessKeyId, accessKeySecret)
}
func NewClientWithRegion(endpoint string, accessKeyId string, accessKeySecret string, regionID common.Region) *Client {
client := &Client{}
client.NewInit(endpoint, ECSAPIVersion, accessKeyId, accessKeySecret, ECSServiceCode, regionID)
return client
}
func NewClientWithEndpoint(endpoint string, accessKeyId string, accessKeySecret string) *Client {
client := &Client{}
client.Init(endpoint, ECSAPIVersion, accessKeyId, accessKeySecret)
return client
}
// ---------------------------------------
// NewECSClient creates a new instance of ECS client
// ---------------------------------------
2017-03-04 05:06:32 -05:00
func NewECSClient(accessKeyId, accessKeySecret string, regionID common.Region) *Client {
return NewECSClientWithSecurityToken(accessKeyId, accessKeySecret, "", regionID)
}
func NewECSClientWithSecurityToken(accessKeyId string, accessKeySecret string, securityToken string, regionID common.Region) *Client {
2017-03-04 05:06:32 -05:00
endpoint := os.Getenv("ECS_ENDPOINT")
if endpoint == "" {
endpoint = ECSDefaultEndpoint
}
return NewECSClientWithEndpointAndSecurityToken(endpoint, accessKeyId, accessKeySecret, securityToken, regionID)
2017-03-04 05:06:32 -05:00
}
func NewECSClientWithEndpoint(endpoint string, accessKeyId string, accessKeySecret string, regionID common.Region) *Client {
return NewECSClientWithEndpointAndSecurityToken(endpoint, accessKeyId, accessKeySecret, "", regionID)
2017-03-04 05:06:32 -05:00
}
func NewECSClientWithEndpointAndSecurityToken(endpoint string, accessKeyId string, accessKeySecret string, securityToken string, regionID common.Region) *Client {
2017-03-03 04:19:16 -05:00
client := &Client{}
client.WithEndpoint(endpoint).
WithVersion(ECSAPIVersion).
WithAccessKeyId(accessKeyId).
WithAccessKeySecret(accessKeySecret).
WithSecurityToken(securityToken).
WithServiceCode(ECSServiceCode).
WithRegionID(regionID).
InitClient()
2017-03-03 04:19:16 -05:00
return client
}
// ---------------------------------------
// NewVPCClient creates a new instance of VPC client
// ---------------------------------------
func NewVPCClient(accessKeyId string, accessKeySecret string, regionID common.Region) *Client {
return NewVPCClientWithSecurityToken(accessKeyId, accessKeySecret, "", regionID)
}
func NewVPCClientWithSecurityToken(accessKeyId string, accessKeySecret string, securityToken string, regionID common.Region) *Client {
endpoint := os.Getenv("VPC_ENDPOINT")
if endpoint == "" {
endpoint = VPCDefaultEndpoint
}
return NewVPCClientWithEndpointAndSecurityToken(endpoint, accessKeyId, accessKeySecret, securityToken, regionID)
}
func NewVPCClientWithEndpoint(endpoint string, accessKeyId string, accessKeySecret string, regionID common.Region) *Client {
return NewVPCClientWithEndpointAndSecurityToken(endpoint, accessKeyId, accessKeySecret, "", regionID)
}
func NewVPCClientWithEndpointAndSecurityToken(endpoint string, accessKeyId string, accessKeySecret string, securityToken string, regionID common.Region) *Client {
client := &Client{}
client.WithEndpoint(endpoint).
WithVersion(VPCAPIVersion).
WithAccessKeyId(accessKeyId).
WithAccessKeySecret(accessKeySecret).
WithSecurityToken(securityToken).
WithServiceCode(VPCServiceCode).
WithRegionID(regionID).
InitClient()
return client
}