From c9abe8aff7ffd276ff8c3bef188f2095a13289a0 Mon Sep 17 00:00:00 2001 From: David Colburn Date: Mon, 4 Mar 2024 19:53:35 -0800 Subject: [PATCH] simplify --- pkg/pipeline/sink/uploader/gcp.go | 25 +++++-------------------- 1 file changed, 5 insertions(+), 20 deletions(-) diff --git a/pkg/pipeline/sink/uploader/gcp.go b/pkg/pipeline/sink/uploader/gcp.go index fb3d1164..b9d42bca 100644 --- a/pkg/pipeline/sink/uploader/gcp.go +++ b/pkg/pipeline/sink/uploader/gcp.go @@ -28,9 +28,6 @@ import ( "github.com/googleapis/gax-go/v2" "google.golang.org/api/googleapi" "google.golang.org/api/option" - "google.golang.org/api/option/internaloption" - "google.golang.org/api/transport" - htransport "google.golang.org/api/transport/http" "github.com/livekit/egress/pkg/errors" "github.com/livekit/egress/pkg/types" @@ -53,25 +50,16 @@ func newGCPUploader(conf *livekit.GCPUpload) (uploader, error) { if conf.Credentials != "" { opts = append(opts, option.WithCredentialsJSON([]byte(conf.Credentials))) } - opts = append([]option.ClientOption{ - option.WithScopes(storage.ScopeFullControl, "https://www.googleapis.com/auth/cloud-platform"), - option.WithUserAgent("gcloud-golang-storage/1.36.0")}, opts...) - opts = append(opts, internaloption.WithDefaultEndpoint("https://storage.googleapis.com/storage/v1/")) - opts = append(opts, internaloption.WithDefaultMTLSEndpoint("https://storage.mtls.googleapis.com/storage/v1/")) - creds, err := transport.Creds(context.Background(), opts...) - if err == nil { - opts = append(opts, internaloption.WithCredentials(creds)) - } - // force ipv4 to avoid "service not available in your location, forbidden" errors from Google - defaultTransport := http.DefaultTransport.(*http.Transport).Clone() // override default transport DialContext + defaultTransport := http.DefaultTransport.(*http.Transport).Clone() http.DefaultTransport.(*http.Transport).DialContext = func(ctx context.Context, network, addr string) (net.Conn, error) { return (&net.Dialer{ Timeout: time.Second * 30, KeepAlive: time.Second * 30, - FallbackDelay: time.Nanosecond, + FallbackDelay: -1, ControlContext: func(ctx context.Context, network, address string, c syscall.RawConn) error { + // force ipv4 to avoid "service not available in your location, forbidden" errors from Google if network == "tcp6" { return errors.New("tcp6 disabled") } @@ -79,13 +67,10 @@ func newGCPUploader(conf *livekit.GCPUpload) (uploader, error) { }, }).DialContext(ctx, network, addr) } - httpClient, _, err := htransport.NewClient(context.Background(), opts...) - // reset default transport - http.DefaultTransport = defaultTransport - - opts = append(opts, option.WithHTTPClient(httpClient)) c, err := storage.NewClient(context.Background(), opts...) + // restore default transport + http.DefaultTransport = defaultTransport if err != nil { return nil, err }