mirror of
https://github.com/goharbor/harbor.git
synced 2025-03-29 14:55:52 +01:00
Remove the registry claim pacakge
This commit removes `src/pkg/token/claims/registry` that is not referenced by other packages. Signed-off-by: Daniel Jiang <jiangd@vmware.com>
This commit is contained in:
parent
e064bd4c01
commit
c303dcf617
@ -1,49 +0,0 @@
|
|||||||
package registry
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/docker/distribution/registry/auth"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Accesses ...
|
|
||||||
type Accesses map[auth.Resource]actions
|
|
||||||
|
|
||||||
// Contains ...
|
|
||||||
func (s Accesses) Contains(access auth.Access) bool {
|
|
||||||
actionSet, ok := s[access.Resource]
|
|
||||||
if ok {
|
|
||||||
return actionSet.contains(access.Action)
|
|
||||||
}
|
|
||||||
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
type actions struct {
|
|
||||||
stringSet
|
|
||||||
}
|
|
||||||
|
|
||||||
func newActions(set ...string) actions {
|
|
||||||
return actions{newStringSet(set...)}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s actions) contains(action string) bool {
|
|
||||||
return s.stringSet.contains(action)
|
|
||||||
}
|
|
||||||
|
|
||||||
type stringSet map[string]struct{}
|
|
||||||
|
|
||||||
func newStringSet(keys ...string) stringSet {
|
|
||||||
ss := make(stringSet, len(keys))
|
|
||||||
ss.add(keys...)
|
|
||||||
return ss
|
|
||||||
}
|
|
||||||
|
|
||||||
func (ss stringSet) add(keys ...string) {
|
|
||||||
for _, key := range keys {
|
|
||||||
ss[key] = struct{}{}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (ss stringSet) contains(key string) bool {
|
|
||||||
_, ok := ss[key]
|
|
||||||
return ok
|
|
||||||
}
|
|
@ -1,38 +0,0 @@
|
|||||||
package registry
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/dgrijalva/jwt-go"
|
|
||||||
"github.com/docker/distribution/registry/auth"
|
|
||||||
"github.com/docker/distribution/registry/auth/token"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Claim implements the interface of jwt.Claims
|
|
||||||
type Claim struct {
|
|
||||||
jwt.StandardClaims
|
|
||||||
Access []*token.ResourceActions `json:"access"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// Valid valid the standard claims
|
|
||||||
func (rc *Claim) Valid() error {
|
|
||||||
return rc.StandardClaims.Valid()
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetAccess ...
|
|
||||||
func (rc *Claim) GetAccess() Accesses {
|
|
||||||
accesses := make(Accesses, len(rc.Access))
|
|
||||||
for _, resourceActions := range rc.Access {
|
|
||||||
resource := auth.Resource{
|
|
||||||
Type: resourceActions.Type,
|
|
||||||
Name: resourceActions.Name,
|
|
||||||
}
|
|
||||||
set, exists := accesses[resource]
|
|
||||||
if !exists {
|
|
||||||
set = newActions()
|
|
||||||
accesses[resource] = set
|
|
||||||
}
|
|
||||||
for _, action := range resourceActions.Actions {
|
|
||||||
set.add(action)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return accesses
|
|
||||||
}
|
|
@ -1,54 +0,0 @@
|
|||||||
package registry
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/docker/distribution/registry/auth"
|
|
||||||
"github.com/docker/distribution/registry/auth/token"
|
|
||||||
"github.com/goharbor/harbor/src/common/rbac"
|
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
"testing"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestValid(t *testing.T) {
|
|
||||||
access := &token.ResourceActions{
|
|
||||||
Type: "type",
|
|
||||||
Name: "repository",
|
|
||||||
Actions: []string{"pull", "push"},
|
|
||||||
}
|
|
||||||
accesses := []*token.ResourceActions{}
|
|
||||||
accesses = append(accesses, access)
|
|
||||||
rClaims := &Claim{
|
|
||||||
Access: accesses,
|
|
||||||
}
|
|
||||||
assert.Nil(t, rClaims.Valid())
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestGetAccessSet(t *testing.T) {
|
|
||||||
access := &token.ResourceActions{
|
|
||||||
Type: "repository",
|
|
||||||
Name: "hello-world",
|
|
||||||
Actions: []string{"pull", "push", "scanner-pull"},
|
|
||||||
}
|
|
||||||
accesses := []*token.ResourceActions{}
|
|
||||||
accesses = append(accesses, access)
|
|
||||||
rClaims := &Claim{
|
|
||||||
Access: accesses,
|
|
||||||
}
|
|
||||||
|
|
||||||
auth1 := auth.Access{
|
|
||||||
Resource: auth.Resource{
|
|
||||||
Type: "repository",
|
|
||||||
Name: "hello-world",
|
|
||||||
},
|
|
||||||
Action: rbac.ActionScannerPull.String(),
|
|
||||||
}
|
|
||||||
auth2 := auth.Access{
|
|
||||||
Resource: auth.Resource{
|
|
||||||
Type: "repository",
|
|
||||||
Name: "busubox",
|
|
||||||
},
|
|
||||||
Action: rbac.ActionScannerPull.String(),
|
|
||||||
}
|
|
||||||
set := rClaims.GetAccess()
|
|
||||||
assert.True(t, set.Contains(auth1))
|
|
||||||
assert.False(t, set.Contains(auth2))
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user