2017-03-04 05:06:32 -05:00
|
|
|
package ram
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
2017-11-27 21:22:16 -05:00
|
|
|
|
|
|
|
"github.com/denverdino/aliyungo/common"
|
2017-03-04 05:06:32 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
// RAMDefaultEndpoint is the default API endpoint of RAM services
|
|
|
|
RAMDefaultEndpoint = "https://ram.aliyuncs.com"
|
|
|
|
RAMAPIVersion = "2015-05-01"
|
|
|
|
)
|
|
|
|
|
|
|
|
type RamClient struct {
|
|
|
|
common.Client
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewClient(accessKeyId string, accessKeySecret string) RamClientInterface {
|
2017-11-27 21:22:16 -05:00
|
|
|
return NewClientWithSecurityToken(accessKeyId, accessKeySecret, "")
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewClientWithSecurityToken(accessKeyId string, accessKeySecret string, securityToken string) RamClientInterface {
|
2017-03-04 05:06:32 -05:00
|
|
|
endpoint := os.Getenv("RAM_ENDPOINT")
|
|
|
|
if endpoint == "" {
|
|
|
|
endpoint = RAMDefaultEndpoint
|
|
|
|
}
|
2017-11-27 21:22:16 -05:00
|
|
|
|
|
|
|
return NewClientWithEndpointAndSecurityToken(endpoint, accessKeyId, accessKeySecret, securityToken)
|
2017-03-04 05:06:32 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func NewClientWithEndpoint(endpoint string, accessKeyId string, accessKeySecret string) RamClientInterface {
|
2017-11-27 21:22:16 -05:00
|
|
|
return NewClientWithEndpointAndSecurityToken(endpoint, accessKeyId, accessKeySecret, "")
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewClientWithEndpointAndSecurityToken(endpoint string, accessKeyId string, accessKeySecret string, securityToken string) RamClientInterface {
|
2017-03-04 05:06:32 -05:00
|
|
|
client := &RamClient{}
|
2017-11-27 21:22:16 -05:00
|
|
|
client.WithEndpoint(endpoint).
|
|
|
|
WithVersion(RAMAPIVersion).
|
|
|
|
WithAccessKeyId(accessKeyId).
|
|
|
|
WithAccessKeySecret(accessKeySecret).
|
|
|
|
WithSecurityToken(securityToken).
|
|
|
|
InitClient()
|
2017-03-04 05:06:32 -05:00
|
|
|
return client
|
|
|
|
}
|