mirror of
https://github.com/owncloud/ocis
synced 2026-04-25 17:25:21 +02:00
feat: clean up multi-instance-ocis
Signed-off-by: Julian Koberg <julian.koberg@kiteworks.com>
This commit is contained in:
@@ -20,7 +20,7 @@ var (
|
||||
type UserBackend interface {
|
||||
GetUserByClaims(ctx context.Context, claim, value string) (*cs3.User, string, error)
|
||||
Authenticate(ctx context.Context, username string, password string) (*cs3.User, string, error)
|
||||
CreateUserFromClaims(ctx context.Context, claims map[string]interface{}, guest bool) (*cs3.User, error)
|
||||
CreateUserFromClaims(ctx context.Context, claims map[string]interface{}) (*cs3.User, error)
|
||||
UpdateUserIfNeeded(ctx context.Context, user *cs3.User, claims map[string]interface{}) error
|
||||
SyncGroupMemberships(ctx context.Context, user *cs3.User, claims map[string]interface{}) error
|
||||
}
|
||||
|
||||
@@ -163,7 +163,7 @@ func (c *cs3backend) Authenticate(ctx context.Context, username string, password
|
||||
// attributes from the provided `claims` map. On success it returns the new
|
||||
// user. If the user already exist this is not considered an error and the
|
||||
// function will just return the existing user.
|
||||
func (c *cs3backend) CreateUserFromClaims(ctx context.Context, claims map[string]interface{}, guest bool) (*cs3.User, error) {
|
||||
func (c *cs3backend) CreateUserFromClaims(ctx context.Context, claims map[string]interface{}) (*cs3.User, error) {
|
||||
gatewayClient, err := c.gatewaySelector.Next()
|
||||
if err != nil {
|
||||
c.logger.Error().Err(err).Msg("could not select next gateway client")
|
||||
@@ -188,13 +188,12 @@ func (c *cs3backend) CreateUserFromClaims(ctx context.Context, claims map[string
|
||||
return nil, err
|
||||
}
|
||||
|
||||
newUser, err := c.libregraphUserFromClaims(claims, guest)
|
||||
newUser, err := c.libregraphUserFromClaims(claims)
|
||||
if err != nil {
|
||||
c.logger.Error().Err(err).Interface("claims", claims).Msg("Error creating user from claims")
|
||||
return nil, fmt.Errorf("error creating user from claims: %w", err)
|
||||
}
|
||||
|
||||
fmt.Println("XXX PROXY Creating user with", newUser.GetUserType())
|
||||
req := lgClient.UsersApi.CreateUser(newctx).User(newUser)
|
||||
|
||||
created, resp, err := req.Execute()
|
||||
@@ -237,7 +236,7 @@ func (c *cs3backend) CreateUserFromClaims(ctx context.Context, claims map[string
|
||||
}
|
||||
|
||||
func (c *cs3backend) UpdateUserIfNeeded(ctx context.Context, user *cs3.User, claims map[string]interface{}) error {
|
||||
newUser, err := c.libregraphUserFromClaims(claims, false)
|
||||
newUser, err := c.libregraphUserFromClaims(claims)
|
||||
if err != nil {
|
||||
c.logger.Error().Err(err).Interface("claims", claims).Msg("Error converting claims to user")
|
||||
return fmt.Errorf("error converting claims to updated user: %w", err)
|
||||
@@ -476,7 +475,7 @@ func (c *cs3backend) isAlreadyExists(resp *http.Response) (bool, error) {
|
||||
return false, nil
|
||||
}
|
||||
|
||||
func (c *cs3backend) libregraphUserFromClaims(claims map[string]interface{}, guest bool) (libregraph.User, error) {
|
||||
func (c *cs3backend) libregraphUserFromClaims(claims map[string]interface{}) (libregraph.User, error) {
|
||||
user := libregraph.User{}
|
||||
if dn, ok := claims[c.autoProvisionClaims.DisplayName].(string); ok {
|
||||
user.SetDisplayName(dn)
|
||||
@@ -492,10 +491,6 @@ func (c *cs3backend) libregraphUserFromClaims(claims map[string]interface{}, gue
|
||||
if mail, ok := claims[c.autoProvisionClaims.Email].(string); ok {
|
||||
user.SetMail(mail)
|
||||
}
|
||||
if guest {
|
||||
user.SetUserType("guest")
|
||||
}
|
||||
|
||||
sub, subExists := claims[oidc.Sub].(string)
|
||||
iss, issExists := claims[oidc.Iss].(string)
|
||||
|
||||
|
||||
@@ -89,9 +89,9 @@ func (_c *UserBackend_Authenticate_Call) RunAndReturn(run func(context.Context,
|
||||
return _c
|
||||
}
|
||||
|
||||
// CreateUserFromClaims provides a mock function with given fields: ctx, claims, guest
|
||||
func (_m *UserBackend) CreateUserFromClaims(ctx context.Context, claims map[string]interface{}, guest bool) (*userv1beta1.User, error) {
|
||||
ret := _m.Called(ctx, claims, guest)
|
||||
// CreateUserFromClaims provides a mock function with given fields: ctx, claims
|
||||
func (_m *UserBackend) CreateUserFromClaims(ctx context.Context, claims map[string]interface{}) (*userv1beta1.User, error) {
|
||||
ret := _m.Called(ctx, claims)
|
||||
|
||||
if len(ret) == 0 {
|
||||
panic("no return value specified for CreateUserFromClaims")
|
||||
@@ -99,19 +99,19 @@ func (_m *UserBackend) CreateUserFromClaims(ctx context.Context, claims map[stri
|
||||
|
||||
var r0 *userv1beta1.User
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(0).(func(context.Context, map[string]interface{}, bool) (*userv1beta1.User, error)); ok {
|
||||
return rf(ctx, claims, guest)
|
||||
if rf, ok := ret.Get(0).(func(context.Context, map[string]interface{}) (*userv1beta1.User, error)); ok {
|
||||
return rf(ctx, claims)
|
||||
}
|
||||
if rf, ok := ret.Get(0).(func(context.Context, map[string]interface{}, bool) *userv1beta1.User); ok {
|
||||
r0 = rf(ctx, claims, guest)
|
||||
if rf, ok := ret.Get(0).(func(context.Context, map[string]interface{}) *userv1beta1.User); ok {
|
||||
r0 = rf(ctx, claims)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).(*userv1beta1.User)
|
||||
}
|
||||
}
|
||||
|
||||
if rf, ok := ret.Get(1).(func(context.Context, map[string]interface{}, bool) error); ok {
|
||||
r1 = rf(ctx, claims, guest)
|
||||
if rf, ok := ret.Get(1).(func(context.Context, map[string]interface{}) error); ok {
|
||||
r1 = rf(ctx, claims)
|
||||
} else {
|
||||
r1 = ret.Error(1)
|
||||
}
|
||||
@@ -127,14 +127,13 @@ type UserBackend_CreateUserFromClaims_Call struct {
|
||||
// CreateUserFromClaims is a helper method to define mock.On call
|
||||
// - ctx context.Context
|
||||
// - claims map[string]interface{}
|
||||
// - guest bool
|
||||
func (_e *UserBackend_Expecter) CreateUserFromClaims(ctx interface{}, claims interface{}, guest interface{}) *UserBackend_CreateUserFromClaims_Call {
|
||||
return &UserBackend_CreateUserFromClaims_Call{Call: _e.mock.On("CreateUserFromClaims", ctx, claims, guest)}
|
||||
func (_e *UserBackend_Expecter) CreateUserFromClaims(ctx interface{}, claims interface{}) *UserBackend_CreateUserFromClaims_Call {
|
||||
return &UserBackend_CreateUserFromClaims_Call{Call: _e.mock.On("CreateUserFromClaims", ctx, claims)}
|
||||
}
|
||||
|
||||
func (_c *UserBackend_CreateUserFromClaims_Call) Run(run func(ctx context.Context, claims map[string]interface{}, guest bool)) *UserBackend_CreateUserFromClaims_Call {
|
||||
func (_c *UserBackend_CreateUserFromClaims_Call) Run(run func(ctx context.Context, claims map[string]interface{})) *UserBackend_CreateUserFromClaims_Call {
|
||||
_c.Call.Run(func(args mock.Arguments) {
|
||||
run(args[0].(context.Context), args[1].(map[string]interface{}), args[2].(bool))
|
||||
run(args[0].(context.Context), args[1].(map[string]interface{}))
|
||||
})
|
||||
return _c
|
||||
}
|
||||
@@ -144,7 +143,7 @@ func (_c *UserBackend_CreateUserFromClaims_Call) Return(_a0 *userv1beta1.User, _
|
||||
return _c
|
||||
}
|
||||
|
||||
func (_c *UserBackend_CreateUserFromClaims_Call) RunAndReturn(run func(context.Context, map[string]interface{}, bool) (*userv1beta1.User, error)) *UserBackend_CreateUserFromClaims_Call {
|
||||
func (_c *UserBackend_CreateUserFromClaims_Call) RunAndReturn(run func(context.Context, map[string]interface{}) (*userv1beta1.User, error)) *UserBackend_CreateUserFromClaims_Call {
|
||||
_c.Call.Return(run)
|
||||
return _c
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user