From 7a2df5bea3f8c2480e269b65c67d5f91c487a499 Mon Sep 17 00:00:00 2001 From: Burcu Dogan Date: Sun, 22 Jun 2014 14:39:35 -0700 Subject: [PATCH] Add docs. --- google/appengine.go | 9 +++++++++ google/appenginevm.go | 9 +++++++++ 2 files changed, 18 insertions(+) diff --git a/google/appengine.go b/google/appengine.go index 6bdf0a4..51120a8 100644 --- a/google/appengine.go +++ b/google/appengine.go @@ -9,20 +9,28 @@ import ( "github.com/golang/oauth2" ) +// AppEngineConfig represents a configuration for an +// App Engine application's Google service account. type AppEngineConfig struct { context appengine.Context scopes []string cache oauth2.Cache } +// NewAppEngineConfig creates a new AppEngineConfig for the +// provided auth scopes. func NewAppEngineConfig(context appengine.Context, scopes []string) *AppEngineConfig { return &AppEngineConfig{context: context, scopes: scopes} } +// NewTransport returns a transport that authorizes +// the requests with the application's service account. func (c *AppEngineConfig) NewTransport() oauth2.Transport { return oauth2.NewAuthorizedTransport(c, nil) } +// NewTransport returns a token-caching transport that authorizes +// the requests with the application's service account. func (c *AppEngineConfig) NewTransportWithCache(cache oauth2.Cache) (oauth2.Transport, error) { token, err := cache.Read() if err != nil { @@ -32,6 +40,7 @@ func (c *AppEngineConfig) NewTransportWithCache(cache oauth2.Cache) (oauth2.Tran return oauth2.NewAuthorizedTransport(c, token), nil } +// FetchToken fetches a new access token for the provided scopes. func (c *AppEngineConfig) FetchToken(existing *oauth2.Token) (*oauth2.Token, error) { token, expiry, err := appengine.AccessToken(c.context, strings.Join(c.scopes, " ")) if err != nil { diff --git a/google/appenginevm.go b/google/appenginevm.go index a6d1df0..1a6ff37 100644 --- a/google/appenginevm.go +++ b/google/appenginevm.go @@ -9,20 +9,28 @@ import ( "google.golang.org/appengine" ) +// AppEngineConfig represents a configuration for an +// App Engine application's Google service account. type AppEngineConfig struct { context appengine.Context scopes []string cache oauth2.Cache } +// NewAppEngineConfig creates a new AppEngineConfig for the +// provided auth scopes. func NewAppEngineConfig(context appengine.Context, scopes []string) *AppEngineConfig { return &AppEngineConfig{context: context, scopes: scopes} } +// NewTransport returns a transport that authorizes +// the requests with the application's service account. func (c *AppEngineConfig) NewTransport() oauth2.Transport { return oauth2.NewAuthorizedTransport(c, nil) } +// NewTransport returns a token-caching transport that authorizes +// the requests with the application's service account. func (c *AppEngineConfig) NewTransportWithCache(cache oauth2.Cache) (oauth2.Transport, error) { token, err := cache.Read() if err != nil { @@ -32,6 +40,7 @@ func (c *AppEngineConfig) NewTransportWithCache(cache oauth2.Cache) (oauth2.Tran return oauth2.NewAuthorizedTransport(c, token), nil } +// FetchToken fetches a new access token for the provided scopes. func (c *AppEngineConfig) FetchToken(existing *oauth2.Token) (*oauth2.Token, error) { token, expiry, err := appengine.AccessToken(c.context, strings.Join(c.scopes, " ")) if err != nil {