| 1 |
package ecs |
| 2 |
|
| 3 |
import ( |
| 4 |
"os" |
| 5 |
|
| 6 |
"github.com/denverdino/aliyungo/common" |
| 7 |
) |
| 8 |
|
| 9 |
|
| 10 |
const DefaultWaitForInterval = 5 |
| 11 |
|
| 12 |
|
| 13 |
const DefaultTimeout = 60 |
| 14 |
|
| 15 |
type Client struct { |
| 16 |
common.Client |
| 17 |
} |
| 18 |
|
| 19 |
const ( |
| 20 |
|
| 21 |
ECSDefaultEndpoint = "https://ecs-cn-hangzhou.aliyuncs.com" |
| 22 |
ECSAPIVersion = "2014-05-26" |
| 23 |
ECSServiceCode = "ecs" |
| 24 |
|
| 25 |
VPCDefaultEndpoint = "https://vpc.aliyuncs.com" |
| 26 |
VPCAPIVersion = "2016-04-28" |
| 27 |
VPCServiceCode = "vpc" |
| 28 |
) |
| 29 |
|
| 30 |
|
| 31 |
func NewClient(accessKeyId, accessKeySecret string) *Client { |
| 32 |
endpoint := os.Getenv("ECS_ENDPOINT") |
| 33 |
if endpoint == "" { |
| 34 |
endpoint = ECSDefaultEndpoint |
| 35 |
} |
| 36 |
return NewClientWithEndpoint(endpoint, accessKeyId, accessKeySecret) |
| 37 |
} |
| 38 |
|
| 39 |
func NewClientWithRegion(endpoint string, accessKeyId string, accessKeySecret string, regionID common.Region) *Client { |
| 40 |
client := &Client{} |
| 41 |
client.NewInit(endpoint, ECSAPIVersion, accessKeyId, accessKeySecret, ECSServiceCode, regionID) |
| 42 |
return client |
| 43 |
} |
| 44 |
|
| 45 |
func NewClientWithEndpoint(endpoint string, accessKeyId string, accessKeySecret string) *Client { |
| 46 |
client := &Client{} |
| 47 |
client.Init(endpoint, ECSAPIVersion, accessKeyId, accessKeySecret) |
| 48 |
return client |
| 49 |
} |
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
func NewECSClient(accessKeyId, accessKeySecret string, regionID common.Region) *Client { |
| 55 |
return NewECSClientWithSecurityToken(accessKeyId, accessKeySecret, "", regionID) |
| 56 |
} |
| 57 |
|
| 58 |
func NewECSClientWithSecurityToken(accessKeyId string, accessKeySecret string, securityToken string, regionID common.Region) *Client { |
| 59 |
endpoint := os.Getenv("ECS_ENDPOINT") |
| 60 |
if endpoint == "" { |
| 61 |
endpoint = ECSDefaultEndpoint |
| 62 |
} |
| 63 |
|
| 64 |
return NewECSClientWithEndpointAndSecurityToken(endpoint, accessKeyId, accessKeySecret, securityToken, regionID) |
| 65 |
} |
| 66 |
|
| 67 |
func NewECSClientWithEndpoint(endpoint string, accessKeyId string, accessKeySecret string, regionID common.Region) *Client { |
| 68 |
return NewECSClientWithEndpointAndSecurityToken(endpoint, accessKeyId, accessKeySecret, "", regionID) |
| 69 |
} |
| 70 |
|
| 71 |
func NewECSClientWithEndpointAndSecurityToken(endpoint string, accessKeyId string, accessKeySecret string, securityToken string, regionID common.Region) *Client { |
| 72 |
client := &Client{} |
| 73 |
client.WithEndpoint(endpoint). |
| 74 |
WithVersion(ECSAPIVersion). |
| 75 |
WithAccessKeyId(accessKeyId). |
| 76 |
WithAccessKeySecret(accessKeySecret). |
| 77 |
WithSecurityToken(securityToken). |
| 78 |
WithServiceCode(ECSServiceCode). |
| 79 |
WithRegionID(regionID). |
| 80 |
InitClient() |
| 81 |
return client |
| 82 |
} |
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
func NewVPCClient(accessKeyId string, accessKeySecret string, regionID common.Region) *Client { |
| 88 |
return NewVPCClientWithSecurityToken(accessKeyId, accessKeySecret, "", regionID) |
| 89 |
} |
| 90 |
|
| 91 |
func NewVPCClientWithSecurityToken(accessKeyId string, accessKeySecret string, securityToken string, regionID common.Region) *Client { |
| 92 |
endpoint := os.Getenv("VPC_ENDPOINT") |
| 93 |
if endpoint == "" { |
| 94 |
endpoint = VPCDefaultEndpoint |
| 95 |
} |
| 96 |
|
| 97 |
return NewVPCClientWithEndpointAndSecurityToken(endpoint, accessKeyId, accessKeySecret, securityToken, regionID) |
| 98 |
} |
| 99 |
|
| 100 |
func NewVPCClientWithEndpoint(endpoint string, accessKeyId string, accessKeySecret string, regionID common.Region) *Client { |
| 101 |
return NewVPCClientWithEndpointAndSecurityToken(endpoint, accessKeyId, accessKeySecret, "", regionID) |
| 102 |
} |
| 103 |
|
| 104 |
func NewVPCClientWithEndpointAndSecurityToken(endpoint string, accessKeyId string, accessKeySecret string, securityToken string, regionID common.Region) *Client { |
| 105 |
client := &Client{} |
| 106 |
client.WithEndpoint(endpoint). |
| 107 |
WithVersion(VPCAPIVersion). |
| 108 |
WithAccessKeyId(accessKeyId). |
| 109 |
WithAccessKeySecret(accessKeySecret). |
| 110 |
WithSecurityToken(securityToken). |
| 111 |
WithServiceCode(VPCServiceCode). |
| 112 |
WithRegionID(regionID). |
| 113 |
InitClient() |
| 114 |
return client |
| 115 |
} |
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
func NewVPCClientWithRegion(endpoint string, accessKeyId string, accessKeySecret string, regionID common.Region) *Client { |
| 121 |
client := &Client{} |
| 122 |
client.NewInit(endpoint, VPCAPIVersion, accessKeyId, accessKeySecret, VPCServiceCode, regionID) |
| 123 |
return client |
| 124 |
} |