From 0dbf86afcf042d27ee0b3beb255e95823d5a161f Mon Sep 17 00:00:00 2001 From: WanLinghao Date: Tue, 19 Feb 2019 11:42:05 +0800 Subject: [PATCH] Migrate the controller to use TokenRequest and rotate token periodically Kubernetes-commit: 244b244f9d84c56ad3a5af255b70c793f6bfd39c --- transport/token_source.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/transport/token_source.go b/transport/token_source.go index 8595df27..b8cadd38 100644 --- a/transport/token_source.go +++ b/transport/token_source.go @@ -59,6 +59,15 @@ func NewCachedFileTokenSource(path string) oauth2.TokenSource { } } +// NewCachedTokenSource returns a oauth2.TokenSource reads a token from a +// designed TokenSource. The ts would provide the source of token. +func NewCachedTokenSource(ts oauth2.TokenSource) oauth2.TokenSource { + return &cachingTokenSource{ + now: time.Now, + base: ts, + } +} + type tokenSourceTransport struct { base http.RoundTripper ort http.RoundTripper