mirror of
https://github.com/absmach/magistrala.git
synced 2026-06-23 04:10:28 +00:00
ef5c253c51
Signed-off-by: nyagamunene <stevenyaga2014@gmail.com> Signed-off-by: dusan <borovcanindusan1@gmail.com> Co-authored-by: Steve Munene <stevenyaga2014@gmail.com>
47 lines
1.1 KiB
Go
47 lines
1.1 KiB
Go
// Copyright (c) Abstract Machines
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
package grpc
|
|
|
|
import (
|
|
"context"
|
|
|
|
grpcCertsV1 "github.com/absmach/supermq/api/grpc/certs/v1"
|
|
"github.com/absmach/supermq/certs"
|
|
"github.com/absmach/supermq/pkg/authn"
|
|
svcerr "github.com/absmach/supermq/pkg/errors/service"
|
|
"github.com/go-kit/kit/endpoint"
|
|
"google.golang.org/protobuf/types/known/emptypb"
|
|
)
|
|
|
|
func getEntityEndpoint(svc certs.Service) endpoint.Endpoint {
|
|
return func(ctx context.Context, request any) (any, error) {
|
|
req := request.(*grpcCertsV1.EntityReq)
|
|
|
|
entityID, err := svc.GetEntityID(ctx, req.SerialNumber)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &grpcCertsV1.EntityRes{EntityId: entityID}, nil
|
|
}
|
|
}
|
|
|
|
func revokeCertsEndpoint(svc certs.Service) endpoint.Endpoint {
|
|
return func(ctx context.Context, request any) (any, error) {
|
|
req := request.(*grpcCertsV1.RevokeReq)
|
|
|
|
session, ok := ctx.Value(authn.SessionKey).(authn.Session)
|
|
if !ok {
|
|
return nil, svcerr.ErrAuthentication
|
|
}
|
|
|
|
err := svc.RevokeAll(ctx, session, req.EntityId)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &emptypb.Empty{}, nil
|
|
}
|
|
}
|