File: client.go

package info (click to toggle)
golang-github-denverdino-aliyungo 0.0~git20180921.13fa8aa-4
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 1,824 kB
  • sloc: xml: 1,359; makefile: 3
file content (78 lines) | stat: -rw-r--r-- 2,567 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package pvtz

import (
	"os"

	"github.com/denverdino/aliyungo/common"
)

// 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
	PVTZDefaultEndpoint = "https://pvtz.aliyuncs.com"
	PVTZServiceCode     = "pvtz"
	PVTZAPIVersion      = "2018-01-01"
)

// NewClient creates a new instance of ECS client
func NewClient(accessKeyId, accessKeySecret string) *Client {
	endpoint := os.Getenv("PVTZ_ENDPOINT")
	if endpoint == "" {
		endpoint = PVTZDefaultEndpoint
	}
	return NewClientWithEndpoint(endpoint, accessKeyId, accessKeySecret)
}

func NewClientWithRegion(endpoint string, accessKeyId string, accessKeySecret string, regionID common.Region) *Client {
	client := &Client{}
	client.NewInit(endpoint, PVTZAPIVersion, accessKeyId, accessKeySecret, PVTZServiceCode, regionID)
	return client
}

func NewClientWithEndpoint(endpoint string, accessKeyId string, accessKeySecret string) *Client {
	client := &Client{}
	client.Init(endpoint, PVTZAPIVersion, accessKeyId, accessKeySecret)
	return client
}

// ---------------------------------------
// NewPVTZClient creates a new instance of PVTZ client
// ---------------------------------------
func NewPVTZClient(accessKeyId, accessKeySecret string, regionID common.Region) *Client {
	return NewPVTZClientWithSecurityToken(accessKeyId, accessKeySecret, "", regionID)
}

func NewPVTZClientWithSecurityToken(accessKeyId string, accessKeySecret string, securityToken string, regionID common.Region) *Client {
	endpoint := os.Getenv("PVTZ_ENDPOINT")
	if endpoint == "" {
		endpoint = PVTZDefaultEndpoint
	}

	return NewPVTZClientWithEndpointAndSecurityToken(endpoint, accessKeyId, accessKeySecret, securityToken, regionID)
}

func NewPVTZClientWithEndpoint(endpoint string, accessKeyId string, accessKeySecret string, regionID common.Region) *Client {
	return NewPVTZClientWithEndpointAndSecurityToken(endpoint, accessKeyId, accessKeySecret, "", regionID)
}

func NewPVTZClientWithEndpointAndSecurityToken(endpoint string, accessKeyId string, accessKeySecret string, securityToken string, regionID common.Region) *Client {
	client := &Client{}
	client.WithEndpoint(endpoint).
		WithVersion(PVTZAPIVersion).
		WithAccessKeyId(accessKeyId).
		WithAccessKeySecret(accessKeySecret).
		WithSecurityToken(securityToken).
		WithServiceCode(PVTZServiceCode).
		WithRegionID(regionID).
		InitClient()
	return client
}