Skip to content

Commit

Permalink
transport/grpc: Fix check of GOOGLE_CLOUD_ENABLE_DIRECT_PATH
Browse files Browse the repository at this point in the history
When GOOGLE_CLOUD_ENABLE_DIRECT_PATH is empty and split is called
a slice with a single empty string is then looped and matched
with strings.Contains. This means that without that environment
variable set every single endpoint is matched.

Instead check to make sure the match isn't against an empty string
first.

Change-Id: I7382c7997098a9f77db44bc8e1fb10942caeaa61
Reviewed-on: https://code-review.googlesource.com/c/google-api-go-client/+/41670
Reviewed-by: Jean de Klerk <[email protected]>
  • Loading branch information
jameshartig authored and jeanbza committed Jun 6, 2019
1 parent 321c6e0 commit ba71ec0
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion transport/grpc/dial.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,8 @@ func isDirectPathEnabled(endpoint string) bool {
// Only try direct path if the user has opted in via the environment variable.
whitelist := strings.Split(os.Getenv("GOOGLE_CLOUD_ENABLE_DIRECT_PATH"), ",")
for _, api := range whitelist {
if strings.Contains(endpoint, api) {
// Ignore empty string since an empty env variable splits into [""]
if api != "" && strings.Contains(endpoint, api) {
return true
}
}
Expand Down

0 comments on commit ba71ec0

Please sign in to comment.