mirror of
https://github.com/ultravioletrs/cocos.git
synced 2026-08-07 07:14:50 +00:00
6169766666
CI / lint (push) Has been cancelled
CI / test (agent) (push) Has been cancelled
CI / test (cli) (push) Has been cancelled
CI / test (cmd) (push) Has been cancelled
CI / test (internal) (push) Has been cancelled
CI / test (manager, true) (push) Has been cancelled
CI / test (pkg) (push) Has been cancelled
CI / upload-coverage (push) Has been cancelled
* Update attestationFromCert function to include ccPlatform parameter for enhanced attestation processing Signed-off-by: Sammy Oina <sammyoina@gmail.com> * chore: migrate dependencies from supermq to magistrala and update build configurations Signed-off-by: Sammy Oina <sammyoina@gmail.com> * chore: update project dependencies, repository source, and support TDX QuoteV5 attestation Signed-off-by: Sammy Oina <sammyoina@gmail.com> --------- Signed-off-by: Sammy Oina <sammyoina@gmail.com>
38 lines
1.2 KiB
Go
38 lines
1.2 KiB
Go
// Copyright (c) Ultraviolet
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
package agent
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/absmach/magistrala/pkg/errors"
|
|
"github.com/ultravioletrs/cocos/agent"
|
|
"github.com/ultravioletrs/cocos/pkg/clients"
|
|
"github.com/ultravioletrs/cocos/pkg/clients/grpc"
|
|
"github.com/ultravioletrs/cocos/pkg/tls"
|
|
grpchealth "google.golang.org/grpc/health/grpc_health_v1"
|
|
)
|
|
|
|
var ErrAgentServiceUnavailable = errors.New("agent service is unavailable")
|
|
|
|
// NewAgentClient creates new agent gRPC client instance.
|
|
func NewAgentClient(ctx context.Context, cfg clients.AttestedClientConfig) (grpc.Client, agent.AgentServiceClient, error) {
|
|
client, err := grpc.NewClient(cfg)
|
|
if err != nil {
|
|
return nil, nil, err
|
|
}
|
|
|
|
if client.Secure() != tls.WithMATLS.String() && client.Secure() != tls.WithATLS.String() && client.Secure() != tls.WithTLS.String() {
|
|
health := grpchealth.NewHealthClient(client.Connection())
|
|
resp, err := health.Check(ctx, &grpchealth.HealthCheckRequest{
|
|
Service: "agent",
|
|
})
|
|
|
|
if err != nil || resp.GetStatus() != grpchealth.HealthCheckResponse_SERVING {
|
|
return nil, nil, errors.Wrap(err, ErrAgentServiceUnavailable)
|
|
}
|
|
}
|
|
|
|
return client, agent.NewAgentServiceClient(client.Connection()), nil
|
|
}
|