mirror of
https://github.com/ultravioletrs/cocos.git
synced 2026-08-07 15:26:26 +00:00
7e63921896
* Add vtpm attestation support to agent service and server Signed-off-by: Sammy Oina <sammyoina@gmail.com> * Update mockery version to v2.53.2 and refactor VM factory to include logger Signed-off-by: Sammy Oina <sammyoina@gmail.com> * Send event notification when computation is stopped in agentService Signed-off-by: Sammy Oina <sammyoina@gmail.com> * Remove redundant assignment of Stderr in qemuVM Start method Signed-off-by: Sammy Oina <sammyoina@gmail.com> * Rename SVM references to CVM in tracing, logging, metrics, and service layers Signed-off-by: Sammy Oina <sammyoina@gmail.com> --------- Signed-off-by: Sammy Oina <sammyoina@gmail.com>
73 lines
1.7 KiB
Go
73 lines
1.7 KiB
Go
// Copyright (c) Ultraviolet
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
package grpc
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
|
|
"github.com/ultravioletrs/cocos/manager"
|
|
"google.golang.org/protobuf/types/known/emptypb"
|
|
)
|
|
|
|
var (
|
|
_ manager.ManagerServiceServer = (*grpcServer)(nil)
|
|
ErrUnexpectedMsg = errors.New("unknown message type")
|
|
)
|
|
|
|
type grpcServer struct {
|
|
manager.UnimplementedManagerServiceServer
|
|
svc manager.Service
|
|
}
|
|
|
|
// NewServer returns new AuthServiceServer instance.
|
|
func NewServer(svc manager.Service) manager.ManagerServiceServer {
|
|
return &grpcServer{
|
|
svc: svc,
|
|
}
|
|
}
|
|
|
|
func (s *grpcServer) CreateVm(ctx context.Context, req *manager.CreateReq) (*manager.CreateRes, error) {
|
|
port, id, err := s.svc.CreateVM(ctx, req)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &manager.CreateRes{
|
|
ForwardedPort: port,
|
|
CvmId: id,
|
|
}, nil
|
|
}
|
|
|
|
func (s *grpcServer) RemoveVm(ctx context.Context, req *manager.RemoveReq) (*emptypb.Empty, error) {
|
|
if err := s.svc.RemoveVM(ctx, req.CvmId); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &emptypb.Empty{}, nil
|
|
}
|
|
|
|
func (s *grpcServer) CVMInfo(ctx context.Context, req *manager.CVMInfoReq) (*manager.CVMInfoRes, error) {
|
|
ovmf, cpunum, cputype, eosversion := s.svc.ReturnCVMInfo(ctx)
|
|
|
|
return &manager.CVMInfoRes{
|
|
OvmfVersion: ovmf,
|
|
CpuNum: int32(cpunum),
|
|
CpuType: cputype,
|
|
EosVersion: eosversion,
|
|
Id: req.Id,
|
|
}, nil
|
|
}
|
|
|
|
func (s *grpcServer) AttestationPolicy(ctx context.Context, req *manager.AttestationPolicyReq) (*manager.AttestationPolicyRes, error) {
|
|
policy, err := s.svc.FetchAttestationPolicy(ctx, req.Id)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &manager.AttestationPolicyRes{
|
|
Info: policy,
|
|
Id: req.Id,
|
|
}, nil
|
|
}
|