Skip to content

Commit

Permalink
add CreateHome logic on login
Browse files Browse the repository at this point in the history
  • Loading branch information
labkode committed Jan 13, 2020
1 parent c7432a0 commit 879ec55
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 33 deletions.
1 change: 1 addition & 0 deletions .mailmap
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
Aritz Brosa <aritz.brosa.iartza@cern.ch> zazola <aritz.brosa@gmail.com>
Giuseppe Lo Presti <giuseppe.lopresti@cern.ch> Giuseppe <giuseppe.lopresti@cern.ch>
Michael D'Silva <michael.dsilva@aarnet.edu.au>
1 change: 1 addition & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- Hugo Gonzalez Labrador <github@hugo.labkode.com>
- Ilja Neumann <ineumann@owncloud.com>
- Jörn Friedrich Dreyer <jfd@butonic.de>
- Michael D'Silva <md@aarnet.edu.au>
- Michael D'Silva <michael.dsilva@aarnet.edu.au>
- Mohitty <mohitt@iitk.ac.in>
- Thomas Boerger <thomas@webhippie.de>
61 changes: 28 additions & 33 deletions internal/grpc/services/gateway/authprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
registry "github.com/cs3org/go-cs3apis/cs3/auth/registry/v1beta1"
gateway "github.com/cs3org/go-cs3apis/cs3/gateway/v1beta1"
rpc "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1"
storageprovider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
"github.com/cs3org/reva/pkg/appctx"
"github.com/cs3org/reva/pkg/errtypes"
"github.com/cs3org/reva/pkg/rgrpc/status"
Expand Down Expand Up @@ -82,39 +83,6 @@ func (s *svc) Authenticate(ctx context.Context, req *gateway.AuthenticateRequest
}, nil
}

// TODO(labkode): we don't ned to call the user manager in the auth phase
// as the auth must provide a valid user. The mapping between user credentials and
// unique claims is done at the Authenticate logic an not here.
/*
userClient, err := pool.GetUserProviderServiceClient(s.c.UserProviderEndpoint)
if err != nil {
log.Err(err).Msg("error getting user provider client")
return &gateway.AuthenticateResponse{
Status: status.NewInternal(ctx, err, "error getting user provider service client"),
}, nil
}
getUserReq := &user.GetUserRequest{
UserId: uid,
}
getUserRes, err := userClient.GetUser(ctx, getUserReq)
if err != nil {
err = errors.Wrap(err, "authsvc: error in GetUser")
res := &gateway.AuthenticateResponse{
Status: status.NewUnauthenticated(ctx, err, "error getting user information"),
}
return res, nil
}
if getUserRes.Status.Code != rpc.Code_CODE_OK {
err := status.NewErrorFromCode(getUserRes.Status.Code, "authsvc")
return &gateway.AuthenticateResponse{
Status: status.NewUnauthenticated(ctx, err, "error getting user information"),
}, nil
}
*/
user := res.User

token, err := s.tokenmgr.MintToken(ctx, user)
Expand All @@ -126,6 +94,33 @@ func (s *svc) Authenticate(ctx context.Context, req *gateway.AuthenticateRequest
return res, nil
}

if s.c.DisableHomeCreationOnLogin {
gwRes := &gateway.AuthenticateResponse{
Status: status.NewOK(ctx),
User: res.User,
Token: token,
}
return gwRes, nil
}

// create home directory
createHomeReq := &storageprovider.CreateHomeRequest{}
createHomeRes, err := s.CreateHome(ctx, createHomeReq)
if err != nil {
log.Err(err).Msg("user id is nil")
return &gateway.AuthenticateResponse{
Status: status.NewInternal(ctx, err, "error creating user home"),
}, nil
}

if createHomeRes.Status.Code != rpc.Code_CODE_OK {
err := status.NewErrorFromCode(createHomeRes.Status.Code, "gateway")
log.Err(err).Msg("error calling Createhome")
return &gateway.AuthenticateResponse{
Status: status.NewInternal(ctx, err, "error creating user home"),
}, nil
}

gwRes := &gateway.AuthenticateResponse{
Status: status.NewOK(ctx),
User: res.User,
Expand Down
1 change: 1 addition & 0 deletions internal/grpc/services/gateway/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ type config struct {
UserProviderEndpoint string `mapstructure:"userprovidersvc"`
CommitShareToStorageGrant bool `mapstructure:"commit_share_to_storage_grant"`
CommitShareToStorageRef bool `mapstructure:"commit_share_to_storage_ref"`
DisableHomeCreationOnLogin bool `mapstructure:"disable_home_creation_on_login"`
DataGatewayEndpoint string `mapstructure:"datagateway"`
TransferSharedSecret string `mapstructure:"transfer_shared_secret"`
TranserExpires int64 `mapstructure:"transfer_expires"`
Expand Down

0 comments on commit 879ec55

Please sign in to comment.