Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(274)

Side by Side Diff: common/gcloud/gs/gs.go

Issue 2219023003: Update APIs to use new Google cloud paths. (Closed) Base URL: https://github.com/luci/luci-go@master
Patch Set: Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The LUCI Authors. All rights reserved. 1 // Copyright 2015 The LUCI Authors. All rights reserved.
2 // Use of this source code is governed under the Apache License, Version 2.0 2 // Use of this source code is governed under the Apache License, Version 2.0
3 // that can be found in the LICENSE file. 3 // that can be found in the LICENSE file.
4 4
5 package gs 5 package gs
6 6
7 import ( 7 import (
8 "fmt" 8 "fmt"
9 "io" 9 "io"
10 "net/http" 10 "net/http"
11 "time" 11 "time"
12 12
13 "github.com/luci/luci-go/common/errors" 13 "github.com/luci/luci-go/common/errors"
14 log "github.com/luci/luci-go/common/logging" 14 log "github.com/luci/luci-go/common/logging"
15 "github.com/luci/luci-go/common/retry" 15 "github.com/luci/luci-go/common/retry"
16
17 gs "cloud.google.com/go/storage"
16 "golang.org/x/net/context" 18 "golang.org/x/net/context"
17 "google.golang.org/api/googleapi" 19 "google.golang.org/api/googleapi"
18 » "google.golang.org/cloud" 20 » "google.golang.org/api/option"
19 » gs "google.golang.org/cloud/storage"
20 ) 21 )
21 22
22 var ( 23 var (
23 // ReadWriteScopes is the set of scopes needed for read/write Google Sto rage 24 // ReadWriteScopes is the set of scopes needed for read/write Google Sto rage
24 // access. 25 // access.
25 ReadWriteScopes = []string{gs.ScopeReadWrite} 26 ReadWriteScopes = []string{gs.ScopeReadWrite}
26 27
27 // ReadOnlyScopes is the set of scopes needed for read/write Google Stor age 28 // ReadOnlyScopes is the set of scopes needed for read/write Google Stor age
28 // read-only access. 29 // read-only access.
29 ReadOnlyScopes = []string{gs.ScopeReadOnly} 30 ReadOnlyScopes = []string{gs.ScopeReadOnly}
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 return nil 191 return nil
191 }, func(err error, d time.Duration) { 192 }, func(err error, d time.Duration) {
192 log.Fields{ 193 log.Fields{
193 log.ErrorKey: err, 194 log.ErrorKey: err,
194 "delay": d, 195 "delay": d,
195 }.Warningf(c, "Transient error deleting file. Retrying...") 196 }.Warningf(c, "Transient error deleting file. Retrying...")
196 }) 197 })
197 } 198 }
198 199
199 func (c *prodClient) newClient() (*gs.Client, error) { 200 func (c *prodClient) newClient() (*gs.Client, error) {
200 » var optsArray [1]cloud.ClientOption 201 » var optsArray [1]option.ClientOption
201 opts := optsArray[:0] 202 opts := optsArray[:0]
202 if c.rt != nil { 203 if c.rt != nil {
203 » » opts = append(opts, cloud.WithBaseHTTP(&http.Client{ 204 » » opts = append(opts, option.WithHTTPClient(&http.Client{
204 Transport: c.rt, 205 Transport: c.rt,
205 })) 206 }))
206 } 207 }
207 return gs.NewClient(c, opts...) 208 return gs.NewClient(c, opts...)
208 } 209 }
209 210
210 func (c *prodClient) handleForPath(p Path) (*gs.ObjectHandle, error) { 211 func (c *prodClient) handleForPath(p Path) (*gs.ObjectHandle, error) {
211 bucket, filename, err := splitPathErr(p) 212 bucket, filename, err := splitPathErr(p)
212 if err != nil { 213 if err != nil {
213 return nil, err 214 return nil, err
(...skipping 16 matching lines...) Expand all
230 // The storage library doesn't return gs.ErrObjectNotExist when Delete 231 // The storage library doesn't return gs.ErrObjectNotExist when Delete
231 // returns a 404. Catch that explicitly. 232 // returns a 404. Catch that explicitly.
232 if t, ok := err.(*googleapi.Error); ok { 233 if t, ok := err.(*googleapi.Error); ok {
233 switch t.Code { 234 switch t.Code {
234 case http.StatusNotFound: 235 case http.StatusNotFound:
235 return true 236 return true
236 } 237 }
237 } 238 }
238 return false 239 return false
239 } 240 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698