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

Side by Side Diff: go/auth/auth.go

Issue 779633003: CT Google Storage utils to download/upload artifacts for workers (Closed) Base URL: https://skia.googlesource.com/buildbot@master
Patch Set: Check for test.short Created 6 years 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
« no previous file with comments | « ct/go/util/testdata/testupload/10ktest/alexa2-2.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 package auth 1 package auth
2 2
3 import ( 3 import (
4 "fmt" 4 "fmt"
5 "net/http" 5 "net/http"
6 "time" 6 "time"
7 7
8 "code.google.com/p/goauth2/oauth" 8 "code.google.com/p/goauth2/oauth"
9 "github.com/oxtoacart/webbrowser" 9 "github.com/oxtoacart/webbrowser"
10 "skia.googlesource.com/buildbot.git/go/util" 10 "skia.googlesource.com/buildbot.git/go/util"
11 ) 11 )
12 12
13 const ( 13 const (
14 // TIMEOUT is the http timeout when making Google Storage requests. 14 // TIMEOUT is the http timeout when making Google Storage requests.
15 TIMEOUT = time.Duration(time.Minute) 15 TIMEOUT = time.Duration(time.Minute)
16 // Supported Cloud storage API OAuth scopes.
17 SCOPE_READ_ONLY = "https://www.googleapis.com/auth/devstorage.read_on ly"
18 SCOPE_READ_WRITE = "https://www.googleapis.com/auth/devstorage.read_wr ite"
19 SCOPE_FULL_CONTROL = "https://www.googleapis.com/auth/devstorage.full_co ntrol"
16 ) 20 )
17 21
18 // DefaultOAuthConfig returns the default configuration for oauth. 22 // DefaultOAuthConfig returns the default configuration for oauth.
19 // If the given path for the cachefile is empty a default value is 23 // If the given path for the cachefile is empty a default value is
20 // used. 24 // used.
21 func DefaultOAuthConfig(cacheFilePath string) *oauth.Config { 25 func DefaultOAuthConfig(cacheFilePath string) *oauth.Config {
26 return OAuthConfig(cacheFilePath, SCOPE_READ_ONLY)
27 }
28
29 // OAuthConfig returns a configuration for oauth with the specified scope.
30 // If the given path for the cachefile is empty a default value is used.
31 func OAuthConfig(cacheFilePath, scope string) *oauth.Config {
22 if cacheFilePath == "" { 32 if cacheFilePath == "" {
23 cacheFilePath = "google_storage_token.data" 33 cacheFilePath = "google_storage_token.data"
24 } 34 }
25
26 return &oauth.Config{ 35 return &oauth.Config{
27 ClientId: "470362608618-nlbqngfl87f4b3mhqqe9ojgaoe11vrld.app s.googleusercontent.com", 36 ClientId: "470362608618-nlbqngfl87f4b3mhqqe9ojgaoe11vrld.app s.googleusercontent.com",
28 ClientSecret: "J4YCkfMXFJISGyuBuVEiH60T", 37 ClientSecret: "J4YCkfMXFJISGyuBuVEiH60T",
29 » » Scope: "https://www.googleapis.com/auth/devstorage.read_o nly", 38 » » Scope: scope,
30 AuthURL: "https://accounts.google.com/o/oauth2/auth", 39 AuthURL: "https://accounts.google.com/o/oauth2/auth",
31 TokenURL: "https://accounts.google.com/o/oauth2/token", 40 TokenURL: "https://accounts.google.com/o/oauth2/token",
32 RedirectURL: "urn:ietf:wg:oauth:2.0:oob", 41 RedirectURL: "urn:ietf:wg:oauth:2.0:oob",
33 TokenCache: oauth.CacheFile(cacheFilePath), 42 TokenCache: oauth.CacheFile(cacheFilePath),
34 } 43 }
35 } 44 }
36 45
37 // runFlow runs through a 3LO OAuth 2.0 flow to get credentials for Google Stora ge. 46 // runFlow runs through a 3LO OAuth 2.0 flow to get credentials for Google Stora ge.
38 func RunFlow(config *oauth.Config) (*http.Client, error) { 47 func RunFlow(config *oauth.Config) (*http.Client, error) {
39 if config == nil { 48 if config == nil {
(...skipping 15 matching lines...) Expand all
55 webbrowser.Open(url) 64 webbrowser.Open(url)
56 var code string 65 var code string
57 fmt.Scan(&code) 66 fmt.Scan(&code)
58 if _, err := transport.Exchange(code); err != nil { 67 if _, err := transport.Exchange(code); err != nil {
59 return nil, err 68 return nil, err
60 } 69 }
61 } 70 }
62 71
63 return transport.Client(), nil 72 return transport.Client(), nil
64 } 73 }
OLDNEW
« no previous file with comments | « ct/go/util/testdata/testupload/10ktest/alexa2-2.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698