-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
storage: when using an emulator, it is not possible to use the same Client object for both uploading and other operations #2476
Comments
@justinruggles thanks for the detailed report! Could you let me know what versions of cloud.google.com/go/storage and google.golang.org/api you are using in your application? |
cloud.google.com/go/storage v1.9.0 |
I was able to work around the issue by using a |
Here's an example should anyone come across this issue: type roundTripper url.URL
func (rt roundTripper) RoundTrip(req *http.Request) (*http.Response, error) {
req.Host = rt.Host
req.URL.Host = rt.Host
req.URL.Scheme = rt.Scheme
return http.DefaultTransport.RoundTrip(req)
}
func main() {
u, _ := url.Parse("http://localhost:8000/")
hClient := &http.Client{Transport: roundTripper(*u)}
gClient, err := storage.NewClient(context.Background(), option.WithHTTPClient(hClient))
} |
Looks like those three lines in |
I've ran into this issue while trying to use this emulator in http mode (i.e. w/o https). If I run the client without I ended up locally commenting out the |
Apologies for the delay on this-- I'm working on a resolution! |
@tritone Hi! May be helpfull for your works PS Can you tell me when the emulator will officially support go sdk? |
NB: when running under |
Hi everyone, this issue has been fixed and will be in the next release. You should then be able to use a Storage Client for all operations, including upload.
Additionally, @justinruggles, we implemented this suggestion. Thank you for bringing our attention to this issue! |
@BrennaEpp was this #4608 ? |
#4608 fixes the original upload issue, correct. #4616 adds @justinruggles's suggestion on allowing users to set |
Relevant upstream issue and fixes: - googleapis/google-cloud-go#2476 - googleapis/google-cloud-go#4616 - googleapis/google-cloud-go#4608
Client
Storage
Environment
MacOS 10.14.6
Go Environment
Code
GCS emulator request logs (pretty-printed for ease of reading)
Expected behavior
When performing client operations using a GCS emulator, one should be able to use a single Client object for both uploading and general operations even though the endpoint prefixes differ.
Actual behavior
When using a GCS emulator from a client application, one must set the
STORAGE_EMULATOR_HOST
environment variable and useoption.WithEndpoint
when creating theClient
withstorage.NewClient
. For general operations, the endpoint specified must include the path prefix/storage/v1
(e.g.http://localhost:8080/storage/v1
) if the emulator uses the same prefix as the public JSON API. Doing this results in the correct value being set for BasePath in the underlying raw client. However, when performing an upload operation, the BasePath is overridden to remove the path component (google-cloud-go/storage/writer.go
Lines 128 to 130 in 89ef506
/upload/storage/v1
) when making the API call. The result is that any general operations performed after uploading using the same Client object will fail because they no longer use the full/storage/v1
path.To work around this, I attempted to make the emulator serve the endpoints without the prefix, but then the upload operations failed because the prefix is always added to those requests in the client.
Additional Context
I'm using a GCS emulator written for my employer that is not yet publicly available.
The text was updated successfully, but these errors were encountered: