Skip to content

Commit

Permalink
Added goauth2 and the google api client.
Browse files Browse the repository at this point in the history
  • Loading branch information
brendandburns committed Jun 17, 2014
1 parent 45397c4 commit 23e736c
Show file tree
Hide file tree
Showing 569 changed files with 353,227 additions and 0 deletions.
4 changes: 4 additions & 0 deletions third_party/deps.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
TOP_PACKAGES="
github.com/coreos/go-etcd/etcd
github.com/fsouza/go-dockerclient
code.google.com/p/goauth2/compute/serviceaccount
code.google.com/p/goauth2/oauth
code.google.com/p/google-api-go-client/compute/v1
"

DEP_PACKAGES="
gopkg.in/v1/yaml
bitbucket.org/kardianos/osext
code.google.com/p/google-api-go-client/googleapi
github.com/coreos/go-log/log
github.com/coreos/go-systemd/journal
"
Expand Down
Binary file not shown.
1 change: 1 addition & 0 deletions third_party/src/code.google.com/p/goauth2/.hg/branch
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
default
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
696c088491246273e92442aa66b5281e5bb34faa 68
696c088491246273e92442aa66b5281e5bb34faa default
4 changes: 4 additions & 0 deletions third_party/src/code.google.com/p/goauth2/.hg/cache/tags
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
68 696c088491246273e92442aa66b5281e5bb34faa 376d5fb6b2d758667877a62ee81b204d35dc2e03

379476c9e05c5275356e0a82ca079e61869e9192 release
4ee7c273e92e663ef8dc0c476d395350a586ad75 weekly
Binary file not shown.
2 changes: 2 additions & 0 deletions third_party/src/code.google.com/p/goauth2/.hg/hgrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[paths]
default = https://code.google.com/p/goauth2
4 changes: 4 additions & 0 deletions third_party/src/code.google.com/p/goauth2/.hg/requires
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
dotencode
fncache
revlogv1
store
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
22 changes: 22 additions & 0 deletions third_party/src/code.google.com/p/goauth2/.hg/store/fncache
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
data/compute/serviceaccount/serviceaccount.go.i
data/AUTHORS.i
data/CONTRIBUTORS.i
data/oauth/oauth.go.i
data/oauth/jwt/example/main.go.i
data/appengine/serviceaccount/cache.go.i
data/oauth/example/buzz.go.i
data/oauth/jwt/jwt.go.i
data/lib/codereview/codereview.cfg.i
data/oauth/jwt/example/example.client_secrets.json.i
data/LICENSE.i
data/appengine/serviceaccount/serviceaccount.go.i
data/oauth/oauth_test.go.i
data/.hgignore.i
data/oauth/jwt/example/example.pem.i
data/oauth/Makefile.i
data/oauth/example/Makefile.i
data/PATENTS.i
data/.hgtags.i
data/README.i
data/oauth/jwt/jwt_test.go.i
data/oauth/example/oauthreq.go.i
Empty file.
Binary file not shown.
Empty file.
Empty file.
1 change: 1 addition & 0 deletions third_party/src/code.google.com/p/goauth2/.hg/undo.branch
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
default
3 changes: 3 additions & 0 deletions third_party/src/code.google.com/p/goauth2/.hg/undo.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
0
pull
https://code.google.com/p/goauth2
Empty file.
1 change: 1 addition & 0 deletions third_party/src/code.google.com/p/goauth2/.hgignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
last-change
2 changes: 2 additions & 0 deletions third_party/src/code.google.com/p/goauth2/.hgtags
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
379476c9e05c5275356e0a82ca079e61869e9192 release
4ee7c273e92e663ef8dc0c476d395350a586ad75 weekly
3 changes: 3 additions & 0 deletions third_party/src/code.google.com/p/goauth2/AUTHORS
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# This source code refers to The Go Authors for copyright purposes.
# The master list of authors is in the main Go distribution,
# visible at http://tip.golang.org/AUTHORS.
3 changes: 3 additions & 0 deletions third_party/src/code.google.com/p/goauth2/CONTRIBUTORS
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# This source code was written by the Go contributors.
# The master list of contributors is in the main Go distribution,
# visible at http://tip.golang.org/CONTRIBUTORS.
27 changes: 27 additions & 0 deletions third_party/src/code.google.com/p/goauth2/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
Copyright (c) 2009 The goauth2 Authors. All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:

* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following disclaimer
in the documentation and/or other materials provided with the
distribution.
* Neither the name of Google Inc. nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
22 changes: 22 additions & 0 deletions third_party/src/code.google.com/p/goauth2/PATENTS
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Additional IP Rights Grant (Patents)

"This implementation" means the copyrightable works distributed by
Google as part of the goauth2 project.

Google hereby grants to You a perpetual, worldwide, non-exclusive,
no-charge, royalty-free, irrevocable (except as stated in this section)
patent license to make, have made, use, offer to sell, sell, import,
transfer and otherwise run, modify and propagate the contents of this
implementation of Go, where such license applies only to those patent
claims, both currently owned or controlled by Google and acquired in
the future, licensable by Google that are necessarily infringed by this
implementation of Go. This grant does not include claims that would be
infringed only as a consequence of further modification of this
implementation. If you or your agent or exclusive licensee institute or
order or agree to the institution of patent litigation against any
entity (including a cross-claim or counterclaim in a lawsuit) alleging
that this implementation of Go or any code incorporated within this
implementation of Go constitutes direct or contributory patent
infringement, or inducement of patent infringement, then any patent
rights granted to you under this License for this implementation of Go
shall terminate as of the date such litigation is filed.
7 changes: 7 additions & 0 deletions third_party/src/code.google.com/p/goauth2/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
This is the repository for goauth2; an OAuth 2.0 client library for Go.

