From 559a2c6864ba02ae4da401fe6f13410ae9fa68fc Mon Sep 17 00:00:00 2001 From: Cody Soyland Date: Fri, 7 Aug 2020 16:28:06 -0500 Subject: [PATCH] Add GetVDS and GetVDSs gRPC implementations --- server/grpc.go | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/server/grpc.go b/server/grpc.go index 2a83a4792..559ce43a0 100644 --- a/server/grpc.go +++ b/server/grpc.go @@ -75,12 +75,23 @@ func errToStatusError(err error) error { return status.Error(codes.Unknown, err.Error()) } -func (*GRPCHandler) GetVDS(ctx context.Context, req *pb.GetVDSRequest) (*pb.GetVDSResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method GetVDS not implemented") +func (h *GRPCHandler) GetVDS(ctx context.Context, req *pb.GetVDSRequest) (*pb.GetVDSResponse, error) { + schema := h.api.Schema(ctx) + for _, index := range schema { + if req.Name == index.Name { + return &pb.GetVDSResponse{Vds: &pb.VDS{Name: index.Name}}, nil + } + } + return nil, status.Error(codes.NotFound, fmt.Sprintf("VDS with name %s not found", req.Name)) } -func (*GRPCHandler) GetVDSs(ctx context.Context, req *pb.GetVDSsRequest) (*pb.GetVDSsResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method GetVDSs not implemented") +func (h *GRPCHandler) GetVDSs(ctx context.Context, req *pb.GetVDSsRequest) (*pb.GetVDSsResponse, error) { + schema := h.api.Schema(ctx) + vdss := make([]*pb.VDS, len(schema)) + for i, index := range schema { + vdss[i] = &pb.VDS{Name: index.Name} + } + return &pb.GetVDSsResponse{Vdss: vdss}, nil } func (*GRPCHandler) PostVDS(ctx context.Context, req *pb.PostVDSRequest) (*pb.PostVDSResponse, error) {