Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d8c91f3f72 | ||
|
|
b819687470 | ||
|
|
dbdae4ed47 |
No files matched your search
+10
-1
@@ -20,11 +20,17 @@ linters:
|
||||
- wsl_v5 # расставление пробелов очень индивидуально
|
||||
- godoclint # ругается на // nolint, не удобно
|
||||
- prealloc # слишком аггресивный, в большинстве случаев не требуется
|
||||
- gomodguard # deprecated
|
||||
settings:
|
||||
exhaustruct_v5:
|
||||
allow-empty: true
|
||||
explicit-mode: true
|
||||
cyclop:
|
||||
max-complexity: 15 # по умолчанию 10 мало
|
||||
funlen:
|
||||
lines: 80
|
||||
goconst:
|
||||
ignore-tests: true # тестовые фикстуры не выносим в константы
|
||||
lll:
|
||||
line-length: 150
|
||||
revive:
|
||||
@@ -60,6 +66,9 @@ linters:
|
||||
- unqueryvet
|
||||
- prealloc
|
||||
path: ".*_test\\.go$"
|
||||
- linters:
|
||||
- goconst
|
||||
path: "tests/" # компонентные тесты: фикстуры и моки не выносим в константы
|
||||
paths:
|
||||
- third_party$
|
||||
- builtin$
|
||||
@@ -72,4 +81,4 @@ formatters:
|
||||
paths:
|
||||
- third_party$
|
||||
- builtin$
|
||||
- examples$
|
||||
- examples$
|
||||
@@ -1,6 +1,6 @@
|
||||
module isp-admin-service
|
||||
|
||||
go 1.26.0
|
||||
go 1.27
|
||||
|
||||
require (
|
||||
github.com/Masterminds/squirrel v1.5.4
|
||||
@@ -8,7 +8,7 @@ require (
|
||||
github.com/iancoleman/strcase v0.3.0
|
||||
github.com/stretchr/testify v1.12.1
|
||||
github.com/txix-open/bgjob v1.6.0
|
||||
github.com/txix-open/isp-kit v1.74.1
|
||||
github.com/txix-open/isp-kit v1.75.0
|
||||
github.com/txix-open/jsonschema v1.3.0
|
||||
golang.org/x/crypto v0.55.0
|
||||
golang.org/x/sync v0.22.0
|
||||
|
||||
@@ -153,8 +153,8 @@ github.com/txix-open/etp/v4 v4.1.3 h1:u9ZyU2yKGgoQ1/DSaElhazWm8xASdqGEdWjoJ2xQlf
|
||||
github.com/txix-open/etp/v4 v4.1.3/go.mod h1:9GK+Aje8BmLFq8Hk4j6Qb976LdU9WECCWAuLK1vAKgM=
|
||||
github.com/txix-open/grmq v1.12.0 h1:lSPYvwLfTL0+b0xDQmuuN6RaKS3NCEJNK9ccWpOWa8Y=
|
||||
github.com/txix-open/grmq v1.12.0/go.mod h1:6m9CCTQao/HAFalu5rFOZGJ5KLEP6WzzIwj80Ml3KGE=
|
||||
github.com/txix-open/isp-kit v1.74.1 h1:2WQl1+e6E1TXcgkm554kYpiyORgZiyJa/zQIks4cUCw=
|
||||
github.com/txix-open/isp-kit v1.74.1/go.mod h1:i4g+hgfVQAXa02kHqr104TqYEsiW2em17RZF0KjkB78=
|
||||
github.com/txix-open/isp-kit v1.75.0 h1:0/qJoDTyjsVkQTCsQ7FAilKo7a5Y5pDI4tfMXloHYCg=
|
||||
github.com/txix-open/isp-kit v1.75.0/go.mod h1:LEBYertzXLJ3gSuxjeJTUcSGLtf28PZWDHFH9lccCHk=
|
||||
github.com/txix-open/jsonschema v1.3.0 h1:XGuOTg22G7PdqfKypjajM20/i5FyGfFYsJKmheebKi4=
|
||||
github.com/txix-open/jsonschema v1.3.0/go.mod h1:l8YDZ1nvJrw6uxWowSVOxCV/ebiMJyapffW87ZEqH00=
|
||||
github.com/txix-open/validator/v10 v10.0.0-20250506161033-f8ce404fffdb h1:UJgT4u/QMv5QHKOQeJ7igShHa36c2/vIRqJiRLdDlf0=
|
||||
|
||||
@@ -21,7 +21,7 @@ var version = "1.0.0"
|
||||
// @host localhost:9000
|
||||
// @BasePath /api/admin
|
||||
|
||||
//go:generate swag init -pd -ot json -eot json
|
||||
//go:generate swag init -pd -ot json
|
||||
func main() {
|
||||
boot := bootstrap.New(version, conf.Remote{}, cluster.Endpoints(routes.EndpointDescriptors()), cluster.GrpcTransport)
|
||||
app := boot.App
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
-- +goose Up
|
||||
INSERT INTO roles (name, permissions, external_group, immutable, exclusive, created_at, updated_at)
|
||||
VALUES ('DIT_KKD_TECH_ADMIN_PROD',
|
||||
'["profile_view", "profile_change_password", "application_group_view", "application_group_add", "application_group_edit", "application_group_delete", "application_group_app_add", "application_group_app_edit", "application_group_app_delete", "application_group_token_view", "application_group_token_add", "application_group_token_delete", "app_access_view", "app_access_edit", "variable_view", "variable_add", "variable_edit", "variable_delete", "module_view", "module_delete", "module_configuration_save_unsafe", "module_configuration_set_active", "module_history_set", "module_history_delete_version", "module_configuration_edit", "module_configuration_add"]'::jsonb,
|
||||
'cn=sudir_prod_int_kkd_tech_admin,cn=groups,cn=accounts,dc=data,dc=corp', true, true, NOW(), NOW())
|
||||
ON CONFLICT (name) DO UPDATE
|
||||
SET permissions = EXCLUDED.permissions;
|
||||
|
||||
INSERT INTO roles (name, permissions, external_group, immutable, exclusive, created_at, updated_at)
|
||||
VALUES ('DIT_KKD_TECH_ADMIN_STAGE',
|
||||
'["profile_view", "profile_change_password", "application_group_view", "application_group_add", "application_group_edit", "application_group_delete", "application_group_app_add", "application_group_app_edit", "application_group_app_delete", "application_group_token_view", "application_group_token_add", "application_group_token_delete", "app_access_view", "app_access_edit", "variable_view", "variable_add", "variable_edit", "variable_delete", "module_view", "module_delete", "module_configuration_save_unsafe", "module_configuration_set_active", "module_history_set", "module_history_delete_version", "module_configuration_edit", "module_configuration_add"]'::jsonb,
|
||||
'cn=sudir_stage_int_kkd_tech_admin,cn=groups,cn=accounts,dc=data,dc=corp', true, true, NOW(), NOW())
|
||||
ON CONFLICT (name) DO UPDATE
|
||||
SET permissions = EXCLUDED.permissions;
|
||||
|
||||
INSERT INTO roles (name, permissions, external_group, immutable, exclusive, created_at, updated_at)
|
||||
VALUES ('DIT_KKD_TECH_ADMIN_IB_PROD',
|
||||
'["session_view", "user_view", "user_block", "user_create", "user_update", "user_delete", "session_revoke", "session_delete", "security_log_view", "profile_view", "profile_edit", "role_view", "role_add", "role_update", "role_delete", "role_link_user", "role_link_external_group", "supervisor_view"]'::jsonb,
|
||||
'cn=sudir_prod_int_kkd_tech_admin_ib,cn=groups,cn=accounts,dc=data,dc=corp', true, true, NOW(), NOW())
|
||||
ON CONFLICT (name) DO UPDATE
|
||||
SET permissions = EXCLUDED.permissions;
|
||||
|
||||
INSERT INTO roles (name, permissions, external_group, immutable, exclusive, created_at, updated_at)
|
||||
VALUES ('DIT_KKD_TECH_ADMIN_IB_STAGE',
|
||||
'["session_view", "user_view", "user_block", "user_create", "user_update", "user_delete", "session_revoke", "session_delete", "security_log_view", "profile_view", "profile_edit", "role_view", "role_add", "role_update", "role_delete", "role_link_user", "role_link_external_group", "supervisor_view"]'::jsonb,
|
||||
'cn=sudir_stage_int_kkd_tech_admin_ib,cn=groups,cn=accounts,dc=data,dc=corp', true, true, NOW(), NOW())
|
||||
ON CONFLICT (name) DO UPDATE
|
||||
SET permissions = EXCLUDED.permissions;
|
||||
|
||||
INSERT INTO roles (name, permissions, external_group, immutable, exclusive, created_at, updated_at)
|
||||
VALUES ('DIT_KKD_TECH_ADMIN_READ_ONLY_PROD',
|
||||
'["profile_view", "application_group_view", "application_group_token_view", "app_access_view", "module_view"]'::jsonb,
|
||||
'cn=sudir_prod_int_kkd_tech_operator_ro,cn=groups,cn=accounts,dc=data,dc=corp', true, true, NOW(), NOW())
|
||||
ON CONFLICT (name) DO UPDATE
|
||||
SET permissions = EXCLUDED.permissions;
|
||||
|
||||
INSERT INTO roles (name, permissions, external_group, immutable, exclusive, created_at, updated_at)
|
||||
VALUES ('DIT_KKD_TECH_ADMIN_READ_ONLY_STAGE',
|
||||
'["profile_view", "application_group_view", "application_group_token_view", "app_access_view", "module_view"]'::jsonb,
|
||||
'cn=sudir_stage_int_kkd_tech_operator_ro,cn=groups,cn=accounts,dc=data,dc=corp', true, true, NOW(), NOW())
|
||||
ON CONFLICT (name) DO UPDATE
|
||||
SET permissions = EXCLUDED.permissions;
|
||||
|
||||
-- +goose Down
|
||||
+4
-4
@@ -38,7 +38,7 @@ func (r Audit) Insert(ctx context.Context, log entity.Audit) (int, error) {
|
||||
|
||||
query, args, err := query.New().
|
||||
Insert("audit").
|
||||
Columns("user_id", "message", "event", "created_at").
|
||||
Columns(userIdAuditColumn, "message", "event", createdAtAuditColumn).
|
||||
Values(log.UserId, log.Message, log.Event, log.CreatedAt).
|
||||
Suffix("returning id").
|
||||
ToSql()
|
||||
@@ -134,7 +134,7 @@ func reqAuditQuery(q squirrel.SelectBuilder, reqQuery *domain.AuditQuery) squirr
|
||||
}
|
||||
|
||||
if reqQuery.UserId != nil {
|
||||
q = q.Where(squirrel.Eq{"user_id": reqQuery.UserId})
|
||||
q = q.Where(squirrel.Eq{userIdAuditColumn: reqQuery.UserId})
|
||||
}
|
||||
|
||||
if reqQuery.Message != nil {
|
||||
@@ -142,8 +142,8 @@ func reqAuditQuery(q squirrel.SelectBuilder, reqQuery *domain.AuditQuery) squirr
|
||||
}
|
||||
|
||||
if reqQuery.CreatedAt != nil {
|
||||
q = q.Where(squirrel.GtOrEq{"created_at": reqQuery.CreatedAt.From}).
|
||||
Where(squirrel.Lt{"created_at": reqQuery.CreatedAt.To})
|
||||
q = q.Where(squirrel.GtOrEq{createdAtAuditColumn: reqQuery.CreatedAt.From}).
|
||||
Where(squirrel.Lt{createdAtAuditColumn: reqQuery.CreatedAt.To})
|
||||
}
|
||||
|
||||
return q
|
||||
|
||||
+6
-6
@@ -205,10 +205,10 @@ func (r Token) LastAccessByUserIds(ctx context.Context, userIds []int) (map[int6
|
||||
ctx = sql_metrics.OperationLabelToContext(ctx, "Token.LastAccessByUserIds")
|
||||
|
||||
query, args, err := query.New().
|
||||
Select("user_id", "max(created_at) as created_at").
|
||||
Select(userIdTokensColumn, "max(created_at) as created_at").
|
||||
From("tokens").
|
||||
Where(squirrel.Eq{"user_id": userIds}).
|
||||
GroupBy("user_id").
|
||||
Where(squirrel.Eq{userIdTokensColumn: userIds}).
|
||||
GroupBy(userIdTokensColumn).
|
||||
ToSql()
|
||||
if err != nil {
|
||||
return nil, errors.WithMessage(err, "build query")
|
||||
@@ -238,7 +238,7 @@ func reqTokenQuery(q squirrel.SelectBuilder, reqQuery *domain.SessionQuery) squi
|
||||
}
|
||||
|
||||
if reqQuery.UserId != nil {
|
||||
q = q.Where(squirrel.Eq{"user_id": reqQuery.UserId})
|
||||
q = q.Where(squirrel.Eq{userIdTokensColumn: reqQuery.UserId})
|
||||
}
|
||||
|
||||
if reqQuery.Status != nil {
|
||||
@@ -246,8 +246,8 @@ func reqTokenQuery(q squirrel.SelectBuilder, reqQuery *domain.SessionQuery) squi
|
||||
}
|
||||
|
||||
if reqQuery.CreatedAt != nil {
|
||||
q = q.Where(squirrel.GtOrEq{"created_at": reqQuery.CreatedAt.From}).
|
||||
Where(squirrel.Lt{"created_at": reqQuery.CreatedAt.To})
|
||||
q = q.Where(squirrel.GtOrEq{createdAtTokensColumn: reqQuery.CreatedAt.From}).
|
||||
Where(squirrel.Lt{createdAtTokensColumn: reqQuery.CreatedAt.To})
|
||||
}
|
||||
|
||||
if reqQuery.ExpiredAt != nil {
|
||||
|
||||
+2
-2
@@ -48,7 +48,7 @@ func (u User) GetUserByEmail(ctx context.Context, email string) (*entity.User, e
|
||||
updatedAtUsersColumn, oauthUserIdUsersColumn, blockedUsersColumn, descriptionUsersColumn, lastActiveAtUsersColumn,
|
||||
fullNameUsersColumn).
|
||||
From("users").
|
||||
Where(squirrel.Eq{"email": email}).
|
||||
Where(squirrel.Eq{emailUsersColumn: email}).
|
||||
ToSql()
|
||||
if err != nil {
|
||||
return nil, errors.WithMessage(err, "build query")
|
||||
@@ -217,7 +217,7 @@ func (u User) GetUsersByEmail(ctx context.Context, email string) ([]entity.User,
|
||||
updatedAtUsersColumn, oauthUserIdUsersColumn, blockedUsersColumn, descriptionUsersColumn, lastActiveAtUsersColumn,
|
||||
fullNameUsersColumn).
|
||||
From("users").
|
||||
Where(squirrel.Eq{"email": email}).
|
||||
Where(squirrel.Eq{emailUsersColumn: email}).
|
||||
ToSql()
|
||||
if err != nil {
|
||||
return nil, errors.WithMessage(err, "build query")
|
||||
|
||||
@@ -12,6 +12,10 @@ import (
|
||||
"github.com/txix-open/isp-kit/metrics/sql_metrics"
|
||||
)
|
||||
|
||||
const (
|
||||
userIdUserRolesColumn = "user_id"
|
||||
)
|
||||
|
||||
type UserRole struct {
|
||||
db db.DB
|
||||
}
|
||||
@@ -23,8 +27,8 @@ func NewUserRole(db db.DB) UserRole {
|
||||
func (u UserRole) GetRolesByUserIds(ctx context.Context, identity []int) ([]entity.UserRole, error) {
|
||||
ctx = sql_metrics.OperationLabelToContext(ctx, "UserRole.GetRolesByUserIds")
|
||||
|
||||
rolesQ, args, err := query.New().Select("role_id", "user_id").
|
||||
From("user_roles").Where(squirrel.Eq{"user_id": identity}).ToSql()
|
||||
rolesQ, args, err := query.New().Select("role_id", userIdUserRolesColumn).
|
||||
From("user_roles").Where(squirrel.Eq{userIdUserRolesColumn: identity}).ToSql()
|
||||
if err != nil {
|
||||
return nil, errors.WithMessage(err, "build query")
|
||||
}
|
||||
@@ -67,7 +71,7 @@ func (u UserRole) UpsertUserRoleLinks(ctx context.Context, id int, roleIds []int
|
||||
ctx = sql_metrics.OperationLabelToContext(ctx, "UserRole.UpsertUserRoleLinks")
|
||||
|
||||
deleteQ, args, err := query.New().
|
||||
Delete("user_roles").Where(squirrel.Eq{"user_id": id}).ToSql()
|
||||
Delete("user_roles").Where(squirrel.Eq{userIdUserRolesColumn: id}).ToSql()
|
||||
if err != nil {
|
||||
return errors.WithMessage(err, "build query")
|
||||
}
|
||||
@@ -83,7 +87,7 @@ func (u UserRole) UpsertUserRoleLinks(ctx context.Context, id int, roleIds []int
|
||||
|
||||
rolesQ := query.New().
|
||||
Insert("user_roles").
|
||||
Columns("user_id", "role_id")
|
||||
Columns(userIdUserRolesColumn, "role_id")
|
||||
for _, roleId := range roleIds {
|
||||
rolesQ = rolesQ.Values(id, roleId)
|
||||
}
|
||||
|
||||
+18
-12
@@ -11,6 +11,12 @@ import (
|
||||
"github.com/txix-open/isp-kit/errors"
|
||||
)
|
||||
|
||||
const (
|
||||
roleNameLabel = "Название"
|
||||
roleGroupLabel = "Группа ЕСК"
|
||||
rolePermissionsLabel = "Разрешения"
|
||||
)
|
||||
|
||||
type roleRoleRepo interface {
|
||||
All(ctx context.Context) ([]entity.Role, error)
|
||||
InsertRole(ctx context.Context, role entity.Role) (*entity.Role, error)
|
||||
@@ -69,13 +75,13 @@ func (u Role) Create(ctx context.Context, req domain.CreateRoleRequest, adminId
|
||||
|
||||
slices.Sort(role.Permissions)
|
||||
diff := diffToString(map[string]any{
|
||||
"Название": "",
|
||||
"Группа ЕСК": "",
|
||||
"Разрешения": []int{},
|
||||
roleNameLabel: "",
|
||||
roleGroupLabel: "",
|
||||
rolePermissionsLabel: []int{},
|
||||
}, map[string]any{
|
||||
"Название": role.Name,
|
||||
"Группа ЕСК": role.ExternalGroup,
|
||||
"Разрешения": role.Permissions,
|
||||
roleNameLabel: role.Name,
|
||||
roleGroupLabel: role.ExternalGroup,
|
||||
rolePermissionsLabel: role.Permissions,
|
||||
})
|
||||
u.auditService.SaveAuditAsync(ctx, adminId,
|
||||
fmt.Sprintf("Роль. Создание новой роли %s. Причина: %s. \n %s", req.Name, req.ChangeMessage, diff),
|
||||
@@ -119,13 +125,13 @@ func (u Role) Update(ctx context.Context, req domain.UpdateRoleRequest, adminId
|
||||
slices.Sort(oldRole.Permissions)
|
||||
slices.Sort(role.Permissions)
|
||||
diff := diffToString(map[string]any{
|
||||
"Название": oldRole.Name,
|
||||
"Группа ЕСК": oldRole.ExternalGroup,
|
||||
"Разрешения": oldRole.Permissions,
|
||||
roleNameLabel: oldRole.Name,
|
||||
roleGroupLabel: oldRole.ExternalGroup,
|
||||
rolePermissionsLabel: oldRole.Permissions,
|
||||
}, map[string]any{
|
||||
"Название": role.Name,
|
||||
"Группа ЕСК": role.ExternalGroup,
|
||||
"Разрешения": role.Permissions,
|
||||
roleNameLabel: role.Name,
|
||||
roleGroupLabel: role.ExternalGroup,
|
||||
rolePermissionsLabel: role.Permissions,
|
||||
})
|
||||
u.auditService.SaveAuditAsync(ctx, adminId,
|
||||
fmt.Sprintf("Роль. Изменение роли %s. Причина: %s. \n %s", req.Name, req.ChangeMessage, diff),
|
||||
|
||||
+23
-16
@@ -16,6 +16,13 @@ import (
|
||||
"golang.org/x/crypto/bcrypt"
|
||||
)
|
||||
|
||||
const (
|
||||
userFullNameLabel = "ФИО"
|
||||
userDescriptionLabel = "Описание"
|
||||
userEmailLabel = "Email"
|
||||
userRolesLabel = "Роли (ID)"
|
||||
)
|
||||
|
||||
type UserTransaction interface {
|
||||
UserRepo
|
||||
UserRoleRepo
|
||||
@@ -253,15 +260,15 @@ func (u User) CreateUser(ctx context.Context, req domain.CreateUserRequest, admi
|
||||
|
||||
slices.Sort(req.Roles)
|
||||
diff := diffToString(map[string]any{
|
||||
"ФИО": "",
|
||||
"Описание": "",
|
||||
"Email": "",
|
||||
"Роли (ID)": []int{},
|
||||
userFullNameLabel: "",
|
||||
userDescriptionLabel: "",
|
||||
userEmailLabel: "",
|
||||
userRolesLabel: []int{},
|
||||
}, map[string]any{
|
||||
"ФИО": usr.FullName,
|
||||
"Описание": req.Description,
|
||||
"Email": req.Email,
|
||||
"Роли (ID)": req.Roles,
|
||||
userFullNameLabel: usr.FullName,
|
||||
userDescriptionLabel: req.Description,
|
||||
userEmailLabel: req.Email,
|
||||
userRolesLabel: req.Roles,
|
||||
})
|
||||
u.auditService.SaveAuditAsync(ctx, adminId,
|
||||
fmt.Sprintf("Пользователь. Создание пользователя %d. \n %s", usr.Id, diff),
|
||||
@@ -342,15 +349,15 @@ func (u User) UpdateUser(ctx context.Context, req domain.UpdateUserRequest, admi
|
||||
|
||||
slices.Sort(req.Roles)
|
||||
diff := diffToString(map[string]any{
|
||||
"ФИО": user.FullName,
|
||||
"Описание": user.Description,
|
||||
"Email": user.Email,
|
||||
"Роли (ID)": RolesIds(oldRoles),
|
||||
userFullNameLabel: user.FullName,
|
||||
userDescriptionLabel: user.Description,
|
||||
userEmailLabel: user.Email,
|
||||
userRolesLabel: RolesIds(oldRoles),
|
||||
}, map[string]any{
|
||||
"ФИО": updatedUser.FullName,
|
||||
"Описание": req.Description,
|
||||
"Email": req.Email,
|
||||
"Роли (ID)": req.Roles,
|
||||
userFullNameLabel: updatedUser.FullName,
|
||||
userDescriptionLabel: req.Description,
|
||||
userEmailLabel: req.Email,
|
||||
userRolesLabel: req.Roles,
|
||||
})
|
||||
u.auditService.SaveAuditAsync(ctx, adminId,
|
||||
fmt.Sprintf("Пользователь. Изменение пользователя %d.\n %s", updatedUser.Id, diff),
|
||||
|
||||
+1
-1
@@ -183,7 +183,7 @@ func (s *AuditSuite) Test_SetEvents_InvalidEvent() {
|
||||
|
||||
func (s *AuditSuite) Test_All_Logs() {
|
||||
request := domain.AuditPageRequest{
|
||||
LimitOffestParams: domain.LimitOffestParams{
|
||||
LimitOffestParams: domain.LimitOffestParams{ //nolint:modernize
|
||||
Limit: 3,
|
||||
Offset: 5,
|
||||
},
|
||||
|
||||
+1
-1
@@ -241,7 +241,7 @@ func (s *AuthTestSuite) Test_Logout_NotFound() {
|
||||
time.Sleep(time.Second)
|
||||
audit := repository.NewAudit(s.db)
|
||||
auditList, err := audit.AllByRequest(s.T().Context(), domain.AuditPageRequest{
|
||||
LimitOffestParams: domain.LimitOffestParams{
|
||||
LimitOffestParams: domain.LimitOffestParams{ //nolint:modernize
|
||||
Limit: 10,
|
||||
Offset: 0,
|
||||
},
|
||||
|
||||
@@ -49,7 +49,7 @@ func TestInactiveWorker(t *testing.T) {
|
||||
require.True(user.Blocked)
|
||||
|
||||
list, err := repository.NewAudit(db).AllByRequest(t.Context(), domain.AuditPageRequest{
|
||||
LimitOffestParams: domain.LimitOffestParams{
|
||||
LimitOffestParams: domain.LimitOffestParams{ //nolint:modernize
|
||||
Limit: 10,
|
||||
Offset: 0,
|
||||
},
|
||||
|
||||
@@ -117,7 +117,7 @@ func (s *SessionSuite) Test_All_Session() {
|
||||
|
||||
// Дефолт сортировка, лимит и оффсет
|
||||
request := domain.SessionPageRequest{
|
||||
LimitOffestParams: domain.LimitOffestParams{
|
||||
LimitOffestParams: domain.LimitOffestParams{ //nolint:modernize
|
||||
Limit: 5,
|
||||
Offset: 1,
|
||||
},
|
||||
@@ -208,7 +208,7 @@ func (s *SessionSuite) Test_All_Session() {
|
||||
}
|
||||
|
||||
request = domain.SessionPageRequest{
|
||||
LimitOffestParams: domain.LimitOffestParams{
|
||||
LimitOffestParams: domain.LimitOffestParams{ //nolint:modernize
|
||||
Limit: 5,
|
||||
Offset: 0,
|
||||
},
|
||||
|
||||
+4
-4
@@ -186,7 +186,7 @@ func (s *UserTestSuite) TestGetUsers() {
|
||||
response := domain.UsersResponse{}
|
||||
err := s.grpcCli.Invoke("admin/user/get_users").
|
||||
JsonRequestBody(domain.UsersPageRequest{
|
||||
LimitOffestParams: domain.LimitOffestParams{
|
||||
LimitOffestParams: domain.LimitOffestParams{ //nolint:modernize
|
||||
Limit: 5,
|
||||
Offset: 1,
|
||||
},
|
||||
@@ -214,7 +214,7 @@ func (s *UserTestSuite) TestGetUsers() {
|
||||
email = "test@mail.ru"
|
||||
err = s.grpcCli.Invoke("admin/user/get_users").
|
||||
JsonRequestBody(domain.UsersPageRequest{
|
||||
LimitOffestParams: domain.LimitOffestParams{
|
||||
LimitOffestParams: domain.LimitOffestParams{ //nolint:modernize
|
||||
Limit: 10,
|
||||
Offset: 0,
|
||||
},
|
||||
@@ -298,7 +298,7 @@ func (s *UserTestSuite) TestGetUsersFilterByLastActiveAt() {
|
||||
response := domain.UsersResponse{}
|
||||
err = s.grpcCli.Invoke("admin/user/get_users").
|
||||
JsonRequestBody(domain.UsersPageRequest{
|
||||
LimitOffestParams: domain.LimitOffestParams{
|
||||
LimitOffestParams: domain.LimitOffestParams{ //nolint:modernize
|
||||
Limit: 5,
|
||||
Offset: 0,
|
||||
},
|
||||
@@ -334,7 +334,7 @@ func (s *UserTestSuite) TestGetUsersSortByName() {
|
||||
response := domain.UsersResponse{}
|
||||
err := s.grpcCli.Invoke("admin/user/get_users").
|
||||
JsonRequestBody(domain.UsersPageRequest{
|
||||
LimitOffestParams: domain.LimitOffestParams{
|
||||
LimitOffestParams: domain.LimitOffestParams{ //nolint:modernize
|
||||
Limit: 10,
|
||||
Offset: 0,
|
||||
},
|
||||
|
||||
+3
-2
@@ -2,6 +2,7 @@ package handler
|
||||
|
||||
import (
|
||||
"context"
|
||||
"slices"
|
||||
|
||||
"github.com/txix-open/bgjob"
|
||||
)
|
||||
@@ -38,8 +39,8 @@ type Sync struct {
|
||||
// will be the outermost wrapper.
|
||||
func NewSync(adapter SyncHandlerAdapter, middlewares ...Middleware) Sync {
|
||||
s := Sync{}
|
||||
for i := len(middlewares) - 1; i >= 0; i-- {
|
||||
adapter = middlewares[i](adapter)
|
||||
for _, middleware := range slices.Backward(middlewares) {
|
||||
adapter = middleware(adapter)
|
||||
}
|
||||
s.handler = adapter
|
||||
return s
|
||||
|
||||
+3
-2
@@ -7,6 +7,7 @@ package client
|
||||
|
||||
import (
|
||||
"context"
|
||||
"slices"
|
||||
"strings"
|
||||
"sync/atomic"
|
||||
|
||||
@@ -96,8 +97,8 @@ func New(initialHosts []string, opts ...Option) (*Client, error) {
|
||||
cli.grpcCli = grpcCli
|
||||
|
||||
roundTripper := cli.do
|
||||
for i := len(cli.middlewares) - 1; i >= 0; i-- {
|
||||
roundTripper = cli.middlewares[i](roundTripper)
|
||||
for _, v := range slices.Backward(cli.middlewares) {
|
||||
roundTripper = v(roundTripper)
|
||||
}
|
||||
cli.roundTripper = roundTripper
|
||||
|
||||
|
||||
+3
-2
@@ -8,6 +8,7 @@ import (
|
||||
"net"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"slices"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@@ -289,8 +290,8 @@ func defaultTransportDialContext(dialer *net.Dialer) func(context.Context, strin
|
||||
// nolint:ireturn
|
||||
func joinMiddlewares(root RoundTripper, mws ...Middleware) RoundTripper {
|
||||
roundTripper := root
|
||||
for i := len(mws) - 1; i >= 0; i-- {
|
||||
roundTripper = mws[i](roundTripper)
|
||||
for _, mw := range slices.Backward(mws) {
|
||||
roundTripper = mw(roundTripper)
|
||||
}
|
||||
return roundTripper
|
||||
}
|
||||
+1
-1
@@ -27,7 +27,7 @@ func LogLevelForError(err error) log.Level {
|
||||
// It uses LogLevelForError to determine the log level and returns the corresponding Logger method.
|
||||
func LogLevelFuncForError(err error, logger log.Logger) func(ctx context.Context, message any, fields ...log.Field) {
|
||||
logLevel := LogLevelForError(err)
|
||||
switch logLevel {
|
||||
switch logLevel { //nolint:exhaustive
|
||||
case log.ErrorLevel:
|
||||
return logger.Error
|
||||
case log.WarnLevel:
|
||||
|
||||
-5
@@ -8,14 +8,9 @@
|
||||
|
||||
Проверяет, что удалённая конфигурация соответствует сгенерированной JSON-схеме и проходит валидацию.
|
||||
|
||||
* Проверяет отсутствие устаревшего тега `valid`
|
||||
* Проверяет соответствие структуры JSON-схеме
|
||||
* Выполняет валидацию значений с помощью `validator.Default`
|
||||
|
||||
### `FindTag[T any](v T, tag string) bool`
|
||||
|
||||
Рекурсивно проверяет, содержит ли структура тег с указанным именем.
|
||||
|
||||
## Usage
|
||||
|
||||
### Example usage in test
|
||||
|
||||
-36
@@ -5,7 +5,6 @@ package rct
|
||||
|
||||
import (
|
||||
"os"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
@@ -21,7 +20,6 @@ import (
|
||||
// validator tag validation.
|
||||
//
|
||||
// The function checks:
|
||||
// - No deprecated 'valid' tags are present
|
||||
// - The default configuration file is valid against the generated schema
|
||||
// - The configuration can be unmarshaled from the file
|
||||
// - The configuration passes validation
|
||||
@@ -30,9 +28,6 @@ import (
|
||||
func Test[T any](t *testing.T, defaultRemoteConfigPath string, remoteConfig T) {
|
||||
require := require.New(t)
|
||||
|
||||
validatorTag := "valid"
|
||||
require.Falsef(FindTag(remoteConfig, validatorTag), "'%s' tag is not longer supported, you must use https://github.com/go-playground/validator", validatorTag)
|
||||
|
||||
defaultRemoteConfig, err := os.ReadFile(defaultRemoteConfigPath)
|
||||
require.NoError(err)
|
||||
|
||||
@@ -58,34 +53,3 @@ func Test[T any](t *testing.T, defaultRemoteConfigPath string, remoteConfig T) {
|
||||
err = validator.Default.ValidateToError(remoteConfig)
|
||||
require.NoError(err)
|
||||
}
|
||||
|
||||
// FindTag recursively searches a type for the specified struct tag.
|
||||
// It traverses structs, maps, arrays, and slices to find any field
|
||||
// that has the given tag. Returns true if the tag is found.
|
||||
func FindTag[T any](v T, tag string) bool {
|
||||
t := reflect.TypeOf(v)
|
||||
if t == nil {
|
||||
return false
|
||||
}
|
||||
queue := []reflect.Type{t}
|
||||
for len(queue) > 0 {
|
||||
cur := queue[0]
|
||||
queue = queue[1:]
|
||||
if cur.Kind() == reflect.Ptr {
|
||||
cur = cur.Elem()
|
||||
}
|
||||
// nolint:exhaustive
|
||||
switch cur.Kind() {
|
||||
case reflect.Struct:
|
||||
for field := range cur.Fields() {
|
||||
if field.Tag.Get(tag) != "" {
|
||||
return true
|
||||
}
|
||||
queue = append(queue, field.Type)
|
||||
}
|
||||
case reflect.Map, reflect.Array, reflect.Slice:
|
||||
queue = append(queue, cur.Elem())
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
Vendored
+2
-2
@@ -213,8 +213,8 @@ github.com/txix-open/etp/v4/bpool
|
||||
github.com/txix-open/etp/v4/internal
|
||||
github.com/txix-open/etp/v4/msg
|
||||
github.com/txix-open/etp/v4/store
|
||||
# github.com/txix-open/isp-kit v1.74.1
|
||||
## explicit; go 1.26.0
|
||||
# github.com/txix-open/isp-kit v1.75.0
|
||||
## explicit; go 1.27
|
||||
github.com/txix-open/isp-kit/app
|
||||
github.com/txix-open/isp-kit/bgjobx
|
||||
github.com/txix-open/isp-kit/bgjobx/handler
|
||||
|
||||
Reference in new issue
Block a user