[GH-ISSUE #146] Support the GRPC API? #2177

Closed
opened 2026-03-15 17:52:47 +03:00 by kerem · 4 comments
Owner

Originally created by @fsouza on GitHub (Dec 9, 2019).
Original GitHub issue: https://github.com/fsouza/fake-gcs-server/issues/146

Certain clients use only the GRPC API and we currently don't support this.

As reported in #84 and #142, the Java clients seem to be use only GRPC.

Open as a question because I don't know yet how much work that would be.

Originally created by @fsouza on GitHub (Dec 9, 2019). Original GitHub issue: https://github.com/fsouza/fake-gcs-server/issues/146 Certain clients use only the GRPC API and we currently don't support this. As reported in #84 and #142, the Java clients seem to be use only GRPC. Open as a question because I don't know yet how much work that would be.
kerem 2026-03-15 17:52:47 +03:00
Author
Owner

@Tyler-Gauch commented on GitHub (Apr 7, 2020):

Hello @fsouza, I am looking to use this within a C# app. I believe the C# app also uses the GRPC API. I was wondering where you were on researching this. I may have some time coming up to help work on this, with research, coding etc, if needed, as others have pointed out this is really the only library available for emulating GCS.

<!-- gh-comment-id:610584456 --> @Tyler-Gauch commented on GitHub (Apr 7, 2020): Hello @fsouza, I am looking to use this within a C# app. I believe the C# app also uses the GRPC API. I was wondering where you were on researching this. I may have some time coming up to help work on this, with research, coding etc, if needed, as others have pointed out this is really the only library available for emulating GCS.
Author
Owner

@someone1 commented on GitHub (Apr 16, 2020):

Chiming in here to lend a few tips:

You can generate a server that fully implements the API quick using the proto file

git clone https://github.com/fsouza/fake-gcs-server.git
git clone --depth=1 https://github.com/googleapis/googleapis.git
mkdir grpc
protoc -I googleapis/ googleapis/google/storage/v1/*.proto --go_out=plugins=grpc:grpc
mv grpc/google.golang.org/genproto fake-gcs-server
rm -r grpc/
mkdir fake-gcs-server/grpc
touch fake-gcs-server/grpc/server.go

You should now have most of it ready to go, server.go contents (I did one as an example):

package grpc

import (
	"context"

	"github.com/golang/protobuf/ptypes"

	pb "github.com/fsouza/fake-gcs-server/genproto/googleapis/storage/v1"
	"github.com/fsouza/fake-gcs-server/internal/backend"
)

type Server struct {
	pb.UnimplementedStorageServer // To satisfy the interface without having to implement every method

	backend backend.Storage // share the same backend as fakeserver does
}

// Now just override whichever endpoints have been implemented in backend.Storage

func (g *grpcServer) ListBuckets(context.Context, *pb.ListBucketsRequest) (*pb.ListBucketsResponse, error) {
	buckets, err := g.backend.ListBuckets()
	if err != nil {
		return nil, err
	}

	resp := &pb.ListBucketsResponse{
		Items: make([]*pb.Bucket, len(buckets)),
	}
	for idx, bucket := range buckets {
		resp.Items[idx].Name = bucket.Name
		tc, err := ptypes.TimestampProto(bucket.TimeCreated)
		if err != nil {
			return nil, err
		}
		resp.Items[idx].TimeCreated = tc
		resp.Items[idx].Versioning = &pb.Bucket_Versioning{
			Enabled: bucket.VersioningEnabled,
		}
	}

	return resp, nil
}

you can use something like cmux to host both the HTTP and gRPC server on the same port (see this article)

I hope that helps!

<!-- gh-comment-id:614388032 --> @someone1 commented on GitHub (Apr 16, 2020): Chiming in here to lend a few tips: You can generate a server that fully implements the API quick using the [proto file](https://github.com/googleapis/googleapis/blob/master/google/storage/v1/storage.proto) ```bash git clone https://github.com/fsouza/fake-gcs-server.git git clone --depth=1 https://github.com/googleapis/googleapis.git mkdir grpc protoc -I googleapis/ googleapis/google/storage/v1/*.proto --go_out=plugins=grpc:grpc mv grpc/google.golang.org/genproto fake-gcs-server rm -r grpc/ mkdir fake-gcs-server/grpc touch fake-gcs-server/grpc/server.go ``` You should now have most of it ready to go, `server.go` contents (I did one as an example): ```go package grpc import ( "context" "github.com/golang/protobuf/ptypes" pb "github.com/fsouza/fake-gcs-server/genproto/googleapis/storage/v1" "github.com/fsouza/fake-gcs-server/internal/backend" ) type Server struct { pb.UnimplementedStorageServer // To satisfy the interface without having to implement every method backend backend.Storage // share the same backend as fakeserver does } // Now just override whichever endpoints have been implemented in backend.Storage func (g *grpcServer) ListBuckets(context.Context, *pb.ListBucketsRequest) (*pb.ListBucketsResponse, error) { buckets, err := g.backend.ListBuckets() if err != nil { return nil, err } resp := &pb.ListBucketsResponse{ Items: make([]*pb.Bucket, len(buckets)), } for idx, bucket := range buckets { resp.Items[idx].Name = bucket.Name tc, err := ptypes.TimestampProto(bucket.TimeCreated) if err != nil { return nil, err } resp.Items[idx].TimeCreated = tc resp.Items[idx].Versioning = &pb.Bucket_Versioning{ Enabled: bucket.VersioningEnabled, } } return resp, nil } ``` you can use something like cmux to host both the HTTP and gRPC server on the same port (see [this article](https://medium.com/@drgarcia1986/listen-grpc-and-http-requests-on-the-same-port-263c40cb45ff)) I hope that helps!
Author
Owner

@fsouza commented on GitHub (Feb 15, 2021):

Turns out the Java SDK issues were not related to gRPC, but rather gzip. Will leave this open though.

<!-- gh-comment-id:779482518 --> @fsouza commented on GitHub (Feb 15, 2021): Turns out the Java SDK issues were not related to gRPC, but rather gzip. Will leave this open though.
Author
Owner

@fsouza commented on GitHub (May 9, 2023):

Fixed via #1138.

<!-- gh-comment-id:1539217349 --> @fsouza commented on GitHub (May 9, 2023): Fixed via #1138.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/fake-gcs-server#2177
No description provided.