| OLD | NEW |
| 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 internal | 5 package internal |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "cloud.google.com/go/compute/metadata" |
| 8 "golang.org/x/net/context" | 9 "golang.org/x/net/context" |
| 9 "golang.org/x/oauth2" | 10 "golang.org/x/oauth2" |
| 10 "golang.org/x/oauth2/google" | 11 "golang.org/x/oauth2/google" |
| 11 "google.golang.org/cloud/compute/metadata" | |
| 12 | 12 |
| 13 "github.com/luci/luci-go/common/data/stringset" | 13 "github.com/luci/luci-go/common/data/stringset" |
| 14 "github.com/luci/luci-go/common/logging" | 14 "github.com/luci/luci-go/common/logging" |
| 15 ) | 15 ) |
| 16 | 16 |
| 17 type gceTokenProvider struct { | 17 type gceTokenProvider struct { |
| 18 account string | 18 account string |
| 19 } | 19 } |
| 20 | 20 |
| 21 // NewGCETokenProvider returns TokenProvider that knows how to use GCE metadata
server. | 21 // NewGCETokenProvider returns TokenProvider that knows how to use GCE metadata
server. |
| (...skipping 23 matching lines...) Expand all Loading... |
| 45 | 45 |
| 46 func (p *gceTokenProvider) MintToken() (*oauth2.Token, error) { | 46 func (p *gceTokenProvider) MintToken() (*oauth2.Token, error) { |
| 47 src := google.ComputeTokenSource(p.account) | 47 src := google.ComputeTokenSource(p.account) |
| 48 return src.Token() | 48 return src.Token() |
| 49 } | 49 } |
| 50 | 50 |
| 51 func (p *gceTokenProvider) RefreshToken(*oauth2.Token) (*oauth2.Token, error) { | 51 func (p *gceTokenProvider) RefreshToken(*oauth2.Token) (*oauth2.Token, error) { |
| 52 // Minting and refreshing on GCE is the same thing: a call to metadata s
erver. | 52 // Minting and refreshing on GCE is the same thing: a call to metadata s
erver. |
| 53 return p.MintToken() | 53 return p.MintToken() |
| 54 } | 54 } |
| OLD | NEW |