2026-02-11 16:48:41: merge [main:c304645d60621efc82700d4c7e501c49a2b2935b];
Create and publish a Docker image / build-and-push-image (push) Canceled after 0s
Create and publish a Docker image / build-and-push-image (push) Canceled after 0s
This commit is contained in:
1 parent
1651a1fc3c
commit
e4445eca46
24 files changed
+2709
-1608
No files matched your search
+32
-11
@@ -11,7 +11,7 @@ import (
|
||||
|
||||
type AccessListRepo interface {
|
||||
GetAccessListByAppId(ctx context.Context, appId int) ([]entity.AccessList, error)
|
||||
DeleteAccessList(ctx context.Context, appId int, methods []string) error
|
||||
DeleteAccessList(ctx context.Context, appId int, methods []entity.Method) error
|
||||
}
|
||||
|
||||
type AccessListSetOneTx interface {
|
||||
@@ -21,7 +21,7 @@ type AccessListSetOneTx interface {
|
||||
type AccessListSetListTx interface {
|
||||
GetAccessListByAppId(ctx context.Context, appId int) ([]entity.AccessList, error)
|
||||
InsertArrayAccessList(ctx context.Context, entity []entity.AccessList) error
|
||||
DeleteAccessList(ctx context.Context, appId int, methods []string) error
|
||||
DeleteAccessList(ctx context.Context, appId int, methods []entity.Method) error
|
||||
DeleteAccessListByAppId(ctx context.Context, appId int) ([]entity.AccessList, error)
|
||||
}
|
||||
|
||||
@@ -79,9 +79,10 @@ func (s AccessList) SetOne(ctx context.Context, request domain.AccessListSetOneR
|
||||
var resp int
|
||||
err = s.tx.AccessListSetOneTx(ctx, func(ctx context.Context, tx AccessListSetOneTx) error {
|
||||
resp, err = tx.UpsertAccessList(ctx, entity.AccessList{
|
||||
AppId: request.AppId,
|
||||
Method: request.Method,
|
||||
Value: request.Value,
|
||||
AppId: request.AppId,
|
||||
HttpMethod: request.HttpMethod,
|
||||
Method: request.Method,
|
||||
Value: request.Value,
|
||||
})
|
||||
if err != nil {
|
||||
return errors.WithMessage(err, "upsert access list")
|
||||
@@ -113,13 +114,17 @@ func (s AccessList) SetList(ctx context.Context, req domain.AccessListSetListReq
|
||||
}
|
||||
|
||||
newAccessList := make([]entity.AccessList, len(req.Methods))
|
||||
updateMethods := make([]string, len(req.Methods))
|
||||
updateMethods := make([]entity.Method, len(req.Methods))
|
||||
for i, m := range req.Methods {
|
||||
updateMethods[i] = m.Method
|
||||
updateMethods[i] = entity.Method{
|
||||
HttpMethod: m.HttpMethod,
|
||||
Method: m.Method,
|
||||
}
|
||||
newAccessList[i] = entity.AccessList{
|
||||
AppId: req.AppId,
|
||||
Method: m.Method,
|
||||
Value: m.Value,
|
||||
AppId: req.AppId,
|
||||
HttpMethod: m.HttpMethod,
|
||||
Method: m.Method,
|
||||
Value: m.Value,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -158,11 +163,27 @@ func (s AccessList) SetList(ctx context.Context, req domain.AccessListSetListReq
|
||||
}
|
||||
|
||||
func (s AccessList) DeleteList(ctx context.Context, req domain.AccessListDeleteListRequest) error {
|
||||
methods := make([]domain.Method, 0, len(req.Methods))
|
||||
for _, method := range req.Methods {
|
||||
methods = append(methods, domain.Method{Method: method})
|
||||
}
|
||||
return s.DeleteListWithMethods(ctx, domain.AccessListDeleteV2ListRequest{
|
||||
AppId: req.AppId,
|
||||
Methods: methods,
|
||||
})
|
||||
}
|
||||
|
||||
func (s AccessList) DeleteListWithMethods(ctx context.Context, req domain.AccessListDeleteV2ListRequest) error {
|
||||
_, err := s.appRepo.GetApplicationById(ctx, req.AppId)
|
||||
if err != nil {
|
||||
return errors.WithMessage(err, "get application by id")
|
||||
}
|
||||
err = s.accessListRepo.DeleteAccessList(ctx, req.AppId, req.Methods)
|
||||
|
||||
methods := make([]entity.Method, 0, len(req.Methods))
|
||||
for _, method := range req.Methods {
|
||||
methods = append(methods, entity.Method{Method: method.Method, HttpMethod: method.HttpMethod})
|
||||
}
|
||||
err = s.accessListRepo.DeleteAccessList(ctx, req.AppId, methods)
|
||||
if err != nil {
|
||||
return errors.WithMessage(err, "delete access_list")
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ type TokenRep interface {
|
||||
}
|
||||
|
||||
type AccessListRep interface {
|
||||
GetAccessListByAppIdAndMethod(ctx context.Context, appId int, method string) (*entity.AccessList, error)
|
||||
GetAccessListByAppIdAndMethod(ctx context.Context, appId int, httpMethod string, method string) (*entity.AccessList, error)
|
||||
}
|
||||
|
||||
type Service struct {
|
||||
@@ -53,8 +53,13 @@ func (s Service) Authenticate(ctx context.Context, token string) (*domain.AuthDa
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (s Service) Authorize(ctx context.Context, appId int, endpoint string) (bool, error) {
|
||||
accessList, err := s.accessListRep.GetAccessListByAppIdAndMethod(ctx, appId, endpoint)
|
||||
func (s Service) Authorize(ctx context.Context, req domain.AuthorizeRequest) (bool, error) {
|
||||
accessList, err := s.accessListRep.GetAccessListByAppIdAndMethod(
|
||||
ctx,
|
||||
req.ApplicationId,
|
||||
req.HttpMethod,
|
||||
req.Endpoint,
|
||||
)
|
||||
if err != nil {
|
||||
return false, errors.WithMessage(err, "get access list by app_id and method")
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user