Ai
1 Star 0 Fork 0

Alibaba Cloud/saml2alibabacloud

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
ram_role.go 1.17 KB
一键复制 编辑 原始数据 按行查看 历史
daxingplay 提交于 2021-03-12 11:54 +08:00 . fix: support new role selection page
package saml2alibabacloud
import (
"fmt"
"strings"
)
// RamRole AlibabaCloud RAM role attributes
type RamRole struct {
RoleARN string
PrincipalARN string
Name string
}
// ParseRamRoles parses and splits the roles while also validating the contents
func ParseRamRoles(roles []string) ([]*RamRole, error) {
ramRoles := make([]*RamRole, len(roles))
for i, role := range roles {
ramRole, err := parseRole(role)
if err != nil {
return nil, err
}
ramRoles[i] = ramRole
}
return ramRoles, nil
}
func parseRole(role string) (*RamRole, error) {
tokens := strings.Split(role, ",")
if len(tokens) != 2 {
return nil, fmt.Errorf("invalid role string only %d tokens", len(tokens))
}
ramRole := &RamRole{}
for _, token := range tokens {
if strings.Contains(token, ":saml-provider") {
ramRole.PrincipalARN = strings.TrimSpace(token)
}
if strings.Contains(token, ":role") {
ramRole.RoleARN = strings.TrimSpace(token)
}
}
if ramRole.PrincipalARN == "" {
return nil, fmt.Errorf("unable to locate `PrincipalARN` in: %s", role)
}
if ramRole.RoleARN == "" {
return nil, fmt.Errorf("unable to locate `RoleARN` in: %s", role)
}
return ramRole, nil
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/aliyun/saml2alibabacloud.git
git@gitee.com:aliyun/saml2alibabacloud.git
aliyun
saml2alibabacloud
saml2alibabacloud
master

搜索帮助