feat: sync lijiaoqiao implementation and staging validation artifacts
This commit is contained in:
35
platform-token-runtime/internal/auth/model/principal.go
Normal file
35
platform-token-runtime/internal/auth/model/principal.go
Normal file
@@ -0,0 +1,35 @@
|
||||
package model
|
||||
|
||||
import "strings"
|
||||
|
||||
const (
|
||||
RoleOwner = "owner"
|
||||
RoleViewer = "viewer"
|
||||
RoleAdmin = "admin"
|
||||
)
|
||||
|
||||
type Principal struct {
|
||||
RequestID string
|
||||
TokenID string
|
||||
SubjectID string
|
||||
Role string
|
||||
Scope []string
|
||||
}
|
||||
|
||||
func (p Principal) HasScope(required string) bool {
|
||||
if required == "" {
|
||||
return true
|
||||
}
|
||||
for _, scope := range p.Scope {
|
||||
if scope == required {
|
||||
return true
|
||||
}
|
||||
if strings.HasSuffix(scope, ":*") {
|
||||
prefix := strings.TrimSuffix(scope, "*")
|
||||
if strings.HasPrefix(required, prefix) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
Reference in New Issue
Block a user