Revert "GCE tokens behavior to new format"

This commit is contained in:
Piotr Szczesniak
2015-09-04 10:26:19 +02:00
parent e724a5210a
commit b813ebadee
3 changed files with 7 additions and 12 deletions

View File

@@ -61,7 +61,6 @@ type GCECloud struct {
type Config struct {
Global struct {
TokenURL string `gcfg:"token-url"`
TokenBody string `gcfg:"token-body"`
ProjectID string `gcfg:"project-id"`
NetworkName string `gcfg:"network-name"`
}
@@ -160,7 +159,7 @@ func newGCECloud(config io.Reader) (*GCECloud, error) {
}
}
if cfg.Global.TokenURL != "" {
tokenSource = newAltTokenSource(cfg.Global.TokenURL, cfg.Global.TokenBody)
tokenSource = newAltTokenSource(cfg.Global.TokenURL)
}
}
client := oauth2.NewClient(oauth2.NoContext, tokenSource)

View File

@@ -19,7 +19,6 @@ package gce_cloud
import (
"encoding/json"
"net/http"
"strings"
"time"
"k8s.io/kubernetes/pkg/util"
@@ -60,7 +59,6 @@ func init() {
type altTokenSource struct {
oauthClient *http.Client
tokenURL string
tokenBody string
throttle util.RateLimiter
}
@@ -75,7 +73,7 @@ func (a *altTokenSource) Token() (*oauth2.Token, error) {
}
func (a *altTokenSource) token() (*oauth2.Token, error) {
req, err := http.NewRequest("POST", a.tokenURL, strings.NewReader(a.tokenBody))
req, err := http.NewRequest("GET", a.tokenURL, nil)
if err != nil {
return nil, err
}
@@ -88,24 +86,23 @@ func (a *altTokenSource) token() (*oauth2.Token, error) {
return nil, err
}
var tok struct {
AccessToken string `json:"accessToken"`
ExpireTime time.Time `json:"expireTime"`
AccessToken string `json:"accessToken"`
ExpiryTimeSeconds int64 `json:"expiryTimeSeconds,string"`
}
if err := json.NewDecoder(res.Body).Decode(&tok); err != nil {
return nil, err
}
return &oauth2.Token{
AccessToken: tok.AccessToken,
Expiry: tok.ExpireTime,
Expiry: time.Unix(tok.ExpiryTimeSeconds, 0),
}, nil
}
func newAltTokenSource(tokenURL, tokenBody string) oauth2.TokenSource {
func newAltTokenSource(tokenURL string) oauth2.TokenSource {
client := oauth2.NewClient(oauth2.NoContext, google.ComputeTokenSource(""))
a := &altTokenSource{
oauthClient: client,
tokenURL: tokenURL,
tokenBody: tokenBody,
throttle: util.NewTokenBucketRateLimiter(tokenURLQPS, tokenURLBurst),
}
return oauth2.ReuseTokenSource(nil, a)