Skip to content
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

feat: prevent body double-read in googleapi.CheckResponse #1602

Merged
merged 3 commits into from
Jan 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion internal/gengapic/gengapic.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ func (g *generator) genAndCommitHelpers(scopes []string) error {
p(" return nil, nil, err")
p(" }")
p(` logger.DebugContext(ctx, "api response", "serviceName", serviceName, "rpcName", rpc, "response", internallog.HTTPResponse(resp, buf))`)
p(" if err = googleapi.CheckResponse(resp); err != nil {")
p(" if err = googleapi.CheckResponseWithBody(resp, buf); err != nil {")
p(" return nil, nil, err")
p(" }")
p(" return buf, resp, nil")
Expand Down
2 changes: 1 addition & 1 deletion internal/gengapic/testdata/helpers_default_scope.want
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func executeHTTPRequestWithResponse(ctx context.Context, client *http.Client, re
return nil, nil, err
}
logger.DebugContext(ctx, "api response", "serviceName", serviceName, "rpcName", rpc, "response", internallog.HTTPResponse(resp, buf))
if err = googleapi.CheckResponse(resp); err != nil {
if err = googleapi.CheckResponseWithBody(resp, buf); err != nil {
return nil, nil, err
}
return buf, resp, nil
Expand Down
2 changes: 1 addition & 1 deletion internal/gengapic/testdata/helpers_multiple_scopes.want
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func executeHTTPRequestWithResponse(ctx context.Context, client *http.Client, re
return nil, nil, err
}
logger.DebugContext(ctx, "api response", "serviceName", serviceName, "rpcName", rpc, "response", internallog.HTTPResponse(resp, buf))
if err = googleapi.CheckResponse(resp); err != nil {
if err = googleapi.CheckResponseWithBody(resp, buf); err != nil {
return nil, nil, err
}
return buf, resp, nil
Expand Down
2 changes: 1 addition & 1 deletion internal/gengapic/testdata/helpers_no_scopes.want
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func executeHTTPRequestWithResponse(ctx context.Context, client *http.Client, re
return nil, nil, err
}
logger.DebugContext(ctx, "api response", "serviceName", serviceName, "rpcName", rpc, "response", internallog.HTTPResponse(resp, buf))
if err = googleapi.CheckResponse(resp); err != nil {
if err = googleapi.CheckResponseWithBody(resp, buf); err != nil {
return nil, nil, err
}
return buf, resp, nil
Expand Down
2 changes: 1 addition & 1 deletion internal/gengapic/testdata/snippet.want
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2024 Google LLC
// Copyright 2025 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
40 changes: 19 additions & 21 deletions showcase/go.mod
Original file line number Diff line number Diff line change
@@ -1,44 +1,42 @@
module showcase

go 1.21
go 1.22

require (
cloud.google.com/go v0.116.0
cloud.google.com/go/iam v1.3.0
github.com/google/go-cmp v0.6.0
github.com/googleapis/gapic-showcase v0.35.5
github.com/googleapis/gax-go/v2 v2.14.0
google.golang.org/api v0.210.0
github.com/googleapis/gax-go/v2 v2.14.1
google.golang.org/api v0.218.0
google.golang.org/genproto v0.0.0-20241209162323-e6fa225c2576
google.golang.org/genproto/googleapis/rpc v0.0.0-20241209162323-e6fa225c2576
google.golang.org/grpc v1.67.1
google.golang.org/protobuf v1.35.2
google.golang.org/genproto/googleapis/rpc v0.0.0-20250115164207-1a7da9e5054f
google.golang.org/grpc v1.69.4
google.golang.org/protobuf v1.36.3
)

require (
cloud.google.com/go/auth v0.11.0 // indirect
cloud.google.com/go/auth/oauth2adapt v0.2.6 // indirect
cloud.google.com/go/compute/metadata v0.5.2 // indirect
cloud.google.com/go/auth v0.14.0 // indirect
cloud.google.com/go/auth/oauth2adapt v0.2.7 // indirect
cloud.google.com/go/compute/metadata v0.6.0 // indirect
cloud.google.com/go/longrunning v0.6.3 // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/go-logr/logr v1.4.2 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/google/s2a-go v0.1.8 // indirect
github.com/google/s2a-go v0.1.9 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.3.4 // indirect
go.opencensus.io v0.24.0 // indirect
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.54.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.54.0 // indirect
go.opentelemetry.io/otel v1.29.0 // indirect
go.opentelemetry.io/otel/metric v1.29.0 // indirect
go.opentelemetry.io/otel/trace v1.29.0 // indirect
golang.org/x/crypto v0.31.0 // indirect
golang.org/x/net v0.33.0 // indirect
golang.org/x/oauth2 v0.24.0 // indirect
go.opentelemetry.io/otel v1.31.0 // indirect
go.opentelemetry.io/otel/metric v1.31.0 // indirect
go.opentelemetry.io/otel/trace v1.31.0 // indirect
golang.org/x/crypto v0.32.0 // indirect
golang.org/x/net v0.34.0 // indirect
golang.org/x/oauth2 v0.25.0 // indirect
golang.org/x/sync v0.10.0 // indirect
golang.org/x/sys v0.28.0 // indirect
golang.org/x/sys v0.29.0 // indirect
golang.org/x/text v0.21.0 // indirect
golang.org/x/time v0.8.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20241206012308-a4fef0638583 // indirect
golang.org/x/time v0.9.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20241209162323-e6fa225c2576 // indirect
)
Loading
Loading