diff --git a/app/publisher/zip.go b/app/publisher/zip.go index d7f4f27aa..700ed169d 100644 --- a/app/publisher/zip.go +++ b/app/publisher/zip.go @@ -265,10 +265,10 @@ func (zh *zipHandler) ServeHTTP(rw http.ResponseWriter, req *http.Request) { return } zh := zip.FileHeader{ - Name: file.path, - Method: zip.Store, + Name: file.path, + Method: zip.Store, + Modified: fr.ModTime().UTC(), } - zh.SetModTime(fr.ModTime()) f, err := zw.CreateHeader(&zh) if err != nil { log.Printf("Could not create %q in zip: %v", file.path, err) diff --git a/internal/osutil/gce/gce.go b/internal/osutil/gce/gce.go index 33d594650..c6b0e4853 100644 --- a/internal/osutil/gce/gce.go +++ b/internal/osutil/gce/gce.go @@ -32,6 +32,7 @@ import ( "golang.org/x/oauth2/google" compute "google.golang.org/api/compute/v1" "google.golang.org/api/googleapi" + "google.golang.org/api/option" "perkeep.org/internal/osutil" "perkeep.org/pkg/env" @@ -158,7 +159,7 @@ func gceInstance() (*gceInst, error) { if err != nil { return nil, fmt.Errorf("error getting a default http client: %v", err) } - cs, err := compute.New(hc) + cs, err := compute.NewService(ctx, option.WithHTTPClient(hc)) if err != nil { return nil, fmt.Errorf("error getting a compute service: %v", err) } diff --git a/misc/docker/dock.go b/misc/docker/dock.go index cb021ff40..42a5b3365 100644 --- a/misc/docker/dock.go +++ b/misc/docker/dock.go @@ -363,7 +363,7 @@ func ProjectTokenSource(proj string, scopes ...string) (oauth2.TokenSource, erro if err != nil { return nil, fmt.Errorf("reading JSON config from %s: %v", fileName, err) } - return conf.TokenSource(oauth2.NoContext), nil + return conf.TokenSource(context.TODO()), nil } var bucketProject = map[string]string{ diff --git a/misc/release/make-release.go b/misc/release/make-release.go index 98f1e9ca5..fae184102 100644 --- a/misc/release/make-release.go +++ b/misc/release/make-release.go @@ -924,7 +924,7 @@ func ProjectTokenSource(proj string, scopes ...string) (oauth2.TokenSource, erro if err != nil { return nil, fmt.Errorf("reading JSON config from %s: %v", fileName, err) } - return conf.TokenSource(oauth2.NoContext), nil + return conf.TokenSource(context.TODO()), nil } var bucketProject = map[string]string{ diff --git a/pkg/blobserver/gethandler/get_test.go b/pkg/blobserver/gethandler/get_test.go index c21a31645..731a51ecd 100644 --- a/pkg/blobserver/gethandler/get_test.go +++ b/pkg/blobserver/gethandler/get_test.go @@ -94,7 +94,7 @@ func testServeBlobContents(t *testing.T, contents, wantType string) { if rr.Code != 200 { t.Errorf("Response code = %d; want 200", rr.Code) } - if g, w := rr.HeaderMap.Get("Content-Type"), wantType; g != w { + if g, w := rr.Result().Header.Get("Content-Type"), wantType; g != w { t.Errorf("Content-Type = %q; want %q", g, w) } if rr.Body.String() != contents { diff --git a/pkg/importer/gphotos/download.go b/pkg/importer/gphotos/download.go index 7863f8050..84cebb267 100644 --- a/pkg/importer/gphotos/download.go +++ b/pkg/importer/gphotos/download.go @@ -28,6 +28,7 @@ import ( "golang.org/x/time/rate" "google.golang.org/api/drive/v3" "google.golang.org/api/googleapi" + "google.golang.org/api/option" ) var scopeURLs = []string{drive.DriveReadonlyScope} @@ -50,7 +51,7 @@ const ( // The permission ID becomes the "userID" (AcctAttrUserID) value on the // account's "importerAccount" permanode. func getUser(ctx context.Context, client *http.Client) (*drive.User, error) { - srv, err := drive.New(client) + srv, err := drive.NewService(ctx, option.WithHTTPClient(client)) if err != nil { return nil, err } @@ -75,8 +76,8 @@ type downloader struct { // // The client must be authenticated for drive.DrivePhotosReadonlyScope // ("https://www.googleapis.com/auth/drive.photos.readonly").. -func newDownloader(client *http.Client) (*downloader, error) { - srv, err := drive.New(client) +func newDownloader(ctx context.Context, client *http.Client) (*downloader, error) { + srv, err := drive.NewService(ctx, option.WithHTTPClient(client)) if err != nil { return nil, err } diff --git a/pkg/importer/gphotos/gphotos.go b/pkg/importer/gphotos/gphotos.go index 8de81db4b..af27c9315 100644 --- a/pkg/importer/gphotos/gphotos.go +++ b/pkg/importer/gphotos/gphotos.go @@ -309,7 +309,7 @@ func (imp) Run(rctx *importer.RunContext) error { } } - dl, err := newDownloader(ctxutil.Client(ctx)) + dl, err := newDownloader(ctx, ctxutil.Client(ctx)) if err != nil { return err } diff --git a/pkg/importer/importer_test.go b/pkg/importer/importer_test.go index 93ece9b4b..1b1442d5e 100644 --- a/pkg/importer/importer_test.go +++ b/pkg/importer/importer_test.go @@ -76,6 +76,6 @@ func TestImportRootPageHTML(t *testing.T) { r := httptest.NewRequest("GET", "/importer/", nil) h.serveImportersRoot(w, r) if w.Code != 200 || !strings.Contains(w.Body.String(), "dummy1") { - t.Errorf("Got %d response with header %v, body %s", w.Code, w.HeaderMap, w.Body.String()) + t.Errorf("Got %d response with header %v, body %s", w.Code, w.Result().Header, w.Body.String()) } } diff --git a/pkg/importer/twitter/twitter.go b/pkg/importer/twitter/twitter.go index 328300a9e..6a972f293 100644 --- a/pkg/importer/twitter/twitter.go +++ b/pkg/importer/twitter/twitter.go @@ -325,10 +325,9 @@ func (im *imp) LongPoll(rctx *importer.RunContext) error { } form := url.Values{"with": {"user"}} - req, _ := http.NewRequest("GET", "https://userstream.twitter.com/1.1/user.json", nil) + req, _ := http.NewRequestWithContext(rctx.Context(), "GET", "https://userstream.twitter.com/1.1/user.json", nil) req.Header.Set("Authorization", oauthClient.AuthorizationHeader(accessCreds, "GET", req.URL, form)) req.URL.RawQuery = form.Encode() - req.Cancel = rctx.Context().Done() log.Printf("twitter: beginning long poll, awaiting new tweets...") res, err := http.DefaultClient.Do(req) diff --git a/pkg/sorted/mysql/cloudsql.go b/pkg/sorted/mysql/cloudsql.go index 67834f902..6dffdd9c4 100644 --- a/pkg/sorted/mysql/cloudsql.go +++ b/pkg/sorted/mysql/cloudsql.go @@ -27,6 +27,7 @@ import ( "cloud.google.com/go/compute/metadata" "golang.org/x/oauth2" "golang.org/x/oauth2/google" + "google.golang.org/api/option" sqladmin "google.golang.org/api/sqladmin/v1beta4" ) @@ -45,7 +46,8 @@ func maybeRemapCloudSQL(host string) (out string, err error) { return "", fmt.Errorf("Failed to lookup GCE project ID: %v", err) } - admin, _ := sqladmin.New(oauth2.NewClient(context.Background(), google.ComputeTokenSource(""))) + ctx := context.TODO() + admin, _ := sqladmin.NewService(ctx, option.WithHTTPClient(oauth2.NewClient(ctx, google.ComputeTokenSource("")))) listRes, err := admin.Instances.List(proj).Do() if err != nil { return "", fmt.Errorf("error enumerating Cloud SQL instances: %v", err) diff --git a/server/perkeepd/logging.go b/server/perkeepd/logging.go index 25fe3fab0..f734d40e7 100644 --- a/server/perkeepd/logging.go +++ b/server/perkeepd/logging.go @@ -76,7 +76,7 @@ func maybeSetupGoogleCloudLogging() io.Closer { } ctx := context.Background() logc, err := logging.NewClient(ctx, - flagGCEProjectID, option.WithServiceAccountFile(flagGCEJWTFile)) + flagGCEProjectID, option.WithCredentialsFile(flagGCEJWTFile)) if err != nil { exitf("Error creating GCL client: %v", err) }