To contribute, follow the Go Programming Language's contribution process:
http://golang.org/doc/contribute.html
Except use the goauth2 repository instead of the go repo.

Contact Andrew Gerrand <adg@golang.org> with any enquiries.
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Copyright 2013 The goauth2 Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// +build appengine

package serviceaccount

import (
"time"

"appengine"
"appengine/memcache"

"code.google.com/p/goauth2/oauth"
)

// cache implementss TokenCache using memcache to store AccessToken
// for the application service account.
type cache struct {
Context appengine.Context
Key string
}

func (m cache) Token() (*oauth.Token, error) {
item, err := memcache.Get(m.Context, m.Key)
if err != nil {
return nil, err
}
return &oauth.Token{
AccessToken: string(item.Value),
Expiry: time.Now().Add(item.Expiration),
}, nil
}

func (m cache) PutToken(tok *oauth.Token) error {
return memcache.Set(m.Context, &memcache.Item{
Key: m.Key,
Value: []byte(tok.AccessToken),
Expiration: tok.Expiry.Sub(time.Now()),
})
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
// Copyright 2013 The goauth2 Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// +build appengine

// The serviceaccount package provides support for making
// OAuth2-authorized HTTP requests from App Engine using service
// accounts.
//
// See: https://developers.google.com/appengine/docs/go/reference#AccessToken
//
// Example usage:
//
// c := appengine.NewContext()
// client, err := serviceaccount.NewClient(c, "https://www.googleapis.com/auth/compute", "https://www.googleapis.com/auth/bigquery")
// if err != nil {
// c.Errorf("failed to create service account client: %q", err)
// return err
// }
// client.Post("https://www.googleapis.com/compute/...", ...)
// client.Post("https://www.googleapis.com/bigquery/...", ...)
//
package serviceaccount

import (
"net/http"
"strings"

"appengine"
"appengine/urlfetch"

"code.google.com/p/goauth2/oauth"
)

// NewClient returns an *http.Client authorized for the
// given scopes with the service account owned by the application.
// Tokens are cached in memcache until they expire.
func NewClient(c appengine.Context, scopes ...string) (*http.Client, error) {
t := &transport{
Context: c,
Scopes: scopes,
Transport: &urlfetch.Transport{
Context: c,
Deadline: 0,
AllowInvalidServerCertificate: false,
},
TokenCache: &cache{
Context: c,
Key: "goauth2_serviceaccount_" + strings.Join(scopes, "_"),
},
}
// Get the initial access token.
if err := t.FetchToken(); err != nil {
return nil, err
}
return &http.Client{
Transport: t,
}, nil
}

// transport is an oauth.Transport with a custom Refresh and RoundTrip implementation.
type transport struct {
*oauth.Token
Context appengine.Context
Scopes []string
Transport http.RoundTripper
TokenCache oauth.Cache
}

func (t *transport) Refresh() error {
// Get a new access token for the application service account.
tok, expiry, err := appengine.AccessToken(t.Context, t.Scopes...)
if err != nil {
return err
}
t.Token = &oauth.Token{
AccessToken: tok,
Expiry: expiry,
}
if t.TokenCache != nil {
// Cache the token and ignore error (as we can always get a new one).
t.TokenCache.PutToken(t.Token)
}
return nil
}

// Fetch token from cache or generate a new one if cache miss or expired.
func (t *transport) FetchToken() error {
// Try to get the Token from the cache if enabled.
if t.Token == nil && t.TokenCache != nil {
// Ignore cache error as we can always get a new token with Refresh.
t.Token, _ = t.TokenCache.Token()
}

// Get a new token using Refresh in case of a cache miss of if it has expired.
if t.Token == nil || t.Expired() {
if err := t.Refresh(); err != nil {
return err
}
}
return nil
}

// cloneRequest returns a clone of the provided *http.Request.
// The clone is a shallow copy of the struct and its Header map.
func cloneRequest(r *http.Request) *http.Request {
// shallow copy of the struct
r2 := new(http.Request)
*r2 = *r
// deep copy of the Header
r2.Header = make(http.Header)
for k, s := range r.Header {
r2.Header[k] = s
}
return r2
}

// RoundTrip issues an authorized HTTP request and returns its response.
func (t *transport) RoundTrip(req *http.Request) (*http.Response, error) {
if err := t.FetchToken(); err != nil {
return nil, err
}

// To set the Authorization header, we must make a copy of the Request
// so that we don't modify the Request we were given.
// This is required by the specification of http.RoundTripper.
newReq := cloneRequest(req)
newReq.Header.Set("Authorization", "Bearer "+t.AccessToken)

// Make the HTTP request.
return t.Transport.RoundTrip(newReq)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
defaultcc: golang-dev@googlegroups.com
contributors: http://go.googlecode.com/hg/CONTRIBUTORS
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
default
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
2ba9f0995cf0215c20ebd6de43a14d70af30fea6 111
82370a626348d2965e51305ac70a6243994c86d7 default
2ba9f0995cf0215c20ebd6de43a14d70af30fea6 default
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
111 2ba9f0995cf0215c20ebd6de43a14d70af30fea6 240bf94bde841a072024e132d5d77029a0b0fbef
14 82370a626348d2965e51305ac70a6243994c86d7

b571b553f8c057cb6952ce817dfb09b6e34a8c0b release
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[paths]
default = https://code.google.com/p/google-api-go-client
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
dotencode
fncache
revlogv1
store
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading

0 comments on commit 23e736c

Please sign in to comment.