derrickaw commented on code in PR #40729:
URL: https://github.com/apache/beam/pull/40729#discussion_r4353178773
##########
sdks/go/pkg/beam/util/gcsx/gcs.go:
##########
@@ -60,12 +64,75 @@ func NewUnauthenticatedClient(ctx context.Context)
(*storage.Client, error) {
// endpointOptions returns the client options for the --gcs_endpoint override,
// if any.
func endpointOptions() []option.ClientOption {
- if ep := gcpopts.GetGcsEndpoint(); ep != "" {
+ if ep := GetGcsEndpoint(); ep != "" {
return []option.ClientOption{option.WithEndpoint(ep)}
}
return nil
}
+// GetGcsEndpoint returns the GCS endpoint override from the --gcs_endpoint
+// flag. If the flag is unset or not registered, it falls back to the
+// "gcs_endpoint" pipeline option, which is how the value reaches remote
+// workers, where flags are not parsed. Returns an empty string if no override
+// is configured.
+//
+// Looking up the flag by name avoids importing gcpopts, which registers global
+// flags such as --region and --project that can conflict with user binaries.
+func GetGcsEndpoint() string {
+ if f := flag.Lookup("gcs_endpoint"); f != nil && f.Value.String() != ""
{
+ return f.Value.String()
+ }
+ return runtime.GlobalOptions.Get("gcs_endpoint")
+}
+
+const universeDomainEnvVar = "GOOGLE_CLOUD_UNIVERSE_DOMAIN"
+
+// findDefaultCredentials is a variable to allow overriding in tests.
+var findDefaultCredentials = google.FindDefaultCredentials
+
+// cachedUniverseDomain caches the universe domain resolved from the default
+// credentials, since resolving it may require a metadata server round trip
+// and clients are created frequently.
+var cachedUniverseDomain struct {
+ mu sync.Mutex
+ resolved bool
+ value string
+}
+
+// GetUniverseDomain returns the Google Cloud universe domain, first from the
+// GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variable, then falling back to the
+// universe domain of the default credentials. Returns an empty string if it
+// cannot be determined.
+//
+// Google API clients don't infer the universe domain from the credentials,
+// and requests fail if the two differ, so clients should pass this value via
+// option.WithUniverseDomain to support non-default universes such as Trusted
+// Partner Cloud (TPC).
+func GetUniverseDomain(ctx context.Context) string {
Review Comment:
Ok, created a separate package. Will that work? Thanks
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]