upgrade get sts token
@@ -30,6 +30,7 @@ import (
"time"
"github.com/AliyunContainerService/csi-plugin/pkg/utils"
+ log "github.com/Sirupsen/logrus"
"github.com/aliyun/alibaba-cloud-sdk-go/services/ecs"
)
@@ -70,8 +71,6 @@ func ProvisionVersion() string {
return VERSION
}
-//var attachdetachMutex = keymutex.NewKeyMutex()
-
// struct for access key
type DefaultOptions struct {
Global struct {
@@ -82,6 +81,16 @@ type DefaultOptions struct {
}
}
+// Define STS Token Response
+type RoleAuth struct {
+ AccessKeyId string
+ AccessKeySecret string
+ Expiration time.Time
+ SecurityToken string
+ LastUpdated time.Time
+ Code string
+}
+
func newEcsClient(access_key_id, access_key_secret, access_token string) *ecs.Client {
ecsClient := &ecs.Client{}
var err error
@@ -138,21 +147,28 @@ func GetMetaData(resource string) string {
// get STS AK
func GetSTSAK() (string, string, string) {
- /*
- m := metadata.NewMetaData(nil)
- rolename := ""
- var err error
- if rolename, err = m.Role(); err != nil {
+ roleAuth := RoleAuth{}
+ subpath := "ram/security-credentials/"
+ roleName, err := utils.GetMetaData(subpath)
+ if err != nil {
+ log.Errorf("GetSTSToken: request roleName with error: %s", err.Error())
return "", "", ""
}
- role, err := m.RamRoleToken(rolename)
+
+ fullPath := filepath.Join(subpath, roleName)
+ roleInfo, err := utils.GetMetaData(fullPath)
if err != nil {
+ log.Errorf("GetSTSToken: request roleInfo with error: %s", err.Error())
return "", "", ""
}
- return role.AccessKeyId, role.AccessKeySecret, role.SecurityToken
- */
+
+ err = json.Unmarshal([]byte(roleInfo), &roleAuth)
+ if err != nil {
+ log.Errorf("GetSTSToken: unmarshal roleInfo: %s, with error: %s", roleInfo, err.Error())
return "", "", ""
}
+ return roleAuth.AccessKeyId, roleAuth.AccessKeySecret, roleAuth.SecurityToken
+}
func GetLocalAK() (string, string) {
var accessKeyID, accessSecret string
