| 1 |
package cms |
| 2 |
|
| 3 |
import ( |
| 4 |
"net/http" |
| 5 |
|
| 6 |
"os" |
| 7 |
|
| 8 |
"github.com/denverdino/aliyungo/common" |
| 9 |
) |
| 10 |
|
| 11 |
type Client struct { |
| 12 |
endpoint string |
| 13 |
accessKeyId string |
| 14 |
accessKeySecret string |
| 15 |
|
| 16 |
debug bool |
| 17 |
httpClient *http.Client |
| 18 |
version string |
| 19 |
internal bool |
| 20 |
|
| 21 |
securityToken string |
| 22 |
} |
| 23 |
|
| 24 |
type CMSClient struct { |
| 25 |
common.Client |
| 26 |
} |
| 27 |
|
| 28 |
func (client *Client) SetSecurityToken(securityToken string) { |
| 29 |
client.securityToken = securityToken |
| 30 |
} |
| 31 |
|
| 32 |
func (client *Client) SetDebug(debug bool) { |
| 33 |
client.debug = debug |
| 34 |
} |
| 35 |
|
| 36 |
const ( |
| 37 |
,暂时保留 |
| 38 |
DefaultEndpoint = "http://alert.aliyuncs.com" |
| 39 |
APIVersion = "2015-08-15" |
| 40 |
METHOD_GET = "GET" |
| 41 |
METHOD_POST = "POST" |
| 42 |
METHOD_PUT = "PUT" |
| 43 |
METHOD_DELETE = "DELETE" |
| 44 |
|
| 45 |
CMSDefaultEndpoint = "http://metrics.cn-hangzhou.aliyuncs.com" |
| 46 |
CMSAPIVersion = "2017-03-01" |
| 47 |
CMSServiceCode = "cms" |
| 48 |
) |
| 49 |
|
| 50 |
的API |
| 51 |
|
| 52 |
func NewClient(accessKeyId, accessKeySecret string) *Client { |
| 53 |
return &Client{ |
| 54 |
accessKeyId: accessKeyId, |
| 55 |
accessKeySecret: accessKeySecret, |
| 56 |
internal: false, |
| 57 |
|
| 58 |
version: APIVersion, |
| 59 |
endpoint: DefaultEndpoint, |
| 60 |
httpClient: &http.Client{}, |
| 61 |
} |
| 62 |
} |
| 63 |
|
| 64 |
func (client *Client) GetApiUri() string { |
| 65 |
return client.endpoint |
| 66 |
} |
| 67 |
|
| 68 |
func (client *Client) GetAccessKey() string { |
| 69 |
return client.accessKeyId |
| 70 |
} |
| 71 |
|
| 72 |
func (client *Client) GetAccessSecret() string { |
| 73 |
return client.accessKeySecret |
| 74 |
} |
| 75 |
|
| 76 |
|
| 77 |
func NewCMSClient(accessKeyId, accessKeySecret string) *CMSClient { |
| 78 |
endpoint := os.Getenv("CMS_ENDPOINT") |
| 79 |
if endpoint == "" { |
| 80 |
endpoint = CMSDefaultEndpoint |
| 81 |
} |
| 82 |
return NewClientWithEndpoint(endpoint, accessKeyId, accessKeySecret) |
| 83 |
} |
| 84 |
|
| 85 |
func NewClientWithEndpoint(endpoint string, accessKeyId, accessKeySecret string) *CMSClient { |
| 86 |
client := &CMSClient{} |
| 87 |
client.Init(endpoint, CMSAPIVersion, accessKeyId, accessKeySecret) |
| 88 |
return client |
| 89 |
} |
| 90 |
|
| 91 |
func NewCMSRegionClient(accessKeyId, accessKeySecret string, regionID common.Region) *CMSClient { |
| 92 |
endpoint := os.Getenv("CMS_ENDPOINT") |
| 93 |
if endpoint == "" { |
| 94 |
endpoint = CMSDefaultEndpoint |
| 95 |
} |
| 96 |
|
| 97 |
return NewClientWithRegion(endpoint, accessKeyId, accessKeySecret, regionID) |
| 98 |
} |
| 99 |
|
| 100 |
func NewClientWithRegion(endpoint string, accessKeyId, accessKeySecret string, regionID common.Region) *CMSClient { |
| 101 |
client := &CMSClient{} |
| 102 |
client.NewInit(endpoint, CMSAPIVersion, accessKeyId, accessKeySecret, CMSServiceCode, regionID) |
| 103 |
return client |
| 104 |
} |