mirror of
https://github.com/ultravioletrs/cocos.git
synced 2026-06-23 04:10:25 +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>
50 lines
1.3 KiB
Go
50 lines
1.3 KiB
Go
// Copyright (c) Ultraviolet
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
package cli
|
|
|
|
import (
|
|
"github.com/absmach/magistrala/pkg/errors"
|
|
"github.com/fatih/color"
|
|
"github.com/spf13/cobra"
|
|
"github.com/ultravioletrs/cocos/agent/auth"
|
|
"github.com/ultravioletrs/cocos/pkg/clients/grpc/agent"
|
|
"google.golang.org/grpc/codes"
|
|
"google.golang.org/grpc/status"
|
|
)
|
|
|
|
var (
|
|
errAgentUnavailable = errors.New("agent is unavailable on the current address")
|
|
errDigitalSignatureVerificationFailed = errors.New("digital signature verification failed, check the provided public key")
|
|
)
|
|
|
|
func decodeErros(err error) error {
|
|
statusErr, ok := status.FromError(err)
|
|
if ok {
|
|
switch statusErr.Code() {
|
|
case codes.PermissionDenied:
|
|
return errDigitalSignatureVerificationFailed
|
|
case codes.Unavailable:
|
|
return errAgentUnavailable
|
|
case codes.Unknown:
|
|
return err
|
|
}
|
|
}
|
|
switch {
|
|
case errors.Contains(err, auth.ErrSignatureVerificationFailed):
|
|
return auth.ErrSignatureVerificationFailed
|
|
|
|
case errors.Contains(err, agent.ErrAgentServiceUnavailable):
|
|
return agent.ErrAgentServiceUnavailable
|
|
default:
|
|
return err
|
|
}
|
|
}
|
|
|
|
func (c *CLI) printError(cmd *cobra.Command, message string, err error) {
|
|
if !c.Verbose {
|
|
err = decodeErros(err)
|
|
}
|
|
msg := color.New(color.FgRed).Sprintf(message, err)
|
|
cmd.Println(msg)
|
|
}
|