pkg/auth: move package to consoleauth

To avoid further name collisions, the very broad named package gets moved into
the consoleauth package where its also mainly being used.

Change-Id: Ie563c9700adbf0553baca2b7b8ba4a1d9c29d144
This commit is contained in:
Stefan Benten 2020-10-06 12:40:31 +02:00
parent 44bd65795b
commit 14a2050b8d
7 changed files with 14 additions and 17 deletions

View File

@ -25,7 +25,6 @@ import (
"storj.io/common/uuid"
"storj.io/private/debug"
"storj.io/private/version"
"storj.io/storj/pkg/auth"
"storj.io/storj/pkg/revocation"
"storj.io/storj/pkg/server"
versionchecker "storj.io/storj/private/version/checker"
@ -40,6 +39,7 @@ import (
"storj.io/storj/satellite/admin"
"storj.io/storj/satellite/audit"
"storj.io/storj/satellite/console"
"storj.io/storj/satellite/console/consoleauth"
"storj.io/storj/satellite/console/consoleweb"
"storj.io/storj/satellite/contact"
"storj.io/storj/satellite/dbcleanup"
@ -269,7 +269,7 @@ func (system *Satellite) AuthenticatedContext(ctx context.Context, userID uuid.U
return nil, err
}
auth, err := system.API.Console.Service.Authorize(auth.WithAPIKey(ctx, []byte(token)))
auth, err := system.API.Console.Service.Authorize(consoleauth.WithAPIKey(ctx, []byte(token)))
if err != nil {
return nil, err
}

View File

@ -1,7 +1,7 @@
// Copyright (C) 2019 Storj Labs, Inc.
// See LICENSE for copying information.
package auth
package consoleauth
import (
"context"

View File

@ -17,7 +17,6 @@ import (
"storj.io/common/testcontext"
"storj.io/common/testrand"
"storj.io/common/uuid"
"storj.io/storj/pkg/auth"
"storj.io/storj/private/post"
"storj.io/storj/satellite"
"storj.io/storj/satellite/accounting"
@ -153,7 +152,7 @@ func TestGrapqhlMutation(t *testing.T) {
token, err := service.Token(ctx, createUser.Email, createUser.Password)
require.NoError(t, err)
sauth, err := service.Authorize(auth.WithAPIKey(ctx, []byte(token)))
sauth, err := service.Authorize(consoleauth.WithAPIKey(ctx, []byte(token)))
require.NoError(t, err)
authCtx := console.WithAuth(ctx, sauth)
@ -177,7 +176,7 @@ func TestGrapqhlMutation(t *testing.T) {
token, err = service.Token(ctx, rootUser.Email, createUser.Password)
require.NoError(t, err)
sauth, err = service.Authorize(auth.WithAPIKey(ctx, []byte(token)))
sauth, err = service.Authorize(consoleauth.WithAPIKey(ctx, []byte(token)))
require.NoError(t, err)
authCtx = console.WithAuth(ctx, sauth)

View File

@ -15,7 +15,6 @@ import (
"storj.io/common/testcontext"
"storj.io/common/testrand"
"storj.io/storj/pkg/auth"
"storj.io/storj/satellite"
"storj.io/storj/satellite/accounting"
"storj.io/storj/satellite/accounting/live"
@ -147,7 +146,7 @@ func TestGraphqlQuery(t *testing.T) {
token, err := service.Token(ctx, createUser.Email, createUser.Password)
require.NoError(t, err)
sauth, err := service.Authorize(auth.WithAPIKey(ctx, []byte(token)))
sauth, err := service.Authorize(consoleauth.WithAPIKey(ctx, []byte(token)))
require.NoError(t, err)
authCtx := console.WithAuth(ctx, sauth)

View File

@ -31,9 +31,9 @@ import (
"storj.io/common/errs2"
"storj.io/common/uuid"
"storj.io/storj/pkg/auth"
"storj.io/storj/private/web"
"storj.io/storj/satellite/console"
"storj.io/storj/satellite/console/consoleauth"
"storj.io/storj/satellite/console/consoleweb/consoleapi"
"storj.io/storj/satellite/console/consoleweb/consoleql"
"storj.io/storj/satellite/console/consoleweb/consolewebauth"
@ -319,7 +319,7 @@ func (server *Server) withAuth(handler http.Handler) http.Handler {
return console.WithAuthFailure(ctx, err)
}
ctx = auth.WithAPIKey(ctx, []byte(token))
ctx = consoleauth.WithAPIKey(ctx, []byte(token))
auth, err := server.service.Authorize(ctx)
if err != nil {
@ -354,7 +354,7 @@ func (server *Server) bucketUsageReportHandler(w http.ResponseWriter, r *http.Re
return
}
auth, err := server.service.Authorize(auth.WithAPIKey(ctx, []byte(token)))
auth, err := server.service.Authorize(consoleauth.WithAPIKey(ctx, []byte(token)))
if err != nil {
server.serveError(w, http.StatusUnauthorized)
return

View File

@ -20,7 +20,6 @@ import (
"storj.io/common/macaroon"
"storj.io/common/memory"
"storj.io/common/uuid"
"storj.io/storj/pkg/auth"
"storj.io/storj/satellite/accounting"
"storj.io/storj/satellite/console/consoleauth"
"storj.io/storj/satellite/payments"
@ -1112,12 +1111,12 @@ func (s *Service) AddProjectMembers(ctx context.Context, projectID uuid.UUID, em
// DeleteProjectMembers removes users by email from given project.
func (s *Service) DeleteProjectMembers(ctx context.Context, projectID uuid.UUID, emails []string) (err error) {
defer mon.Task()(&ctx)(&err)
authInfo, err := s.getAuthAndAuditLog(ctx, "delete project members", zap.String("projectID", projectID.String()), zap.Strings("emails", emails))
auth, err := s.getAuthAndAuditLog(ctx, "delete project members", zap.String("projectID", projectID.String()), zap.Strings("emails", emails))
if err != nil {
return err
}
if _, err = s.isProjectMember(ctx, authInfo.User.ID, projectID); err != nil {
if _, err = s.isProjectMember(ctx, auth.User.ID, projectID); err != nil {
if ErrUnauthorized.Has(err) {
return ErrUnauthorized.Wrap(err)
}
@ -1439,7 +1438,7 @@ func (s *Service) GetProjectUsageLimits(ctx context.Context, projectID uuid.UUID
// Authorize validates token from context and returns authorized Authorization.
func (s *Service) Authorize(ctx context.Context) (a Authorization, err error) {
defer mon.Task()(&ctx)(&err)
tokenS, ok := auth.GetAPIKey(ctx)
tokenS, ok := consoleauth.GetAPIKey(ctx)
if !ok {
return Authorization{}, ErrUnauthorized.New("no api key was provided")
}

View File

@ -21,8 +21,8 @@ import (
"storj.io/common/rpc/rpcstatus"
"storj.io/common/storj"
"storj.io/common/uuid"
"storj.io/storj/pkg/auth"
"storj.io/storj/satellite/console"
"storj.io/storj/satellite/console/consoleauth"
)
const (
@ -127,7 +127,7 @@ func getAPIKey(ctx context.Context, header *pb.RequestHeader) (key *macaroon.API
return macaroon.ParseRawAPIKey(header.ApiKey)
}
keyData, ok := auth.GetAPIKey(ctx)
keyData, ok := consoleauth.GetAPIKey(ctx)
if !ok {
return nil, errs.New("missing credentials")
}