2026-01-27 13:25:45: merge [main:e5e723811e7a9dc57a6ff5d1c067c07c23a97210];
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
6a3abf67a2
commit
602a2a1ac4
24 files changed
+222
-114
No files matched your search
@@ -2,6 +2,8 @@ package service
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"isp-gate-service/domain"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
@@ -12,7 +14,7 @@ type AuthorizationCache interface {
|
||||
}
|
||||
|
||||
type AuthorizationRepo interface {
|
||||
Authorize(ctx context.Context, applicationId int, endpoint string) (bool, error)
|
||||
Authorize(ctx context.Context, req domain.AuthorizeRequest) (bool, error)
|
||||
}
|
||||
|
||||
type Authorization struct {
|
||||
@@ -27,21 +29,26 @@ func NewAuthorization(cache AuthorizationCache, repo AuthorizationRepo) Authoriz
|
||||
}
|
||||
}
|
||||
|
||||
func (s Authorization) Authorize(ctx context.Context, applicationId int, endpoint string) (bool, error) {
|
||||
ok, err := s.cache.Get(ctx, applicationId, endpoint)
|
||||
func (s Authorization) Authorize(ctx context.Context, applicationId int, httpMethod string, endpoint string) (bool, error) {
|
||||
cacheKey := fmt.Sprintf("%s %s", httpMethod, endpoint)
|
||||
ok, err := s.cache.Get(ctx, applicationId, cacheKey)
|
||||
if err != nil {
|
||||
return false, errors.WithMessage(err, "authz cache get")
|
||||
}
|
||||
if ok {
|
||||
return ok, nil
|
||||
return true, nil
|
||||
}
|
||||
|
||||
ok, err = s.repo.Authorize(ctx, applicationId, endpoint)
|
||||
ok, err = s.repo.Authorize(ctx, domain.AuthorizeRequest{
|
||||
ApplicationId: applicationId,
|
||||
HttpMethod: httpMethod,
|
||||
Endpoint: endpoint,
|
||||
})
|
||||
if err != nil {
|
||||
return false, errors.WithMessagef(err, "authz repo authorize")
|
||||
}
|
||||
if ok {
|
||||
err = s.cache.SetAuthorized(ctx, applicationId, endpoint)
|
||||
err = s.cache.SetAuthorized(ctx, applicationId, cacheKey)
|
||||
if err != nil {
|
||||
return false, errors.WithMessagef(err, "authz cache set")
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user