1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2025-03-31 03:45:17 +00:00
kyverno/pkg/cel/libs/user/impl.go

34 lines
673 B
Go
Raw Normal View History

package user
import (
"strings"
"github.com/google/cel-go/common/types"
"github.com/google/cel-go/common/types/ref"
"github.com/kyverno/kyverno/pkg/cel/utils"
)
const (
saPrefix = "system:serviceaccount:"
)
type impl struct {
types.Adapter
}
func (c *impl) parse_service_account_string(user ref.Val) ref.Val {
if user, err := utils.ConvertToNative[string](user); err != nil {
return types.WrapErr(err)
} else {
var sa ServiceAccount
if strings.HasPrefix(user, saPrefix) {
user = user[len(saPrefix):]
if sep := strings.Index(user, ":"); sep != -1 {
sa.Namesapce = user[:sep]
sa.Name = user[sep+1:]
}
}
return c.NativeToValue(sa)
}
}