Skip to content

Commit

Permalink
coordinator: use grcp error codes
Browse files Browse the repository at this point in the history
Signed-off-by: Paul Meyer <[email protected]>
  • Loading branch information
katexochen committed Jan 8, 2024
1 parent adc1b26 commit 7c818c1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
12 changes: 7 additions & 5 deletions coordinator/coordapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ import (
"github.com/edgelesssys/nunki/internal/manifest"
"github.com/edgelesssys/nunki/internal/memstore"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/keepalive"
"google.golang.org/grpc/status"
)

type coordAPIServer struct {
Expand Down Expand Up @@ -59,19 +61,19 @@ func (s *coordAPIServer) SetManifest(_ context.Context, req *coordapi.SetManifes

var m *manifest.Manifest
if err := json.Unmarshal(req.Manifest, &m); err != nil {
return nil, fmt.Errorf("failed to unmarshal manifest: %w", err)
return nil, status.Errorf(codes.InvalidArgument, "unmarshaling manifest: %s", err)
}

for _, policyBytes := range req.Policies {
policy := manifest.Policy(policyBytes)
if _, ok := m.Policies[policy.Hash()]; !ok {
return nil, fmt.Errorf("policy %v not found in manifest", policy.Hash())
return nil, status.Errorf(codes.InvalidArgument, "policy %v not found in manifest", policy.Hash())
}
s.policyTextStore.Set(policy.Hash(), policy)
}

if err := s.manifSetGetter.SetManifest(m); err != nil {
return nil, err
return nil, status.Errorf(codes.Internal, "setting manifest: %s", err)
}

resp := &coordapi.SetManifestResponse{
Expand All @@ -89,12 +91,12 @@ func (s *coordAPIServer) GetManifests(_ context.Context, _ *coordapi.GetManifest

manifests := s.manifSetGetter.GetManifests()
if len(manifests) == 0 {
return nil, fmt.Errorf("no manifests found")
return nil, status.Errorf(codes.FailedPrecondition, "no manifests found")
}

manifestBytes, err := manifestSliceToBytesSlice(manifests)
if err != nil {
return nil, err
return nil, status.Errorf(codes.Internal, "marshaling manifests: %s", err)
}

resp := &coordapi.GetManifestsResponse{
Expand Down
5 changes: 4 additions & 1 deletion coordinator/intercom.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ import (
"github.com/edgelesssys/nunki/internal/grpc/atlscredentials"
"github.com/edgelesssys/nunki/internal/intercom"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/keepalive"
"google.golang.org/grpc/status"
)

type intercomServer struct {
Expand Down Expand Up @@ -59,7 +61,8 @@ func (i *intercomServer) NewMeshCert(_ context.Context, req *intercom.NewMeshCer

cert, err := i.certGet.GetCert(req.PeerPublicKeyHash)
if err != nil {
return nil, err
return nil, status.Errorf(codes.Internal,
"getting certificate with public key hash %q: %s", req.PeerPublicKeyHash, err)
}

meshCACert := i.caChainGetter.GetMeshCACert()
Expand Down

0 comments on commit 7c818c1

Please sign in to comment.