mirror of
https://github.com/kyverno/kyverno.git
synced 2025-03-29 02:45:06 +00:00
* feat: add cel user lib Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com> * unit test Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com> --------- Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>
33 lines
673 B
Go
33 lines
673 B
Go
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)
|
|
}
|
|
}
|