diff --git a/src/pkg/token/claims/registry/accesses.go b/src/pkg/token/claims/registry/accesses.go deleted file mode 100644 index 3665a415d..000000000 --- a/src/pkg/token/claims/registry/accesses.go +++ /dev/null @@ -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 -} diff --git a/src/pkg/token/claims/registry/registry.go b/src/pkg/token/claims/registry/registry.go deleted file mode 100644 index 07d18ce58..000000000 --- a/src/pkg/token/claims/registry/registry.go +++ /dev/null @@ -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 -} diff --git a/src/pkg/token/claims/registry/registry_test.go b/src/pkg/token/claims/registry/registry_test.go deleted file mode 100644 index 600a07edd..000000000 --- a/src/pkg/token/claims/registry/registry_test.go +++ /dev/null @@ -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)) -}