代码拉取完成,页面将自动刷新
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
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。