| 1 |
package kms |
| 2 |
|
| 3 |
import ( |
| 4 |
"os" |
| 5 |
|
| 6 |
"github.com/denverdino/aliyungo/common" |
| 7 |
) |
| 8 |
|
| 9 |
const ( |
| 10 |
|
| 11 |
KMSDefaultEndpoint = "https://kms.cn-hangzhou.aliyuncs.com" |
| 12 |
KMSAPIVersion = "2016-01-20" |
| 13 |
KMSServiceCode = "kms" |
| 14 |
) |
| 15 |
|
| 16 |
type Client struct { |
| 17 |
common.Client |
| 18 |
} |
| 19 |
|
| 20 |
|
| 21 |
func NewClient(accessKeyId, accessKeySecret string) *Client { |
| 22 |
endpoint := os.Getenv("KMS_ENDPOINT") |
| 23 |
if endpoint == "" { |
| 24 |
endpoint = KMSDefaultEndpoint |
| 25 |
} |
| 26 |
return NewClientWithEndpoint(endpoint, accessKeyId, accessKeySecret) |
| 27 |
} |
| 28 |
|
| 29 |
func NewClientWithRegion(accessKeyId string, accessKeySecret string, regionID common.Region) *Client { |
| 30 |
endpoint := os.Getenv("KMS_ENDPOINT") |
| 31 |
if endpoint == "" { |
| 32 |
endpoint = KMSDefaultEndpoint |
| 33 |
} |
| 34 |
client := &Client{} |
| 35 |
client.NewInit(endpoint, KMSAPIVersion, accessKeyId, accessKeySecret, KMSServiceCode, regionID) |
| 36 |
return client |
| 37 |
} |
| 38 |
|
| 39 |
func NewClientWithEndpoint(endpoint string, accessKeyId string, accessKeySecret string) *Client { |
| 40 |
client := &Client{} |
| 41 |
client.Init(endpoint, KMSAPIVersion, accessKeyId, accessKeySecret) |
| 42 |
return client |
| 43 |
} |
| 44 |
|
| 45 |
func NewECSClientWithSecurityToken(accessKeyId string, accessKeySecret string, securityToken string, regionID common.Region) *Client { |
| 46 |
endpoint := os.Getenv("KMS_ENDPOINT") |
| 47 |
if endpoint == "" { |
| 48 |
endpoint = KMSDefaultEndpoint |
| 49 |
} |
| 50 |
|
| 51 |
return NewKMSClientWithEndpointAndSecurityToken(endpoint, accessKeyId, accessKeySecret, securityToken, regionID) |
| 52 |
} |
| 53 |
|
| 54 |
func NewKMSClientWithEndpointAndSecurityToken(endpoint string, accessKeyId string, accessKeySecret string, securityToken string, regionID common.Region) *Client { |
| 55 |
client := &Client{} |
| 56 |
client.WithEndpoint(endpoint). |
| 57 |
WithVersion(KMSAPIVersion). |
| 58 |
WithAccessKeyId(accessKeyId). |
| 59 |
WithAccessKeySecret(accessKeySecret). |
| 60 |
WithSecurityToken(securityToken). |
| 61 |
WithServiceCode(KMSServiceCode). |
| 62 |
WithRegionID(regionID). |
| 63 |
InitClient() |
| 64 |
return client |
| 65 |
} |