mirror of
https://github.com/grafana/grafana.git
synced 2024-11-30 12:44:10 -06:00
6c43eb0b4d
* Split Create User * Use new create user and User from package user * Add service to wire * Making create user work * Replace user from user pkg * One more * Move Insert to orguser Service/Store * Remove unnecessary conversion * Cleaunp * Fix Get User and add fakes * Fixing get org id for user logic, adding fakes and other adjustments * Add some tests for ourguser service and store * Fix insert org logic * Add comment about deprecation * Fix after merge with main * Move orguser service/store to org service/store * Remove orguser from wire * Unimplement new Create user and use User from pkg user * Fix wire generation * Fix lint * Fix lint - use only User and CrateUserCommand from user pkg * Remove User and CreateUserCommand from models * Fix lint 2
108 lines
4.4 KiB
Go
108 lines
4.4 KiB
Go
package auth
|
|
|
|
import (
|
|
"context"
|
|
"net"
|
|
|
|
"github.com/grafana/grafana/pkg/models"
|
|
"github.com/grafana/grafana/pkg/services/user"
|
|
)
|
|
|
|
type FakeUserAuthTokenService struct {
|
|
CreateTokenProvider func(ctx context.Context, user *user.User, clientIP net.IP, userAgent string) (*models.UserToken, error)
|
|
TryRotateTokenProvider func(ctx context.Context, token *models.UserToken, clientIP net.IP, userAgent string) (bool, error)
|
|
LookupTokenProvider func(ctx context.Context, unhashedToken string) (*models.UserToken, error)
|
|
RevokeTokenProvider func(ctx context.Context, token *models.UserToken, soft bool) error
|
|
RevokeAllUserTokensProvider func(ctx context.Context, userId int64) error
|
|
ActiveAuthTokenCount func(ctx context.Context) (int64, error)
|
|
GetUserTokenProvider func(ctx context.Context, userId, userTokenId int64) (*models.UserToken, error)
|
|
GetUserTokensProvider func(ctx context.Context, userId int64) ([]*models.UserToken, error)
|
|
GetUserRevokedTokensProvider func(ctx context.Context, userId int64) ([]*models.UserToken, error)
|
|
BatchRevokedTokenProvider func(ctx context.Context, userIds []int64) error
|
|
}
|
|
|
|
func NewFakeUserAuthTokenService() *FakeUserAuthTokenService {
|
|
return &FakeUserAuthTokenService{
|
|
CreateTokenProvider: func(ctx context.Context, user *user.User, clientIP net.IP, userAgent string) (*models.UserToken, error) {
|
|
return &models.UserToken{
|
|
UserId: 0,
|
|
UnhashedToken: "",
|
|
}, nil
|
|
},
|
|
TryRotateTokenProvider: func(ctx context.Context, token *models.UserToken, clientIP net.IP, userAgent string) (bool, error) {
|
|
return false, nil
|
|
},
|
|
LookupTokenProvider: func(ctx context.Context, unhashedToken string) (*models.UserToken, error) {
|
|
return &models.UserToken{
|
|
UserId: 0,
|
|
UnhashedToken: "",
|
|
}, nil
|
|
},
|
|
RevokeTokenProvider: func(ctx context.Context, token *models.UserToken, soft bool) error {
|
|
return nil
|
|
},
|
|
RevokeAllUserTokensProvider: func(ctx context.Context, userId int64) error {
|
|
return nil
|
|
},
|
|
BatchRevokedTokenProvider: func(ctx context.Context, userIds []int64) error {
|
|
return nil
|
|
},
|
|
ActiveAuthTokenCount: func(ctx context.Context) (int64, error) {
|
|
return 10, nil
|
|
},
|
|
GetUserTokenProvider: func(ctx context.Context, userId, userTokenId int64) (*models.UserToken, error) {
|
|
return nil, nil
|
|
},
|
|
GetUserTokensProvider: func(ctx context.Context, userId int64) ([]*models.UserToken, error) {
|
|
return nil, nil
|
|
},
|
|
}
|
|
}
|
|
|
|
// Init initializes the service.
|
|
// Required for dependency injection.
|
|
func (s *FakeUserAuthTokenService) Init() error {
|
|
return nil
|
|
}
|
|
|
|
func (s *FakeUserAuthTokenService) CreateToken(ctx context.Context, user *user.User, clientIP net.IP, userAgent string) (*models.UserToken, error) {
|
|
return s.CreateTokenProvider(context.Background(), user, clientIP, userAgent)
|
|
}
|
|
|
|
func (s *FakeUserAuthTokenService) LookupToken(ctx context.Context, unhashedToken string) (*models.UserToken, error) {
|
|
return s.LookupTokenProvider(context.Background(), unhashedToken)
|
|
}
|
|
|
|
func (s *FakeUserAuthTokenService) TryRotateToken(ctx context.Context, token *models.UserToken, clientIP net.IP,
|
|
userAgent string) (bool, error) {
|
|
return s.TryRotateTokenProvider(context.Background(), token, clientIP, userAgent)
|
|
}
|
|
|
|
func (s *FakeUserAuthTokenService) RevokeToken(ctx context.Context, token *models.UserToken, soft bool) error {
|
|
return s.RevokeTokenProvider(context.Background(), token, soft)
|
|
}
|
|
|
|
func (s *FakeUserAuthTokenService) RevokeAllUserTokens(ctx context.Context, userId int64) error {
|
|
return s.RevokeAllUserTokensProvider(context.Background(), userId)
|
|
}
|
|
|
|
func (s *FakeUserAuthTokenService) ActiveTokenCount(ctx context.Context) (int64, error) {
|
|
return s.ActiveAuthTokenCount(context.Background())
|
|
}
|
|
|
|
func (s *FakeUserAuthTokenService) GetUserToken(ctx context.Context, userId, userTokenId int64) (*models.UserToken, error) {
|
|
return s.GetUserTokenProvider(context.Background(), userId, userTokenId)
|
|
}
|
|
|
|
func (s *FakeUserAuthTokenService) GetUserTokens(ctx context.Context, userId int64) ([]*models.UserToken, error) {
|
|
return s.GetUserTokensProvider(context.Background(), userId)
|
|
}
|
|
|
|
func (s *FakeUserAuthTokenService) GetUserRevokedTokens(ctx context.Context, userId int64) ([]*models.UserToken, error) {
|
|
return s.GetUserRevokedTokensProvider(context.Background(), userId)
|
|
}
|
|
|
|
func (s *FakeUserAuthTokenService) BatchRevokeAllUserTokens(ctx context.Context, userIds []int64) error {
|
|
return s.BatchRevokedTokenProvider(ctx, userIds)
|
|
}
|