2024-01-22 17:22:41: merge [master:56d3e06e49d7a75f142424293788a4f3b6245430];
This commit is contained in:
1 parent
7014f56cbb
commit
2b91caece0
60 files changed
+3558
No files matched your search
@@ -0,0 +1,47 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"isp-gate-service/domain"
|
||||
|
||||
"github.com/integration-system/isp-kit/grpc/client"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
const (
|
||||
adminAuthenticate = "admin/secure/authenticate"
|
||||
adminAuthorize = "admin/secure/authorize"
|
||||
)
|
||||
|
||||
type Admin struct {
|
||||
cli *client.Client
|
||||
}
|
||||
|
||||
func NewAdmin(cli *client.Client) Admin {
|
||||
return Admin{cli: cli}
|
||||
}
|
||||
|
||||
func (r Admin) Authenticate(ctx context.Context, token string) (*domain.AdminAuthenticateResponse, error) {
|
||||
resp := domain.AdminAuthenticateResponse{}
|
||||
err := r.cli.Invoke(adminAuthenticate).
|
||||
JsonRequestBody(domain.AuthenticateRequest{Token: token}).
|
||||
JsonResponseBody(&resp).
|
||||
Do(ctx)
|
||||
if err != nil {
|
||||
return nil, errors.WithMessagef(err, "grpc client invoke %s", adminAuthenticate)
|
||||
}
|
||||
return &resp, nil
|
||||
}
|
||||
|
||||
func (r Admin) Authorize(ctx context.Context, adminId int, permission string) (bool, error) {
|
||||
resp := domain.AdminAuthorizeResponse{}
|
||||
err := r.cli.Invoke(adminAuthorize).
|
||||
JsonRequestBody(domain.AdminAuthorizeRequest{AdminId: adminId, Permission: permission}).
|
||||
JsonResponseBody(&resp).
|
||||
Do(ctx)
|
||||
if err != nil {
|
||||
return false, errors.WithMessagef(err, "grpc client invoke: %s", adminAuthorize)
|
||||
}
|
||||
return resp.Authorized, nil
|
||||
}
|
||||
Reference in new issue
Block a user