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

Side by Side Diff: go/src/infra/libs/auth/auth.go

Issue 1149313002: go: Replace Logrus with go-logging. (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master
Patch Set: typo Created 5 years, 7 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
« no previous file with comments | « go/Goopfile.lock ('k') | go/src/infra/libs/auth/auth_test.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 /* 5 /*
6 Package auth defines an opinionated wrapper around OAuth2. 6 Package auth defines an opinionated wrapper around OAuth2.
7 7
8 It hides configurability of base oauth2 library and instead makes a predefined 8 It hides configurability of base oauth2 library and instead makes a predefined
9 set of choices regarding where the credentials should be stored and how OAuth2 9 set of choices regarding where the credentials should be stored and how OAuth2
10 should be used. It makes authentication flows look more uniform across tools 10 should be used. It makes authentication flows look more uniform across tools
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 45
46 var ( 46 var (
47 // ErrLoginRequired is returned by Transport() in case long term credent ials 47 // ErrLoginRequired is returned by Transport() in case long term credent ials
48 // are not cached and the user must go through interactive login. 48 // are not cached and the user must go through interactive login.
49 ErrLoginRequired = errors.New("Interactive login is required") 49 ErrLoginRequired = errors.New("Interactive login is required")
50 50
51 // ErrInsufficientAccess is returned by Login() or Transport() if access _token 51 // ErrInsufficientAccess is returned by Login() or Transport() if access _token
52 // can't be minted for given OAuth scopes. For example if GCE instance w asn't 52 // can't be minted for given OAuth scopes. For example if GCE instance w asn't
53 // granted access to requested scopes when it was created. 53 // granted access to requested scopes when it was created.
54 ErrInsufficientAccess = internal.ErrInsufficientAccess 54 ErrInsufficientAccess = internal.ErrInsufficientAccess
55
56 // ErrNoTerminal is returned by Login() if interaction with a user is
57 // required, but the process is not attached to a terminal.
58 ErrNoTerminal = errors.New("Can't interact with a user: no terminal")
59 ) 55 )
60 56
61 // Known Google API OAuth scopes. 57 // Known Google API OAuth scopes.
62 const ( 58 const (
63 OAuthScopeEmail = "https://www.googleapis.com/auth/userinfo.email" 59 OAuthScopeEmail = "https://www.googleapis.com/auth/userinfo.email"
64 ) 60 )
65 61
66 // Method defines a method to use to obtain OAuth access_token. 62 // Method defines a method to use to obtain OAuth access_token.
67 type Method string 63 type Method string
68 64
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 defer a.lock.Unlock() 311 defer a.lock.Unlock()
316 312
317 err := a.ensureInitialized() 313 err := a.ensureInitialized()
318 if err != nil { 314 if err != nil {
319 return err 315 return err
320 } 316 }
321 if !a.provider.RequiresInteraction() { 317 if !a.provider.RequiresInteraction() {
322 return nil 318 return nil
323 } 319 }
324 320
325 // Active terminal is required for interaction with a user.
326 if !logging.IsTerminal {
327 return ErrNoTerminal
328 }
329
330 // Create initial token. This may require interaction with a user. 321 // Create initial token. This may require interaction with a user.
331 a.token, err = a.provider.MintToken() 322 a.token, err = a.provider.MintToken()
332 if err != nil { 323 if err != nil {
333 return err 324 return err
334 } 325 }
335 326
336 // Store the initial token in the cache. Don't abort if it fails, the to ken 327 // Store the initial token in the cache. Don't abort if it fails, the to ken
337 // is still usable from the memory. 328 // is still usable from the memory.
338 if err = a.cacheToken(a.token); err != nil { 329 if err = a.cacheToken(a.token); err != nil {
339 a.log.Warningf("auth: failed to write token to cache: %v", err) 330 a.log.Warningf("auth: failed to write token to cache: %v", err)
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after
646 func DefaultClient() (clientID string, clientSecret string) { 637 func DefaultClient() (clientID string, clientSecret string) {
647 clientID = "446450136466-2hr92jrq8e6i4tnsa56b52vacp7t3936.apps.googleuse rcontent.com" 638 clientID = "446450136466-2hr92jrq8e6i4tnsa56b52vacp7t3936.apps.googleuse rcontent.com"
648 clientSecret = "uBfbay2KCy9t4QveJ-dOqHtp" 639 clientSecret = "uBfbay2KCy9t4QveJ-dOqHtp"
649 return 640 return
650 } 641 }
651 642
652 // SecretsDir returns an absolute path to a directory to keep secret files in. 643 // SecretsDir returns an absolute path to a directory to keep secret files in.
653 func SecretsDir() string { 644 func SecretsDir() string {
654 return secretsDir() 645 return secretsDir()
655 } 646 }
OLDNEW
« no previous file with comments | « go/Goopfile.lock ('k') | go/src/infra/libs/auth/auth_test.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698