mirror of
https://github.com/ultravioletrs/cocos.git
synced 2026-06-23 04:10:25 +00:00
5377dd4d7f
* Refactor mock interfaces to use 'any' instead of 'interface{}' for improved type safety and readability across multiple files in the manager and pkg directories.
Signed-off-by: Sammy Oina <sammyoina@gmail.com>
* Update Go version to 1.25.x in CI workflows and remove obsolete Go package files
Signed-off-by: Sammy Oina <sammyoina@gmail.com>
* Add mock implementations for various components in the attestation and SDK packages
- Created mock for MeasurementProvider in pkg/attestation/cmdconfig/mocks/mocks_test.go
- Created mock for Provider in pkg/attestation/mocks/mocks_test.go
- Created mock for Client in pkg/clients/grpc/mocks/mocks_test.go
- Created mock for SDK in pkg/sdk/mocks/mocks_test.go
These mocks are generated using mockery and are intended for unit testing purposes.
Signed-off-by: Sammy Oina <sammyoina@gmail.com>
* Remove autogenerated mock files and update mock usage in tests
- Deleted mocks for gRPC clients in pkg/clients/grpc/mocks/mocks_test.go and pkg/sdk/mocks/mocks_test.go.
- Updated test files in pkg/progressbar/progress_test.go to use the new mock structure without type parameters for gRPC client interfaces.
- Refactored mock generation in pkg/sdk/mocks/sdk.go to streamline the mock creation process and ensure consistency across mock methods.
Signed-off-by: Sammy Oina <sammyoina@gmail.com>
* Update protobuf generated files for events and manager
- Bump protoc-gen-go version from v1.36.5 to v1.36.8 in events.pb.go and manager.pb.go.
- Refactor raw descriptor definitions in events.pb.go and manager.pb.go to use string concatenation for better readability and maintainability.
- Ensure compatibility with the latest protobuf specifications and improve code generation consistency.
Signed-off-by: Sammy Oina <sammyoina@gmail.com>
* Update test commands to use GOTOOLCHAIN for consistent Go version handling
Signed-off-by: Sammy Oina <sammyoina@gmail.com>
* Fix GOTOOLCHAIN usage in test command for consistency
Signed-off-by: Sammy Oina <sammyoina@gmail.com>
---------
Signed-off-by: Sammy Oina <sammyoina@gmail.com>
112 lines
2.6 KiB
Go
112 lines
2.6 KiB
Go
// Copyright (c) Ultraviolet
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
package grpc
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/go-kit/kit/endpoint"
|
|
"github.com/ultravioletrs/cocos/agent"
|
|
"github.com/ultravioletrs/cocos/pkg/attestation"
|
|
)
|
|
|
|
func algoEndpoint(svc agent.Service) endpoint.Endpoint {
|
|
return func(ctx context.Context, request any) (any, error) {
|
|
req := request.(algoReq)
|
|
|
|
if err := req.validate(); err != nil {
|
|
return algoRes{}, err
|
|
}
|
|
|
|
algo := agent.Algorithm{Algorithm: req.Algorithm, Requirements: req.Requirements}
|
|
|
|
err := svc.Algo(ctx, algo)
|
|
if err != nil {
|
|
return algoRes{}, err
|
|
}
|
|
|
|
return algoRes{}, nil
|
|
}
|
|
}
|
|
|
|
func dataEndpoint(svc agent.Service) endpoint.Endpoint {
|
|
return func(ctx context.Context, request any) (any, error) {
|
|
req := request.(dataReq)
|
|
|
|
if err := req.validate(); err != nil {
|
|
return dataRes{}, err
|
|
}
|
|
|
|
dataset := agent.Dataset{Dataset: req.Dataset, Filename: req.Filename}
|
|
|
|
err := svc.Data(ctx, dataset)
|
|
if err != nil {
|
|
return dataRes{}, err
|
|
}
|
|
|
|
return dataRes{}, nil
|
|
}
|
|
}
|
|
|
|
func resultEndpoint(svc agent.Service) endpoint.Endpoint {
|
|
return func(ctx context.Context, request any) (any, error) {
|
|
req := request.(resultReq)
|
|
|
|
if err := req.validate(); err != nil {
|
|
return resultRes{}, err
|
|
}
|
|
file, err := svc.Result(ctx)
|
|
if err != nil {
|
|
return resultRes{}, err
|
|
}
|
|
|
|
return resultRes{File: file}, nil
|
|
}
|
|
}
|
|
|
|
func attestationEndpoint(svc agent.Service) endpoint.Endpoint {
|
|
return func(ctx context.Context, request any) (any, error) {
|
|
req := request.(attestationReq)
|
|
|
|
if err := req.validate(); err != nil {
|
|
return attestationRes{}, err
|
|
}
|
|
file, err := svc.Attestation(ctx, req.TeeNonce, req.VtpmNonce, attestation.PlatformType(req.AttType))
|
|
if err != nil {
|
|
return attestationRes{}, err
|
|
}
|
|
|
|
return attestationRes{File: file}, nil
|
|
}
|
|
}
|
|
|
|
func imaMeasurementsEndpoint(svc agent.Service) endpoint.Endpoint {
|
|
return func(ctx context.Context, request any) (any, error) {
|
|
req := request.(imaMeasurementsReq)
|
|
|
|
if err := req.validate(); err != nil {
|
|
return imaMeasurementsRes{}, err
|
|
}
|
|
file, pcr10, err := svc.IMAMeasurements(ctx)
|
|
if err != nil {
|
|
return imaMeasurementsRes{}, err
|
|
}
|
|
|
|
return imaMeasurementsRes{File: file, PCR10: pcr10}, nil
|
|
}
|
|
}
|
|
|
|
func azureAttestationTokenEndpoint(svc agent.Service) endpoint.Endpoint {
|
|
return func(ctx context.Context, request any) (any, error) {
|
|
req := request.(azureAttestationTokenReq)
|
|
if err := req.validate(); err != nil {
|
|
return fetchAttestationTokenRes{}, err
|
|
}
|
|
file, err := svc.AzureAttestationToken(ctx, req.tokenNonce)
|
|
if err != nil {
|
|
return fetchAttestationTokenRes{}, err
|
|
}
|
|
return fetchAttestationTokenRes{File: file}, nil
|
|
}
|
|
}
|