MSP-7470 AuthModuleName -> AuthMethodBasePath & trim slash

This commit is contained in:
Синельник Тимур Романович committed 2026-04-06 09:26:04 +03:00
1 parent 23a4d94cff
commit 1b2b9c5817
3 files changed
+26 -26

No files matched your search

+5 -5
View File
@@ -92,9 +92,9 @@ type CookieTokenProvider struct {
}
type UserAuthSetting struct {
EndpointPrefixes []string `schema:"Префиксы пути,для которых настраивается аутентификация/авторизация" validate:"required"`
TokenProvider string `schema:"Название метода получения токена из запроса" validate:"required"`
AuthModuleName string `schema:"Название модуля для аутентификации/авторизации" validate:"required"`
CacheDataInSec int `schema:"Время кеширования данных авторизации пользователя,отключен при значениях <=0,в секундах"`
SkipAppAuth bool `schema:"Пропустить аутентификацию и авторизацию приложения"`
EndpointPrefixes []string `schema:"Префиксы пути,для которых настраивается аутентификация/авторизация" validate:"required"`
TokenProvider string `schema:"Название метода получения токена из запроса" validate:"required"`
AuthMethodBasePath string `schema:"Путь до метода аутентификации/авторизации,метод вызывается через isp-router-service" validate:"required"`
CacheDataInSec int `schema:"Время кеширования данных авторизации пользователя,отключен при значениях <=0,в секундах"`
SkipAppAuth bool `schema:"Пропустить аутентификацию и авторизацию приложения"`
}
+8 -8
View File
@@ -16,8 +16,8 @@ import (
)
type UserAuthenticationCache interface {
Get(ctx context.Context, authModuleName string, token string) (*entity.UserAuthData, error)
Set(ctx context.Context, authModuleName string, token string, data entity.UserAuthData, duration time.Duration) error
Get(ctx context.Context, authBasePath string, token string) (*entity.UserAuthData, error)
Set(ctx context.Context, authBasePath string, token string, data entity.UserAuthData, duration time.Duration) error
}
type UserAuthenticationRepo interface {
@@ -31,7 +31,7 @@ type TokenProvider interface {
type userAuthSetting struct {
tokenProvider string
endpointPrefix string
authModuleName string
authBasePath string
authCacheDuration time.Duration
skipAppAuth bool
}
@@ -82,7 +82,7 @@ func NewUserAuthentication(
for _, prefix := range setting.EndpointPrefixes {
endpointsSettings = append(endpointsSettings, userAuthSetting{
endpointPrefix: prefix,
authModuleName: setting.AuthModuleName,
authBasePath: strings.TrimPrefix(setting.AuthMethodBasePath, "/"),
tokenProvider: setting.TokenProvider,
skipAppAuth: setting.SkipAppAuth,
authCacheDuration: cacheDuration,
@@ -142,17 +142,17 @@ func (s UserAuthentication) authenticate(
token string,
) (*domain.AuthenticateUserResponse, error) {
if setting.authCacheDuration <= 0 {
resp, err := s.repo.Authenticate(ctx, setting.authModuleName, token)
resp, err := s.repo.Authenticate(ctx, setting.authBasePath, token)
if err != nil {
return nil, errors.WithMessage(err, "auth repo authenticate")
}
return s.convertAuthReponse(resp, setting.skipAppAuth), nil
}
authData, err := s.cache.Get(ctx, setting.authModuleName, token)
authData, err := s.cache.Get(ctx, setting.authBasePath, token)
switch {
case errors.Is(err, domain.ErrAuthenticationCacheMiss):
resp, err := s.repo.Authenticate(ctx, setting.authModuleName, token)
resp, err := s.repo.Authenticate(ctx, setting.authBasePath, token)
if err != nil {
return nil, errors.WithMessage(err, "auth repo authenticate")
}
@@ -161,7 +161,7 @@ func (s UserAuthentication) authenticate(
}
err = s.cache.Set(
ctx,
setting.authModuleName,
setting.authBasePath,
token,
*resp.AuthData,
setting.authCacheDuration,
+13 -13
View File
@@ -379,14 +379,14 @@ func (s *HappyPathTestSuite) TestUserAuthorization() { // nolint:funlen
},
UserAuthSettings: []conf.UserAuthSetting{
{
EndpointPrefixes: []string{"endpoint"},
TokenProvider: "test_provider",
AuthModuleName: "test-user-auth",
EndpointPrefixes: []string{"endpoint"},
TokenProvider: "test_provider",
AuthMethodBasePath: "test-user-auth",
},
{
EndpointPrefixes: []string{"failed_auth_endpoint"},
TokenProvider: "test_provider",
AuthModuleName: "failed-user-auth",
EndpointPrefixes: []string{"failed_auth_endpoint"},
TokenProvider: "test_provider",
AuthMethodBasePath: "failed-user-auth",
},
},
}
@@ -506,15 +506,15 @@ func (s *HappyPathTestSuite) TestUserAuthorization_SkipAppAuth() { // nolint:fun
},
UserAuthSettings: []conf.UserAuthSetting{
{
EndpointPrefixes: []string{"endpoint"},
TokenProvider: "test_provider",
AuthModuleName: "test-user-auth",
SkipAppAuth: true,
EndpointPrefixes: []string{"endpoint"},
TokenProvider: "test_provider",
AuthMethodBasePath: "test-user-auth",
SkipAppAuth: true,
},
{
EndpointPrefixes: []string{"failed_endpoint"},
TokenProvider: "test_provider",
AuthModuleName: "test-user-auth",
EndpointPrefixes: []string{"failed_endpoint"},
TokenProvider: "test_provider",
AuthMethodBasePath: "test-user-auth",
},
},
}