consul/agent/grpc-external/services/resource/list.go

32 lines
856 B
Go
Raw Normal View History

// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
package resource
import (
"context"
"github.com/hashicorp/consul/internal/storage"
"github.com/hashicorp/consul/proto-public/pbresource"
)
func (s *Server) List(ctx context.Context, req *pbresource.ListRequest) (*pbresource.ListResponse, error) {
if _, err := s.resolveType(req.Type); err != nil {
return nil, err
}
2023-04-04 16:30:06 +00:00
resources, err := s.Backend.List(ctx, readConsistencyFrom(ctx), storage.UnversionedTypeFrom(req.Type), req.Tenancy, req.NamePrefix)
if err != nil {
return nil, err
}
// filter out non-matching GroupVersion
result := make([]*pbresource.Resource, 0)
for _, resource := range resources {
if resource.Id.Type.GroupVersion == req.Type.GroupVersion {
result = append(result, resource)
}
}
return &pbresource.ListResponse{Resources: result}, nil
}