mirror of https://github.com/status-im/consul.git
35 lines
900 B
Go
35 lines
900 B
Go
// Copyright (c) HashiCorp, Inc.
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
package resource
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
|
|
"google.golang.org/grpc/codes"
|
|
"google.golang.org/grpc/status"
|
|
|
|
"github.com/hashicorp/consul/internal/storage"
|
|
"github.com/hashicorp/consul/proto-public/pbresource"
|
|
)
|
|
|
|
func (s *Server) Read(ctx context.Context, req *pbresource.ReadRequest) (*pbresource.ReadResponse, error) {
|
|
// check type exists
|
|
if _, err := s.resolveType(req.Id.Type); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
resource, err := s.backend.Read(ctx, readConsistencyFrom(ctx), req.Id)
|
|
if err != nil {
|
|
if errors.Is(err, storage.ErrNotFound) {
|
|
return nil, status.Error(codes.NotFound, err.Error())
|
|
}
|
|
if errors.As(err, &storage.GroupVersionMismatchError{}) {
|
|
return nil, status.Error(codes.InvalidArgument, err.Error())
|
|
}
|
|
return nil, err
|
|
}
|
|
return &pbresource.ReadResponse{Resource: resource}, nil
|
|
}
|