23 |
24 |
48 |
49 |
--------------------------------------------------------------------------------
/backend/swagger-ui/favicon-16x16.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sinmetal/gcpsm/92aeedc7835d9d5f58c0489897e57cd1f9423156/backend/swagger-ui/favicon-16x16.png
--------------------------------------------------------------------------------
/backend/swagger-ui/favicon-32x32.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sinmetal/gcpsm/92aeedc7835d9d5f58c0489897e57cd1f9423156/backend/swagger-ui/favicon-32x32.png
--------------------------------------------------------------------------------
/backend/swagger-ui/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | Swagger UI
7 |
8 |
9 |
10 |
11 |
30 |
31 |
32 |
33 |
34 |
67 |
68 |
69 |
70 |
71 |
72 |
93 |
94 |
95 |
96 |
--------------------------------------------------------------------------------
/backend/swagger-ui/oauth2-redirect.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
61 |
--------------------------------------------------------------------------------
/fmt.sh:
--------------------------------------------------------------------------------
1 | go fmt ./backend
2 | golint ./backend
3 | go vet ./backend
--------------------------------------------------------------------------------
/vendor/cloud.google.com/go/AUTHORS:
--------------------------------------------------------------------------------
1 | # This is the official list of cloud authors for copyright purposes.
2 | # This file is distinct from the CONTRIBUTORS files.
3 | # See the latter for an explanation.
4 |
5 | # Names should be added to this file as:
6 | # Name or Organization
7 | # The email address is not required for organizations.
8 |
9 | Filippo Valsorda
10 | Google Inc.
11 | Ingo Oeser
12 | Palm Stone Games, Inc.
13 | Paweł Knap
14 | Péter Szilágyi
15 | Tyler Treat
16 |
--------------------------------------------------------------------------------
/vendor/cloud.google.com/go/CONTRIBUTORS:
--------------------------------------------------------------------------------
1 | # People who have agreed to one of the CLAs and can contribute patches.
2 | # The AUTHORS file lists the copyright holders; this file
3 | # lists people. For example, Google employees are listed here
4 | # but not in AUTHORS, because Google holds the copyright.
5 | #
6 | # https://developers.google.com/open-source/cla/individual
7 | # https://developers.google.com/open-source/cla/corporate
8 | #
9 | # Names should be added to this file as:
10 | # Name
11 |
12 | # Keep the list alphabetically sorted.
13 |
14 | Alexis Hunt
15 | Andreas Litt
16 | Andrew Gerrand
17 | Brad Fitzpatrick
18 | Burcu Dogan
19 | Dave Day
20 | David Sansome
21 | David Symonds
22 | Filippo Valsorda
23 | Glenn Lewis
24 | Ingo Oeser
25 | James Hall
26 | Johan Euphrosine
27 | Jonathan Amsterdam
28 | Kunpei Sakai
29 | Luna Duclos
30 | Magnus Hiie
31 | Mario Castro
32 | Michael McGreevy
33 | Omar Jarjur
34 | Paweł Knap
35 | Péter Szilágyi
36 | Sarah Adams
37 | Thanatat Tamtan
38 | Toby Burress
39 | Tuo Shan
40 | Tyler Treat
41 |
--------------------------------------------------------------------------------
/vendor/github.com/favclip/golidator/.gitignore:
--------------------------------------------------------------------------------
1 | .idea/
2 | *.iml
3 |
--------------------------------------------------------------------------------
/vendor/github.com/favclip/golidator/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2016 tv-asahi
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/vendor/github.com/favclip/golidator/README.md:
--------------------------------------------------------------------------------
1 | # golidator
2 |
3 | The programable validator.
4 |
5 | ## Description
6 |
7 | Existing validator is not fully flexible.
8 | We want to customize error object generation.
9 | We want to modify value instead of raise error when validation failed.
10 | We want it.
11 |
12 | ## Samples
13 |
14 | see [usage](https://github.com/favclip/golidator/blob/master/usage_test.go)
15 |
16 | ### Basic usage
17 |
18 | ```
19 | v := golidator.NewValidator()
20 | err := v.Validate(obj)
21 | ```
22 |
23 | ### Use Custom Validator
24 |
25 | ```
26 | v := golidator.NewValidator()
27 | v.SetValidationFunc("req", func(param string, val reflect.Value) (golidator.ValidationResult, error) {
28 | if str := val.String(); str == "" {
29 | return golidator.ValidationNG, nil
30 | }
31 |
32 | return golidator.ValidationOK, nil
33 | })
34 | ```
35 |
--------------------------------------------------------------------------------
/vendor/github.com/favclip/golidator/errors.go:
--------------------------------------------------------------------------------
1 | package golidator
2 |
3 | import (
4 | "bytes"
5 | "errors"
6 | "fmt"
7 | "reflect"
8 | )
9 |
10 | // ErrEmptyValidationName means invalid validator name error.
11 | var ErrEmptyValidationName = errors.New("validator name is required")
12 |
13 | // ErrUnsupportedValue means golidator is not support type of passed value.
14 | var ErrUnsupportedValue = errors.New("unsupported type")
15 |
16 | // ErrValidateUnsupportedType means validator is not support field type.
17 | var ErrValidateUnsupportedType = errors.New("unsupported field type")
18 |
19 | // ErrInvalidConfigValue means config value can't accept by validator.
20 | var ErrInvalidConfigValue = errors.New("invalid configuration value")
21 |
22 | // ErrorReport provides detail of error informations.
23 | type ErrorReport struct {
24 | Root reflect.Value `json:"-"`
25 |
26 | Type string `json:"type"` // fixed value. https://github.com/favclip/golidator
27 | Details []*ErrorDetail `json:"details"`
28 | }
29 |
30 | // ErrorDetail provides error about 1 field.
31 | type ErrorDetail struct {
32 | ParentFieldName string `json:"-"`
33 | Current reflect.Value `json:"-"`
34 | Value reflect.Value `json:"-"`
35 | Field reflect.StructField `json:"-"`
36 |
37 | FieldName string `json:"fieldName"` // e.g. address , person.name
38 | ReasonList []*ErrorReason `json:"reasonList"`
39 | }
40 |
41 | // ErrorReason contains why validation is failed?
42 | type ErrorReason struct {
43 | Type string `json:"type"` // e.g. req , min, enum
44 | Config string `json:"config,omitempty"` // e.g. 1, manual|auto, ^[^@]+@gmail.com$
45 | }
46 |
47 | func (report *ErrorReport) Error() string {
48 | buf := bytes.NewBufferString("invalid. ")
49 |
50 | for t := report.Root.Type(); ; {
51 | switch t.Kind() {
52 | case reflect.Array, reflect.Chan, reflect.Map, reflect.Ptr, reflect.Slice:
53 | t = t.Elem()
54 | continue
55 | }
56 | if name := t.Name(); name != "" {
57 | fmt.Fprint(buf, name, " ")
58 | }
59 | break
60 | }
61 | for idx, detail := range report.Details {
62 | fmt.Fprint(buf, "#", idx+1, " ", detail.FieldName, ": ")
63 | for _, report := range detail.ReasonList {
64 | fmt.Fprint(buf, report.Type)
65 | if report.Config != "" {
66 | fmt.Fprint(buf, "=", report.Config)
67 | }
68 | if detail.Value.Kind() == reflect.String {
69 | fmt.Fprintf(buf, " actual: '%v'", detail.Value.Interface())
70 | } else {
71 | fmt.Fprintf(buf, " actual: %v", detail.Value.Interface())
72 | }
73 | }
74 | if idx != len(report.Details)-1 {
75 | fmt.Fprint(buf, ", ")
76 | }
77 | }
78 |
79 | return buf.String()
80 | }
81 |
--------------------------------------------------------------------------------
/vendor/github.com/favclip/golidator/test.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh -eux
2 |
3 | goimports -w .
4 | go tool vet .
5 | golint ./...
6 | go test ./... $@
7 |
--------------------------------------------------------------------------------
/vendor/github.com/favclip/ucon/.gitignore:
--------------------------------------------------------------------------------
1 | .idea/
2 | *.iml
3 |
--------------------------------------------------------------------------------
/vendor/github.com/favclip/ucon/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2016 tv-asahi
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/vendor/github.com/favclip/ucon/plugin.go:
--------------------------------------------------------------------------------
1 | package ucon
2 |
3 | import "fmt"
4 |
5 | type pluginContainer struct {
6 | base interface{}
7 | }
8 |
9 | // HandlersScannerPlugin is an interface to make a plugin for scanning request handlers.
10 | type HandlersScannerPlugin interface {
11 | HandlersScannerProcess(m *ServeMux, rds []*RouteDefinition) error
12 | }
13 |
14 | func (p *pluginContainer) check() {
15 | if p.HandlersScanner() != nil {
16 | return
17 | }
18 |
19 | panic(fmt.Sprintf("unused plugin: %#v", p.base))
20 | }
21 |
22 | // HandlersScanner returns itself if it implements HandlersScannerPlugin.
23 | func (p *pluginContainer) HandlersScanner() HandlersScannerPlugin {
24 | if v, ok := p.base.(HandlersScannerPlugin); ok {
25 | return v
26 | }
27 |
28 | return nil
29 | }
30 |
31 | type emptyCtx int
32 |
33 | var background = new(emptyCtx)
34 |
35 | func (*emptyCtx) Value(key interface{}) interface{} {
36 | return nil
37 | }
38 |
39 | // Context is a key-value store.
40 | type Context interface {
41 | Value(key interface{}) interface{}
42 | }
43 |
44 | // WithValue returns a new context containing the value.
45 | // Values contained by parent context are inherited.
46 | func WithValue(parent Context, key interface{}, val interface{}) Context {
47 | return &valueCtx{parent, key, val}
48 | }
49 |
50 | type valueCtx struct {
51 | Context
52 | key interface{}
53 | val interface{}
54 | }
55 |
56 | func (c *valueCtx) Value(key interface{}) interface{} {
57 | if c.key == key {
58 | return c.val
59 | }
60 | return c.Context.Value(key)
61 | }
62 |
--------------------------------------------------------------------------------
/vendor/github.com/favclip/ucon/request.go:
--------------------------------------------------------------------------------
1 | package ucon
2 |
3 | import (
4 | "context"
5 | "errors"
6 | "fmt"
7 | "net/http"
8 | "reflect"
9 | )
10 |
11 | // ErrInvalidRequestHandler is the error that Bubble.RequestHandler is not a function.
12 | var ErrInvalidRequestHandler = errors.New("invalid request handler. not function")
13 |
14 | // ErrInvalidArgumentLength is the error that length of Bubble.Arguments does not match to RequestHandler arguments.
15 | var ErrInvalidArgumentLength = errors.New("invalid arguments")
16 |
17 | // ErrInvalidArgumentValue is the error that value in Bubble.Arguments is invalid.
18 | var ErrInvalidArgumentValue = errors.New("invalid argument value")
19 |
20 | // Bubble is a context of data processing that will be passed to a request handler at last.
21 | // The name `Bubble` means that the processing flow is a event-bubbling.
22 | // Processors, called `middleware`, are executed in order with same context, and at last the RequestHandler will be called.
23 | type Bubble struct {
24 | R *http.Request
25 | W http.ResponseWriter
26 | Context context.Context
27 | RequestHandler HandlerContainer
28 |
29 | Debug bool
30 |
31 | Handled bool
32 | ArgumentTypes []reflect.Type
33 | Arguments []reflect.Value
34 | Returns []reflect.Value
35 |
36 | queueIndex int
37 | mux *ServeMux
38 | }
39 |
40 | func (b *Bubble) checkHandlerType() error {
41 | if _, ok := b.RequestHandler.(HandlerContainer); ok {
42 | return nil
43 | }
44 | hv := reflect.ValueOf(b.RequestHandler)
45 | if hv.Type().Kind() == reflect.Func {
46 | return nil
47 | }
48 |
49 | return ErrInvalidRequestHandler
50 | }
51 |
52 | func (b *Bubble) handler() interface{} {
53 | if hv, ok := b.RequestHandler.(HandlerContainer); ok {
54 | return hv.Handler()
55 | }
56 | hv := reflect.ValueOf(b.RequestHandler)
57 | if hv.Type().Kind() == reflect.Func {
58 | return b.RequestHandler
59 | }
60 |
61 | return nil
62 | }
63 |
64 | func (b *Bubble) init(m *ServeMux) error {
65 | err := b.checkHandlerType()
66 | if err != nil {
67 | return err
68 | }
69 |
70 | hv := reflect.ValueOf(b.handler())
71 | numIn := hv.Type().NumIn()
72 | b.ArgumentTypes = make([]reflect.Type, numIn)
73 | for i := 0; i < numIn; i++ {
74 | b.ArgumentTypes[i] = hv.Type().In(i)
75 | }
76 | b.Arguments = make([]reflect.Value, numIn)
77 |
78 | b.mux = m
79 | b.Debug = m.Debug
80 |
81 | return nil
82 | }
83 |
84 | // Next passes the bubble to next middleware.
85 | // If the bubble reaches at last, RequestHandler will be called.
86 | func (b *Bubble) Next() error {
87 | if b.queueIndex < len(b.mux.middlewares) {
88 | qi := b.queueIndex
89 | b.queueIndex++
90 | m := b.mux.middlewares[qi]
91 | err := m(b)
92 | return err
93 | }
94 |
95 | return b.do()
96 | }
97 |
98 | func (b *Bubble) do() error {
99 | hv := reflect.ValueOf(b.handler())
100 |
101 | if len(b.Arguments) != len(b.ArgumentTypes) || len(b.Arguments) != hv.Type().NumIn() {
102 | return ErrInvalidArgumentLength
103 | }
104 | for idx, arg := range b.Arguments {
105 | if !arg.IsValid() {
106 | fmt.Printf("ArgumentInvalid %d\n", idx)
107 | return ErrInvalidArgumentValue
108 | }
109 | if !arg.Type().AssignableTo(hv.Type().In(idx)) {
110 | fmt.Printf("TypeMismatch %d, %+v, %+v\n", idx, b.Arguments[idx], hv.Type().In(idx))
111 | return ErrInvalidArgumentValue
112 | }
113 | }
114 |
115 | b.Returns = hv.Call(b.Arguments)
116 |
117 | b.Handled = true
118 |
119 | return nil
120 | }
121 |
--------------------------------------------------------------------------------
/vendor/github.com/favclip/ucon/routing.go:
--------------------------------------------------------------------------------
1 | // +build go1.7
2 |
3 | package ucon
4 |
5 | import (
6 | "context"
7 | "net/http"
8 | )
9 |
10 | func getDefaultContext(r *http.Request) context.Context {
11 | return r.Context()
12 | }
13 |
--------------------------------------------------------------------------------
/vendor/github.com/favclip/ucon/routing_classic.go:
--------------------------------------------------------------------------------
1 | // +build !go1.7
2 |
3 | package ucon
4 |
5 | import (
6 | "context"
7 | "net/http"
8 | )
9 |
10 | func getDefaultContext(r *http.Request) context.Context {
11 | return context.Background()
12 | }
13 |
--------------------------------------------------------------------------------
/vendor/github.com/favclip/ucon/swagger/jsonschema_draft4.go:
--------------------------------------------------------------------------------
1 | package swagger
2 |
3 | // Schema is https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#schemaObject
4 | type Schema struct {
5 | Ref string `json:"$ref,omitempty"`
6 | Format string `json:"format,omitempty"`
7 | Title string `json:"title,omitempty"`
8 | Description string `json:"description,omitempty"`
9 | Default interface{} `json:"default,omitempty"`
10 | Maximum *int `json:"maximum,omitempty"`
11 | ExclusiveMaximum *bool `json:"exclusiveMaximum,omitempty"`
12 | Minimum *int `json:"minimum,omitempty"`
13 | ExclusiveMinimum *bool `json:"exclusiveMinimum,omitempty"`
14 | MaxLength *int `json:"maxLength,omitempty"`
15 | MinLength *int `json:"minLength,omitempty"`
16 | Pattern string `json:"pattern,omitempty"`
17 | MaxItems *int `json:"maxItems,omitempty"`
18 | MinItems *int `json:"minItems,omitempty"`
19 | UniqueItems *bool `json:"uniqueItems,omitempty"`
20 | MaxProperties *int `json:"maxProperties,omitempty"`
21 | MinProperties *int `json:"minProperties,omitempty"`
22 | Required []string `json:"required,omitempty"`
23 | Enum []interface{} `json:"enum,omitempty"`
24 | Type string `json:"type,omitempty"`
25 | Items *Schema `json:"items,omitempty"`
26 | AllOf []*Schema `json:"allOf,omitempty"`
27 | Properties map[string]*Schema `json:"properties,omitempty"`
28 | AdditionalProperties map[string]*Schema `json:"additionalProperties,omitempty"`
29 | Discriminator string `json:"discriminator,omitempty"`
30 | ReadOnly *bool `json:"readOnly,omitempty"`
31 | // Xml XML
32 | ExternalDocs *ExternalDocumentation `json:"externalDocs,omitempty"`
33 | Example interface{} `json:"example,omitempty"`
34 | }
35 |
36 | // ShallowCopy returns a clone of *Schema.
37 | func (schema *Schema) ShallowCopy() *Schema {
38 | return &Schema{
39 | Ref: schema.Ref,
40 | Format: schema.Format,
41 | Title: schema.Title,
42 | Description: schema.Description,
43 | Default: schema.Default,
44 | Maximum: schema.Maximum,
45 | ExclusiveMaximum: schema.ExclusiveMaximum,
46 | Minimum: schema.Minimum,
47 | ExclusiveMinimum: schema.ExclusiveMinimum,
48 | MaxLength: schema.MaxLength,
49 | MinLength: schema.MinLength,
50 | Pattern: schema.Pattern,
51 | MaxItems: schema.MaxItems,
52 | MinItems: schema.MinItems,
53 | UniqueItems: schema.UniqueItems,
54 | MaxProperties: schema.MaxProperties,
55 | MinProperties: schema.MinProperties,
56 | Required: schema.Required,
57 | Enum: schema.Enum,
58 | Type: schema.Type,
59 | Items: schema.Items,
60 | AllOf: schema.AllOf,
61 | Properties: schema.Properties,
62 | AdditionalProperties: schema.AdditionalProperties,
63 | Discriminator: schema.Discriminator,
64 | ReadOnly: schema.ReadOnly,
65 | ExternalDocs: schema.ExternalDocs,
66 | Example: schema.Example,
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/vendor/github.com/favclip/ucon/swagger/middleware.go:
--------------------------------------------------------------------------------
1 | package swagger
2 |
3 | import (
4 | "fmt"
5 |
6 | "net/http"
7 |
8 | "github.com/favclip/ucon"
9 | )
10 |
11 | var _ ucon.HTTPErrorResponse = &securityError{}
12 | var _ error = &securityError{}
13 |
14 | type securityError struct {
15 | Code int `json:"code"`
16 | Type string `json:"type"`
17 | Message string `json:"message"`
18 | }
19 |
20 | func (ve *securityError) StatusCode() int {
21 | return ve.Code
22 | }
23 |
24 | func (ve *securityError) ErrorMessage() interface{} {
25 | return ve
26 | }
27 |
28 | func (ve *securityError) Error() string {
29 | return fmt.Sprintf("status code %d: %v", ve.StatusCode(), ve.Message)
30 | }
31 |
32 | func newSecurityError(code int, message string) *securityError {
33 | return &securityError{
34 | Code: code,
35 | Type: "https://github.com/favclip/ucon#swagger-security",
36 | Message: message,
37 | }
38 | }
39 |
40 | var (
41 | // ErrSecurityDefinitionsIsRequired is returned when security definition is missing in object or path items.
42 | ErrSecurityDefinitionsIsRequired = newSecurityError(http.StatusInternalServerError, "swagger: SecurityDefinitions is required")
43 | // ErrSecuritySettingsAreWrong is returned when required scope is missing in object or path items.
44 | ErrSecuritySettingsAreWrong = newSecurityError(http.StatusInternalServerError, "swagger: security settings are wrong")
45 | // ErrNotImplemented is returned when specified type is not implemented.
46 | ErrNotImplemented = newSecurityError(http.StatusInternalServerError, "swagger: not implemented")
47 | // ErrAccessDenied is returned when access user doesn't have a access grant.
48 | ErrAccessDenied = newSecurityError(http.StatusUnauthorized, "swagger: access denied")
49 | )
50 |
51 | // CheckSecurityRequirements about request.
52 | func CheckSecurityRequirements(obj *Object, getScopes func(b *ucon.Bubble) ([]string, error)) ucon.MiddlewareFunc {
53 |
54 | return func(b *ucon.Bubble) error {
55 | op, ok := b.RequestHandler.Value(swaggerOperationKey{}).(*Operation)
56 | if !ok {
57 | return b.Next()
58 | }
59 |
60 | var secReqs []SecurityRequirement
61 | if op.Security != nil {
62 | // If len(op.Security) == 0, It overwrite top-level definition.
63 | // check by != nil.
64 | secReqs = op.Security
65 |
66 | } else {
67 | secReqs = obj.Security
68 | }
69 |
70 | // check security. It is ok if any one of the security passes.
71 | passed := false
72 | for _, req := range secReqs {
73 | sec_type:
74 | for name, oauth2ReqScopes := range req {
75 | if obj.SecurityDefinitions == nil {
76 | return ErrSecurityDefinitionsIsRequired
77 | }
78 |
79 | scheme, ok := obj.SecurityDefinitions[name]
80 | if !ok {
81 | return ErrSecurityDefinitionsIsRequired
82 | }
83 |
84 | switch scheme.Type {
85 | case "oauth2":
86 | scopes, err := getScopes(b)
87 | if err != nil {
88 | return err
89 | }
90 |
91 | // all scopes are required.
92 | outer:
93 | for _, reqScope := range oauth2ReqScopes {
94 | for _, scope := range scopes {
95 | if scope == reqScope {
96 | continue outer
97 | }
98 | }
99 |
100 | continue sec_type
101 | }
102 |
103 | passed = true
104 |
105 | case "basic":
106 | fallthrough
107 | case "apiKey":
108 | fallthrough
109 | default:
110 | if len(oauth2ReqScopes) != 0 {
111 | return ErrSecuritySettingsAreWrong
112 | }
113 |
114 | return ErrNotImplemented
115 | }
116 | }
117 | }
118 | if passed {
119 | return b.Next()
120 | }
121 |
122 | return ErrAccessDenied
123 | }
124 | }
125 |
--------------------------------------------------------------------------------
/vendor/github.com/favclip/ucon/swagger/validator.go:
--------------------------------------------------------------------------------
1 | package swagger
2 |
3 | import (
4 | "fmt"
5 | "reflect"
6 |
7 | "github.com/favclip/golidator"
8 | "github.com/favclip/ucon"
9 | )
10 |
11 | // DefaultValidator used in RequestValidator.
12 | var DefaultValidator ucon.Validator
13 |
14 | var _ ucon.HTTPErrorResponse = &validateError{}
15 | var _ error = &validateError{}
16 |
17 | type validateError struct {
18 | Code int `json:"code"`
19 | Origin error `json:"-"`
20 | }
21 |
22 | type validateMessage struct {
23 | Type string `json:"type"`
24 | Message string `json:"message"`
25 | }
26 |
27 | func (ve *validateError) StatusCode() int {
28 | return ve.Code
29 | }
30 |
31 | func (ve *validateError) ErrorMessage() interface{} {
32 | return &validateMessage{
33 | Type: "https://github.com/favclip/ucon#swagger-validate",
34 | Message: ve.Origin.Error(),
35 | }
36 | }
37 |
38 | func (ve *validateError) Error() string {
39 | if ve.Origin != nil {
40 | return ve.Origin.Error()
41 | }
42 | return fmt.Sprintf("status code %d: %v", ve.StatusCode(), ve.ErrorMessage())
43 | }
44 |
45 | // RequestValidator checks request object validity by swagger tag.
46 | func RequestValidator() ucon.MiddlewareFunc {
47 | return ucon.RequestValidator(DefaultValidator)
48 | }
49 |
50 | func init() {
51 | v := &golidator.Validator{}
52 | v.SetTag("swagger")
53 |
54 | v.SetValidationFunc("req", golidator.ReqValidator)
55 | v.SetValidationFunc("d", golidator.DefaultValidator)
56 | v.SetValidationFunc("enum", golidator.EnumValidator)
57 |
58 | // TODO emit to swagger.json
59 | v.SetValidationFunc("min", golidator.MinValidator)
60 | v.SetValidationFunc("max", golidator.MaxValidator)
61 | v.SetValidationFunc("minLen", golidator.MinLenValidator)
62 | v.SetValidationFunc("maxLen", golidator.MaxLenValidator)
63 |
64 | // ignore in=path, in=query pattern
65 | v.SetValidationFunc("in", func(param string, v reflect.Value) (golidator.ValidationResult, error) {
66 | return golidator.ValidationOK, nil
67 | })
68 |
69 | DefaultValidator = v
70 | }
71 |
--------------------------------------------------------------------------------
/vendor/github.com/favclip/ucon/test.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh -eux
2 |
3 | goimports -w .
4 | go generate ./...
5 | go tool vet .
6 | golint .
7 | golint swagger
8 | go test ./... $@
9 |
--------------------------------------------------------------------------------
/vendor/github.com/favclip/ucon/test_utils.go:
--------------------------------------------------------------------------------
1 | package ucon
2 |
3 | import (
4 | "context"
5 | "io"
6 | "net/http"
7 | "net/http/httptest"
8 | "net/url"
9 | "testing"
10 | )
11 |
12 | // BubbleTestOption is an option for setting a mock request.
13 | type BubbleTestOption struct {
14 | Method string
15 | URL string
16 | Body io.Reader
17 | MiddlewareContext Context
18 | }
19 |
20 | // MakeMiddlewareTestBed returns a Bubble and ServeMux for handling the request made from the option.
21 | func MakeMiddlewareTestBed(t *testing.T, middleware MiddlewareFunc, handler interface{}, opts *BubbleTestOption) (*Bubble, *ServeMux) {
22 | if opts == nil {
23 | opts = &BubbleTestOption{
24 | Method: "GET",
25 | URL: "/api/tmp",
26 | }
27 | }
28 | if opts.MiddlewareContext == nil {
29 | opts.MiddlewareContext = background
30 | }
31 | mux := NewServeMux()
32 | mux.Middleware(middleware)
33 |
34 | r, err := http.NewRequest(opts.Method, opts.URL, opts.Body)
35 | if err != nil {
36 | t.Fatal(err)
37 | }
38 |
39 | if opts.Body != nil {
40 | r.Header.Add("Content-Type", "application/json")
41 | }
42 |
43 | w := httptest.NewRecorder()
44 |
45 | u, err := url.Parse(opts.URL)
46 | if err != nil {
47 | t.Fatal(err)
48 | }
49 |
50 | rd := &RouteDefinition{
51 | Method: opts.Method,
52 | PathTemplate: ParsePathTemplate(u.Path),
53 | HandlerContainer: &handlerContainerImpl{
54 | handler: handler,
55 | Context: opts.MiddlewareContext,
56 | },
57 | }
58 |
59 | b, err := mux.newBubble(context.Background(), w, r, rd)
60 | if err != nil {
61 | t.Fatal(err)
62 | }
63 |
64 | return b, mux
65 | }
66 |
67 | // MakeHandlerTestBed returns a response by the request made from arguments.
68 | // To test some handlers, those must be registered by Handle or HandleFunc before calling this.
69 | func MakeHandlerTestBed(t *testing.T, method string, path string, body io.Reader) *http.Response {
70 | ts := httptest.NewServer(DefaultMux)
71 | defer ts.Close()
72 |
73 | reqURL, err := url.Parse(ts.URL)
74 | if err != nil {
75 | t.Fatal(err)
76 | }
77 | reqURL, err = reqURL.Parse(path)
78 | if err != nil {
79 | t.Fatal(err)
80 | }
81 |
82 | req, err := http.NewRequest(method, reqURL.String(), body)
83 | if err != nil {
84 | t.Fatal(err)
85 | }
86 | if body != nil {
87 | req.Header.Add("Content-Type", "application/json")
88 | }
89 | resp, err := http.DefaultClient.Do(req)
90 | if err != nil {
91 | t.Fatal(err)
92 | }
93 |
94 | return resp
95 | }
96 |
--------------------------------------------------------------------------------
/vendor/github.com/favclip/ucon/url_rawpath.go:
--------------------------------------------------------------------------------
1 | // +build go1.5
2 |
3 | package ucon
4 |
5 | import (
6 | "net/http"
7 | )
8 |
9 | func encodedPathFromRequest(r *http.Request) string {
10 | return r.URL.EscapedPath()
11 | }
12 |
--------------------------------------------------------------------------------
/vendor/github.com/favclip/ucon/url_rawpath_go14.go:
--------------------------------------------------------------------------------
1 | // +build !go1.5
2 |
3 | package ucon
4 |
5 | import (
6 | "net/http"
7 | )
8 |
9 | func encodedPathFromRequest(r *http.Request) string {
10 | // url.EscapedPath() が欲しいがappengine環境下ではgo1.4で元データが存在しないのでごまかす /page/foo%2Fbar みたいな構造がうまく処理できない 解決は不可能という認識…
11 | // r.RequestURI から自力で頑張ればイケる…??
12 | return r.URL.Path
13 | }
14 |
--------------------------------------------------------------------------------
/vendor/github.com/golang/protobuf/AUTHORS:
--------------------------------------------------------------------------------
1 | # This source code refers to The Go Authors for copyright purposes.
2 | # The master list of authors is in the main Go distribution,
3 | # visible at http://tip.golang.org/AUTHORS.
4 |
--------------------------------------------------------------------------------
/vendor/github.com/golang/protobuf/CONTRIBUTORS:
--------------------------------------------------------------------------------
1 | # This source code was written by the Go contributors.
2 | # The master list of contributors is in the main Go distribution,
3 | # visible at http://tip.golang.org/CONTRIBUTORS.
4 |
--------------------------------------------------------------------------------
/vendor/github.com/golang/protobuf/LICENSE:
--------------------------------------------------------------------------------
1 | Go support for Protocol Buffers - Google's data interchange format
2 |
3 | Copyright 2010 The Go Authors. All rights reserved.
4 | https://github.com/golang/protobuf
5 |
6 | Redistribution and use in source and binary forms, with or without
7 | modification, are permitted provided that the following conditions are
8 | met:
9 |
10 | * Redistributions of source code must retain the above copyright
11 | notice, this list of conditions and the following disclaimer.
12 | * Redistributions in binary form must reproduce the above
13 | copyright notice, this list of conditions and the following disclaimer
14 | in the documentation and/or other materials provided with the
15 | distribution.
16 | * Neither the name of Google Inc. nor the names of its
17 | contributors may be used to endorse or promote products derived from
18 | this software without specific prior written permission.
19 |
20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 |
32 |
--------------------------------------------------------------------------------
/vendor/github.com/golang/protobuf/proto/Makefile:
--------------------------------------------------------------------------------
1 | # Go support for Protocol Buffers - Google's data interchange format
2 | #
3 | # Copyright 2010 The Go Authors. All rights reserved.
4 | # https://github.com/golang/protobuf
5 | #
6 | # Redistribution and use in source and binary forms, with or without
7 | # modification, are permitted provided that the following conditions are
8 | # met:
9 | #
10 | # * Redistributions of source code must retain the above copyright
11 | # notice, this list of conditions and the following disclaimer.
12 | # * Redistributions in binary form must reproduce the above
13 | # copyright notice, this list of conditions and the following disclaimer
14 | # in the documentation and/or other materials provided with the
15 | # distribution.
16 | # * Neither the name of Google Inc. nor the names of its
17 | # contributors may be used to endorse or promote products derived from
18 | # this software without specific prior written permission.
19 | #
20 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 | # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 | # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 | # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 |
32 | install:
33 | go install
34 |
35 | test: install generate-test-pbs
36 | go test
37 |
38 |
39 | generate-test-pbs:
40 | make install
41 | make -C testdata
42 | protoc --go_out=Mtestdata/test.proto=github.com/golang/protobuf/proto/testdata,Mgoogle/protobuf/any.proto=github.com/golang/protobuf/ptypes/any:. proto3_proto/proto3.proto
43 | make
44 |
--------------------------------------------------------------------------------
/vendor/github.com/pkg/errors/.gitignore:
--------------------------------------------------------------------------------
1 | # Compiled Object files, Static and Dynamic libs (Shared Objects)
2 | *.o
3 | *.a
4 | *.so
5 |
6 | # Folders
7 | _obj
8 | _test
9 |
10 | # Architecture specific extensions/prefixes
11 | *.[568vq]
12 | [568vq].out
13 |
14 | *.cgo1.go
15 | *.cgo2.c
16 | _cgo_defun.c
17 | _cgo_gotypes.go
18 | _cgo_export.*
19 |
20 | _testmain.go
21 |
22 | *.exe
23 | *.test
24 | *.prof
25 |
--------------------------------------------------------------------------------
/vendor/github.com/pkg/errors/.travis.yml:
--------------------------------------------------------------------------------
1 | language: go
2 | go_import_path: github.com/pkg/errors
3 | go:
4 | - 1.4.3
5 | - 1.5.4
6 | - 1.6.2
7 | - 1.7.1
8 | - tip
9 |
10 | script:
11 | - go test -v ./...
12 |
--------------------------------------------------------------------------------
/vendor/github.com/pkg/errors/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright (c) 2015, Dave Cheney
2 | All rights reserved.
3 |
4 | Redistribution and use in source and binary forms, with or without
5 | modification, are permitted provided that the following conditions are met:
6 |
7 | * Redistributions of source code must retain the above copyright notice, this
8 | list of conditions and the following disclaimer.
9 |
10 | * Redistributions in binary form must reproduce the above copyright notice,
11 | this list of conditions and the following disclaimer in the documentation
12 | and/or other materials provided with the distribution.
13 |
14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
15 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
18 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
20 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
21 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
22 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 |
--------------------------------------------------------------------------------
/vendor/github.com/pkg/errors/README.md:
--------------------------------------------------------------------------------
1 | # errors [](https://travis-ci.org/pkg/errors) [](https://ci.appveyor.com/project/davecheney/errors/branch/master) [](http://godoc.org/github.com/pkg/errors) [](https://goreportcard.com/report/github.com/pkg/errors)
2 |
3 | Package errors provides simple error handling primitives.
4 |
5 | `go get github.com/pkg/errors`
6 |
7 | The traditional error handling idiom in Go is roughly akin to
8 | ```go
9 | if err != nil {
10 | return err
11 | }
12 | ```
13 | which applied recursively up the call stack results in error reports without context or debugging information. The errors package allows programmers to add context to the failure path in their code in a way that does not destroy the original value of the error.
14 |
15 | ## Adding context to an error
16 |
17 | The errors.Wrap function returns a new error that adds context to the original error. For example
18 | ```go
19 | _, err := ioutil.ReadAll(r)
20 | if err != nil {
21 | return errors.Wrap(err, "read failed")
22 | }
23 | ```
24 | ## Retrieving the cause of an error
25 |
26 | Using `errors.Wrap` constructs a stack of errors, adding context to the preceding error. Depending on the nature of the error it may be necessary to reverse the operation of errors.Wrap to retrieve the original error for inspection. Any error value which implements this interface can be inspected by `errors.Cause`.
27 | ```go
28 | type causer interface {
29 | Cause() error
30 | }
31 | ```
32 | `errors.Cause` will recursively retrieve the topmost error which does not implement `causer`, which is assumed to be the original cause. For example:
33 | ```go
34 | switch err := errors.Cause(err).(type) {
35 | case *MyError:
36 | // handle specifically
37 | default:
38 | // unknown error
39 | }
40 | ```
41 |
42 | [Read the package documentation for more information](https://godoc.org/github.com/pkg/errors).
43 |
44 | ## Contributing
45 |
46 | We welcome pull requests, bug fixes and issue reports. With that said, the bar for adding new symbols to this package is intentionally set high.
47 |
48 | Before proposing a change, please discuss your change by raising an issue.
49 |
50 | ## Licence
51 |
52 | BSD-2-Clause
53 |
--------------------------------------------------------------------------------
/vendor/github.com/pkg/errors/appveyor.yml:
--------------------------------------------------------------------------------
1 | version: build-{build}.{branch}
2 |
3 | clone_folder: C:\gopath\src\github.com\pkg\errors
4 | shallow_clone: true # for startup speed
5 |
6 | environment:
7 | GOPATH: C:\gopath
8 |
9 | platform:
10 | - x64
11 |
12 | # http://www.appveyor.com/docs/installed-software
13 | install:
14 | # some helpful output for debugging builds
15 | - go version
16 | - go env
17 | # pre-installed MinGW at C:\MinGW is 32bit only
18 | # but MSYS2 at C:\msys64 has mingw64
19 | - set PATH=C:\msys64\mingw64\bin;%PATH%
20 | - gcc --version
21 | - g++ --version
22 |
23 | build_script:
24 | - go install -v ./...
25 |
26 | test_script:
27 | - set PATH=C:\gopath\bin;%PATH%
28 | - go test -v ./...
29 |
30 | #artifacts:
31 | # - path: '%GOPATH%\bin\*.exe'
32 | deploy: off
33 |
--------------------------------------------------------------------------------
/vendor/go.mercari.io/datastore/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 |
3 | .idea/
4 |
5 | node_modules/
6 |
7 | vendor/
8 | build-cmd/
9 |
--------------------------------------------------------------------------------
/vendor/go.mercari.io/datastore/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | # Contributing
2 |
3 | Please read the CLA below carefully before submitting your contribution.
4 |
5 | https://www.mercari.com/cla/
6 |
--------------------------------------------------------------------------------
/vendor/go.mercari.io/datastore/Gopkg.toml:
--------------------------------------------------------------------------------
1 | # Refer to https://github.com/golang/dep/blob/master/docs/Gopkg.toml.md
2 | # for detailed Gopkg.toml documentation.
3 |
4 | required = [
5 | "golang.org/x/tools/cmd/goimports",
6 | "github.com/golang/lint/golint",
7 | "honnef.co/go/tools/cmd/gosimple",
8 | "honnef.co/go/tools/cmd/staticcheck",
9 | "honnef.co/go/tools/cmd/unused",
10 | "github.com/favclip/jwg",
11 | "github.com/favclip/qbg"
12 | ]
13 |
14 | [[constraint]]
15 | name = "cloud.google.com/go"
16 | version = "^0.16.0"
17 |
18 | [[constraint]]
19 | branch = "master"
20 | name = "github.com/golang/protobuf"
21 |
22 | [[constraint]]
23 | branch = "master"
24 | name = "golang.org/x/net"
25 |
26 | [[constraint]]
27 | branch = "master"
28 | name = "golang.org/x/oauth2"
29 |
30 | [[constraint]]
31 | branch = "master"
32 | name = "golang.org/x/sync"
33 |
34 | [[constraint]]
35 | branch = "master"
36 | name = "google.golang.org/api"
37 |
38 | [[constraint]]
39 | branch = "master"
40 | name = "google.golang.org/appengine"
41 |
42 | [[constraint]]
43 | branch = "master"
44 | name = "github.com/favclip/testerator"
45 |
--------------------------------------------------------------------------------
/vendor/go.mercari.io/datastore/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright (c) 2017 Mercari, Inc.
2 |
3 | MIT License
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining
6 | a copy of this software and associated documentation files (the
7 | "Software"), to deal in the Software without restriction, including
8 | without limitation the rights to use, copy, modify, merge, publish,
9 | distribute, sublicense, and/or sell copies of the Software, and to
10 | permit persons to whom the Software is furnished to do so, subject to
11 | the following conditions:
12 |
13 | The above copyright notice and this permission notice shall be
14 | included in all copies or substantial portions of the Software.
15 |
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 |
--------------------------------------------------------------------------------
/vendor/go.mercari.io/datastore/LICENSE.goon:
--------------------------------------------------------------------------------
1 | ========================================================================
2 | For github.com/mjibson/goon
3 | boom/boom.go
4 | ========================================================================
5 |
6 | Copyright (c) 2012 Matt Jibson
7 |
8 | Permission to use, copy, modify, and distribute this software for any
9 | purpose with or without fee is hereby granted, provided that the above
10 | copyright notice and this permission notice appear in all copies.
11 |
12 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
13 | WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
14 | MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
15 | ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
16 | WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
17 | ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
18 | OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19 |
--------------------------------------------------------------------------------
/vendor/go.mercari.io/datastore/aedatastore/doc.go:
--------------------------------------------------------------------------------
1 | package aedatastore // import "go.mercari.io/datastore/aedatastore"
2 |
--------------------------------------------------------------------------------
/vendor/go.mercari.io/datastore/aedatastore/key.go:
--------------------------------------------------------------------------------
1 | package aedatastore
2 |
3 | import (
4 | "context"
5 |
6 | w "go.mercari.io/datastore"
7 | "google.golang.org/appengine/datastore"
8 | )
9 |
10 | var _ w.Key = (*keyImpl)(nil)
11 | var _ w.PendingKey = (*pendingKeyImpl)(nil)
12 |
13 | type keyImpl struct {
14 | ctx context.Context
15 | kind string
16 | id int64
17 | name string
18 | parent *keyImpl
19 | namespace string
20 | }
21 |
22 | type pendingKeyImpl struct {
23 | ctx context.Context
24 | key *datastore.Key
25 | }
26 |
27 | type contextPendingKey struct{}
28 |
29 | func (k *keyImpl) Kind() string {
30 | if k == nil {
31 | panic("k is nil")
32 | }
33 | return k.kind
34 | }
35 |
36 | func (k *keyImpl) ID() int64 {
37 | return k.id
38 | }
39 |
40 | func (k *keyImpl) Name() string {
41 | return k.name
42 | }
43 |
44 | func (k *keyImpl) ParentKey() w.Key {
45 | if k.parent == nil {
46 | return nil
47 | }
48 | return k.parent
49 | }
50 |
51 | func (k *keyImpl) Namespace() string {
52 | return k.namespace
53 | }
54 |
55 | func (k *keyImpl) SetNamespace(namespace string) {
56 | k.namespace = namespace
57 | }
58 |
59 | func (k *keyImpl) String() string {
60 | // TODO 手で実装しなおしたほうがいいかも 互換性のため
61 | return toOriginalKey(k).String()
62 | }
63 |
64 | func (k *keyImpl) GobEncode() ([]byte, error) {
65 | // TODO 手で実装しなおしたほうがいいかも 互換性のため
66 | return toOriginalKey(k).GobEncode()
67 | }
68 |
69 | func (k *keyImpl) GobDecode(buf []byte) error {
70 | // TODO 手で実装しなおしたほうがいいかも 互換性のため
71 |
72 | origKey := &datastore.Key{}
73 | err := origKey.GobDecode(buf)
74 | if err != nil {
75 | return err
76 | }
77 |
78 | k.kind = origKey.Kind()
79 | k.id = origKey.IntID()
80 | k.name = origKey.StringID()
81 | k.parent = toWrapperKey(k.ctx, origKey.Parent())
82 | k.namespace = origKey.Namespace()
83 |
84 | return nil
85 | }
86 |
87 | func (k *keyImpl) MarshalJSON() ([]byte, error) {
88 | // TODO 手で実装しなおしたほうがいいかも 互換性のため
89 |
90 | return toOriginalKey(k).MarshalJSON()
91 | }
92 |
93 | func (k *keyImpl) UnmarshalJSON(buf []byte) error {
94 | // TODO 手で実装しなおしたほうがいいかも 互換性のため
95 |
96 | origKey := &datastore.Key{}
97 | err := origKey.UnmarshalJSON(buf)
98 | if err != nil {
99 | return err
100 | }
101 |
102 | k.kind = origKey.Kind()
103 | k.id = origKey.IntID()
104 | k.name = origKey.StringID()
105 | k.parent = toWrapperKey(k.ctx, origKey.Parent())
106 | k.namespace = origKey.Namespace()
107 |
108 | return nil
109 | }
110 |
111 | func (k *keyImpl) Encode() string {
112 | return toOriginalKey(k).Encode()
113 | }
114 |
115 | func (k *keyImpl) Equal(o w.Key) bool {
116 | var a w.Key = k
117 | var b = o
118 | for {
119 | if a == nil && b == nil {
120 | return true
121 | } else if a != nil && b == nil {
122 | return false
123 | } else if a == nil && b != nil {
124 | return false
125 | }
126 | if a.Kind() != b.Kind() || a.Name() != b.Name() || a.ID() != b.ID() || a.Namespace() != b.Namespace() {
127 | return false
128 | }
129 |
130 | // NOTE Don't checking appID. align to Cloud Datastore API.
131 |
132 | a = a.ParentKey()
133 | b = b.ParentKey()
134 | }
135 | }
136 |
137 | func (k *keyImpl) Incomplete() bool {
138 | return k.Name() == "" && k.ID() == 0
139 | }
140 |
141 | func (p *pendingKeyImpl) StoredContext() context.Context {
142 | return context.WithValue(p.ctx, contextPendingKey{}, p)
143 | }
144 |
--------------------------------------------------------------------------------
/vendor/go.mercari.io/datastore/app.yaml:
--------------------------------------------------------------------------------
1 | runtime: go
2 | api_version: go1.9
3 |
4 | handlers:
5 | - url: /.*
6 | script: _go_app
7 |
--------------------------------------------------------------------------------
/vendor/go.mercari.io/datastore/build-in-docker.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash -eux
2 |
3 | docker build -t mercari/datastore .
4 | docker run -t --rm \
5 | -v $(pwd):/go/src/go.mercari.io/datastore \
6 | mercari/datastore \
7 | /bin/bash -ci "cd /go/src/go.mercari.io/datastore && ./setup.sh && (./serve.sh > /dev/null 2>&1 &) && ./test.sh"
8 |
--------------------------------------------------------------------------------
/vendor/go.mercari.io/datastore/caches.go:
--------------------------------------------------------------------------------
1 | package datastore
2 |
3 | import (
4 | "bytes"
5 | "context"
6 | "fmt"
7 | "strconv"
8 | "strings"
9 | )
10 |
11 | type Middleware interface {
12 | AllocateIDs(info *MiddlewareInfo, keys []Key) ([]Key, error)
13 | PutMultiWithoutTx(info *MiddlewareInfo, keys []Key, psList []PropertyList) ([]Key, error)
14 | PutMultiWithTx(info *MiddlewareInfo, keys []Key, psList []PropertyList) ([]PendingKey, error)
15 | GetMultiWithoutTx(info *MiddlewareInfo, keys []Key, psList []PropertyList) error
16 | GetMultiWithTx(info *MiddlewareInfo, keys []Key, psList []PropertyList) error
17 | DeleteMultiWithoutTx(info *MiddlewareInfo, keys []Key) error
18 | DeleteMultiWithTx(info *MiddlewareInfo, keys []Key) error
19 | PostCommit(info *MiddlewareInfo, tx Transaction, commit Commit) error
20 | PostRollback(info *MiddlewareInfo, tx Transaction) error
21 | Run(info *MiddlewareInfo, q Query, qDump *QueryDump) Iterator
22 | GetAll(info *MiddlewareInfo, q Query, qDump *QueryDump, psList *[]PropertyList) ([]Key, error)
23 | Next(info *MiddlewareInfo, q Query, qDump *QueryDump, iter Iterator, ps *PropertyList) (Key, error)
24 | Count(info *MiddlewareInfo, q Query, qDump *QueryDump) (int, error)
25 | }
26 |
27 | type MiddlewareInfo struct {
28 | Context context.Context
29 | Client Client
30 | Transaction Transaction
31 | Next Middleware
32 | }
33 |
34 | type QueryDump struct {
35 | Kind string
36 | Ancestor Key
37 | EventualConsistency bool
38 | Namespace string
39 | Transaction Transaction
40 | Filter []*QueryFilterCondition
41 | Order []string
42 | Project []string
43 | Distinct bool
44 | KeysOnly bool
45 | Limit int
46 | Offset int
47 | Start Cursor
48 | End Cursor
49 | }
50 |
51 | func (dump *QueryDump) String() string {
52 | // generate keys that are unique for queries
53 | // TODO ProjectID...?
54 |
55 | b := bytes.NewBufferString("v1:") // encoding format version
56 | b.WriteString(dump.Kind)
57 |
58 | if dump.Ancestor != nil {
59 | b.WriteString("&a=")
60 | b.WriteString(dump.Ancestor.String())
61 | }
62 |
63 | if dump.EventualConsistency {
64 | b.WriteString("&e=t")
65 | }
66 |
67 | if dump.Namespace != "" {
68 | b.WriteString("&n=")
69 | b.WriteString(dump.Namespace)
70 | }
71 |
72 | if dump.Transaction != nil {
73 | b.WriteString("&t=t")
74 | }
75 |
76 | if l := len(dump.Filter); l != 0 {
77 | b.WriteString("&f=")
78 | for idx, f := range dump.Filter {
79 | b.WriteString(f.Filter)
80 | b.WriteString(fmt.Sprintf("%+v", f.Value))
81 | if (idx + 1) != l {
82 | b.WriteString("|")
83 | }
84 | }
85 | }
86 | if l := len(dump.Order); l != 0 {
87 | b.WriteString("&or=")
88 | b.WriteString(strings.Join(dump.Order, "|"))
89 | }
90 | if l := len(dump.Project); l != 0 {
91 | b.WriteString("&p=")
92 | b.WriteString(strings.Join(dump.Project, "|"))
93 | }
94 | if dump.Distinct {
95 | b.WriteString("&d=t")
96 | }
97 | if dump.KeysOnly {
98 | b.WriteString("&k=t")
99 | }
100 | if dump.Limit != 0 {
101 | b.WriteString("&l=")
102 | b.WriteString(strconv.Itoa(dump.Limit))
103 | }
104 | if dump.Offset != 0 {
105 | b.WriteString("&o=")
106 | b.WriteString(strconv.Itoa(dump.Offset))
107 | }
108 | if dump.Start != nil {
109 | b.WriteString("&s=")
110 | b.WriteString(dump.Start.String())
111 | }
112 | if dump.End != nil {
113 | b.WriteString("&e=")
114 | b.WriteString(dump.End.String())
115 | }
116 |
117 | return b.String()
118 | }
119 |
120 | type QueryFilterCondition struct {
121 | Filter string
122 | Value interface{}
123 | }
124 |
--------------------------------------------------------------------------------
/vendor/go.mercari.io/datastore/doc.go:
--------------------------------------------------------------------------------
1 | package datastore // import "go.mercari.io/datastore"
2 |
--------------------------------------------------------------------------------
/vendor/go.mercari.io/datastore/docker-compose.yml:
--------------------------------------------------------------------------------
1 | version: "3"
2 | services:
3 | dsemu:
4 | image: google/cloud-sdk:193.0.0
5 | ports:
6 | - "8081:8081"
7 | command: gcloud --project=datastore-wrapper beta emulators datastore start --host-port=0.0.0.0:8081 --no-store-on-disk --consistency=1.0
8 |
9 | redis:
10 | image: redis:alpine
11 | ports:
12 | - "6379:6379"
13 |
--------------------------------------------------------------------------------
/vendor/go.mercari.io/datastore/errors.go:
--------------------------------------------------------------------------------
1 | // Copyright 2014 Google Inc. All Rights Reserved.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | // This file provides error functions for common API failure modes.
16 |
17 | package datastore
18 |
19 | import (
20 | "errors"
21 | "fmt"
22 | "reflect"
23 | )
24 |
25 | var (
26 | ErrInvalidEntityType = errors.New("datastore: invalid entity type")
27 | ErrInvalidKey = errors.New("datastore: invalid key")
28 | ErrNoSuchEntity = errors.New("datastore: no such entity")
29 | )
30 |
31 | // ErrFieldMismatch is returned when a field is to be loaded into a different
32 | // type than the one it was stored from, or when a field is missing or
33 | // unexported in the destination struct.
34 | // StructType is the type of the struct pointed to by the destination argument
35 | // passed to Get or to Iterator.Next.
36 | type ErrFieldMismatch struct {
37 | StructType reflect.Type
38 | FieldName string
39 | Reason string
40 | }
41 |
42 | func (e *ErrFieldMismatch) Error() string {
43 | return fmt.Sprintf("datastore: cannot load field %q into a %q: %s",
44 | e.FieldName, e.StructType, e.Reason)
45 | }
46 |
47 | var ErrConcurrentTransaction = errors.New("datastore: concurrent transaction")
48 |
49 | // MultiError is returned by batch operations when there are errors with
50 | // particular elements. Errors will be in a one-to-one correspondence with
51 | // the input elements; successful elements will have a nil entry.
52 | type MultiError []error
53 |
54 | func (m MultiError) Error() string {
55 | s, n := "", 0
56 | for _, e := range m {
57 | if e != nil {
58 | if n == 0 {
59 | s = e.Error()
60 | }
61 | n++
62 | }
63 | }
64 | switch n {
65 | case 0:
66 | return "(0 errors)"
67 | case 1:
68 | return s
69 | case 2:
70 | return s + " (and 1 other error)"
71 | }
72 | return fmt.Sprintf("%s (and %d other errors)", s, n-1)
73 | }
74 |
--------------------------------------------------------------------------------
/vendor/go.mercari.io/datastore/export.go:
--------------------------------------------------------------------------------
1 | package datastore
2 |
3 | import (
4 | "encoding/gob"
5 | "time"
6 | )
7 |
8 | var LoadEntity = loadEntity
9 | var SaveEntity = saveEntity
10 |
11 | func init() {
12 | gob.Register(time.Time{})
13 | gob.Register(&Entity{})
14 | gob.Register(GeoPoint{})
15 | gob.Register([]interface{}{})
16 | }
17 |
--------------------------------------------------------------------------------
/vendor/go.mercari.io/datastore/interfaces.go:
--------------------------------------------------------------------------------
1 | package datastore
2 |
3 | import (
4 | "context"
5 | )
6 |
7 | var FromContext ClientGenerator
8 |
9 | type ClientGenerator func(ctx context.Context, opts ...ClientOption) (Client, error)
10 |
11 | type Client interface {
12 | Get(ctx context.Context, key Key, dst interface{}) error
13 | GetMulti(ctx context.Context, keys []Key, dst interface{}) error
14 | Put(ctx context.Context, key Key, src interface{}) (Key, error)
15 | PutMulti(ctx context.Context, keys []Key, src interface{}) ([]Key, error)
16 | Delete(ctx context.Context, key Key) error
17 | DeleteMulti(ctx context.Context, keys []Key) error
18 |
19 | NewTransaction(ctx context.Context) (Transaction, error)
20 | RunInTransaction(ctx context.Context, f func(tx Transaction) error) (Commit, error)
21 | Run(ctx context.Context, q Query) Iterator
22 | AllocateIDs(ctx context.Context, keys []Key) ([]Key, error)
23 | Count(ctx context.Context, q Query) (int, error)
24 | GetAll(ctx context.Context, q Query, dst interface{}) ([]Key, error)
25 |
26 | IncompleteKey(kind string, parent Key) Key
27 | NameKey(kind, name string, parent Key) Key
28 | IDKey(kind string, id int64, parent Key) Key
29 |
30 | NewQuery(kind string) Query
31 |
32 | Close() error
33 |
34 | DecodeKey(encoded string) (Key, error)
35 | DecodeCursor(s string) (Cursor, error)
36 |
37 | Batch() *Batch
38 | AppendMiddleware(middleware Middleware) // NOTE First-In First-Apply
39 | RemoveMiddleware(middleware Middleware) bool
40 | Context() context.Context
41 | SetContext(ctx context.Context)
42 | }
43 |
44 | type Key interface {
45 | Kind() string
46 | ID() int64
47 | Name() string
48 | ParentKey() Key
49 | Namespace() string
50 | SetNamespace(namespace string)
51 |
52 | String() string
53 | GobEncode() ([]byte, error)
54 | GobDecode(buf []byte) error
55 | MarshalJSON() ([]byte, error)
56 | UnmarshalJSON(buf []byte) error
57 | Encode() string
58 | Equal(o Key) bool
59 | Incomplete() bool
60 | }
61 |
62 | type PendingKey interface {
63 | StoredContext() context.Context
64 | }
65 |
66 | type Transaction interface {
67 | Get(key Key, dst interface{}) error
68 | GetMulti(keys []Key, dst interface{}) error
69 | Put(key Key, src interface{}) (PendingKey, error)
70 | PutMulti(keys []Key, src interface{}) ([]PendingKey, error)
71 | Delete(key Key) error
72 | DeleteMulti(keys []Key) error
73 |
74 | Commit() (Commit, error)
75 | Rollback() error
76 |
77 | Batch() *TransactionBatch
78 | }
79 |
80 | type Commit interface {
81 | Key(p PendingKey) Key
82 | }
83 |
84 | type GeoPoint struct {
85 | Lat, Lng float64
86 | }
87 |
88 | type Query interface {
89 | Ancestor(ancestor Key) Query
90 | EventualConsistency() Query
91 | Namespace(ns string) Query
92 | Transaction(t Transaction) Query
93 | Filter(filterStr string, value interface{}) Query
94 | Order(fieldName string) Query
95 | Project(fieldNames ...string) Query
96 | Distinct() Query
97 | // NOT IMPLEMENTED ON APPENGINE DistinctOn(fieldNames ...string) *Query
98 | KeysOnly() Query
99 | Limit(limit int) Query
100 | Offset(offset int) Query
101 | Start(c Cursor) Query
102 | End(c Cursor) Query
103 |
104 | Dump() *QueryDump
105 | }
106 |
107 | type Iterator interface {
108 | Next(dst interface{}) (Key, error)
109 | Cursor() (Cursor, error)
110 | }
111 |
112 | type Cursor interface {
113 | String() string
114 | }
115 |
116 | type PropertyTranslator interface {
117 | ToPropertyValue(ctx context.Context) (interface{}, error)
118 | FromPropertyValue(ctx context.Context, p Property) (dst interface{}, err error)
119 | }
120 |
121 | // TODO ComplexPropertyTranslator e.g. ToProperties(ctx context.Context) ([]Property, error)
122 |
--------------------------------------------------------------------------------
/vendor/go.mercari.io/datastore/internal/c/atomiccache/atomiccache.go:
--------------------------------------------------------------------------------
1 | // Copyright 2016 Google Inc. All Rights Reserved.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | // Package atomiccache provides a map-based cache that supports very fast
16 | // reads.
17 | package atomiccache
18 |
19 | import (
20 | "sync"
21 | "sync/atomic"
22 | )
23 |
24 | type mapType map[interface{}]interface{}
25 |
26 | // Cache is a map-based cache that supports fast reads via use of atomics.
27 | // Writes are slow, requiring a copy of the entire cache.
28 | // The zero Cache is an empty cache, ready for use.
29 | type Cache struct {
30 | val atomic.Value // mapType
31 | mu sync.Mutex // used only by writers
32 | }
33 |
34 | // Get returns the value of the cache at key. If there is no value,
35 | // getter is called to provide one, and the cache is updated.
36 | // The getter function may be called concurrently. It should be pure,
37 | // returning the same value for every call.
38 | func (c *Cache) Get(key interface{}, getter func() interface{}) interface{} {
39 | mp, _ := c.val.Load().(mapType)
40 | if v, ok := mp[key]; ok {
41 | return v
42 | }
43 |
44 | // Compute value without lock.
45 | // Might duplicate effort but won't hold other computations back.
46 | newV := getter()
47 |
48 | c.mu.Lock()
49 | mp, _ = c.val.Load().(mapType)
50 | newM := make(mapType, len(mp)+1)
51 | for k, v := range mp {
52 | newM[k] = v
53 | }
54 | newM[key] = newV
55 | c.val.Store(newM)
56 | c.mu.Unlock()
57 | return newV
58 | }
59 |
--------------------------------------------------------------------------------
/vendor/go.mercari.io/datastore/internal/option.go:
--------------------------------------------------------------------------------
1 | package internal
2 |
3 | import (
4 | "net/http"
5 | "os"
6 |
7 | "golang.org/x/oauth2"
8 | )
9 |
10 | type ClientSettings struct {
11 | ProjectID string
12 |
13 | Scopes []string
14 | TokenSource oauth2.TokenSource
15 | CredentialsFile string // if set, Token Source is ignored.
16 | HTTPClient *http.Client
17 | }
18 |
19 | func GetProjectID() string {
20 | return os.Getenv("PROJECT_ID") // NOTE ないよりマシ
21 | }
22 |
--------------------------------------------------------------------------------
/vendor/go.mercari.io/datastore/internal/shared/doc.go:
--------------------------------------------------------------------------------
1 | package shared
2 |
3 | // this package MUST only referenced by client implementation package.
4 | // e.g. aedatastore, clouddatastore.
5 |
--------------------------------------------------------------------------------
/vendor/go.mercari.io/datastore/option.go:
--------------------------------------------------------------------------------
1 | // Copyright 2017 Google Inc. All Rights Reserved.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | // Package option contains options for Google API clients.
16 |
17 | package datastore
18 |
19 | import (
20 | "net/http"
21 |
22 | "go.mercari.io/datastore/internal"
23 | "golang.org/x/oauth2"
24 | )
25 |
26 | type ClientOption interface {
27 | Apply(*internal.ClientSettings)
28 | }
29 |
30 | func WithProjectID(projectID string) ClientOption {
31 | return withProjectID{projectID}
32 | }
33 |
34 | type withProjectID struct{ s string }
35 |
36 | func (w withProjectID) Apply(o *internal.ClientSettings) {
37 | o.ProjectID = w.s
38 | }
39 |
40 | // WithTokenSource returns a ClientOption that specifies an OAuth2 token
41 | // source to be used as the basis for authentication.
42 | func WithTokenSource(s oauth2.TokenSource) ClientOption {
43 | return withTokenSource{s}
44 | }
45 |
46 | type withTokenSource struct{ ts oauth2.TokenSource }
47 |
48 | func (w withTokenSource) Apply(o *internal.ClientSettings) {
49 | o.TokenSource = w.ts
50 | }
51 |
52 | type withCredFile string
53 |
54 | func (w withCredFile) Apply(o *internal.ClientSettings) {
55 | o.CredentialsFile = string(w)
56 | }
57 |
58 | // WithCredentialsFile returns a ClientOption that authenticates
59 | // API calls with the given service account or refresh token JSON
60 | // credentials file.
61 | func WithCredentialsFile(filename string) ClientOption {
62 | return withCredFile(filename)
63 | }
64 |
65 | // WithScopes returns a ClientOption that overrides the default OAuth2 scopes
66 | // to be used for a service.
67 | func WithScopes(scope ...string) ClientOption {
68 | return withScopes(scope)
69 | }
70 |
71 | type withScopes []string
72 |
73 | func (w withScopes) Apply(o *internal.ClientSettings) {
74 | s := make([]string, len(w))
75 | copy(s, w)
76 | o.Scopes = s
77 | }
78 |
79 | // WithHTTPClient returns a ClientOption that specifies the HTTP client to use
80 | // as the basis of communications. This option may only be used with services
81 | // that support HTTP as their communication transport. When used, the
82 | // WithHTTPClient option takes precedent over all other supplied options.
83 | func WithHTTPClient(client *http.Client) ClientOption {
84 | return withHTTPClient{client}
85 | }
86 |
87 | type withHTTPClient struct{ client *http.Client }
88 |
89 | func (w withHTTPClient) Apply(o *internal.ClientSettings) {
90 | o.HTTPClient = w.client
91 | }
92 |
--------------------------------------------------------------------------------
/vendor/go.mercari.io/datastore/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "datastore",
3 | "version": "0.17.0",
4 | "private": true,
5 | "scripts": {
6 | "changelog": "conventional-changelog -p angular -i CHANGELOG.md -s"
7 | },
8 | "license": "MIT",
9 | "devDependencies": {
10 | "conventional-changelog-cli": "^1.3.4"
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/vendor/go.mercari.io/datastore/query.go:
--------------------------------------------------------------------------------
1 | // Copyright 2014 Google Inc. All Rights Reserved.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | package datastore
16 |
17 | const (
18 | keyFieldName = "__key__"
19 | )
20 |
--------------------------------------------------------------------------------
/vendor/go.mercari.io/datastore/serve.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh -eux
2 |
3 | docker-compose up
4 |
--------------------------------------------------------------------------------
/vendor/go.mercari.io/datastore/setup.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh -eux
2 |
3 | # install or fetch dependencies
4 | # gcloud components install --quiet app-engine-go
5 | # gcloud components install --quiet beta cloud-datastore-emulator
6 | go get -u github.com/golang/dep/cmd/dep
7 | dep ensure
8 |
9 | # build tools
10 | rm -rf build-cmd/
11 | mkdir build-cmd
12 | go build -o build-cmd/goimports ./vendor/golang.org/x/tools/cmd/goimports
13 | go build -o build-cmd/golint ./vendor/github.com/golang/lint/golint
14 | go build -o build-cmd/gosimple ./vendor/honnef.co/go/tools/cmd/gosimple
15 | go build -o build-cmd/staticcheck ./vendor/honnef.co/go/tools/cmd/staticcheck
16 | go build -o build-cmd/unused ./vendor/honnef.co/go/tools/cmd/unused
17 | go build -o build-cmd/jwg ./vendor/github.com/favclip/jwg/cmd/jwg
18 | go build -o build-cmd/qbg ./vendor/github.com/favclip/qbg/cmd/qbg
19 |
20 | # copy utils from other repo
21 | rm -rf internal/c internal/pb
22 | mkdir -p internal/c internal/pb
23 |
24 | cp -r vendor/cloud.google.com/go/internal/atomiccache internal/c/atomiccache
25 | cp -r vendor/cloud.google.com/go/internal/fields internal/c/fields
26 | cp -r vendor/google.golang.org/appengine/internal/memcache internal/pb/memcache
27 |
28 | if [ `uname` = "Darwin" ]; then
29 | sed -i '' -e 's/"cloud.google.com\/go\/internal\/atomiccache"/"go.mercari.io\/datastore\/internal\/c\/atomiccache"/g' internal/c/fields/fields.go
30 | elif [ `uname` = "Linux" ]; then
31 | sed -i -e 's/"cloud.google.com\/go\/internal\/atomiccache"/"go.mercari.io\/datastore\/internal\/c\/atomiccache"/g' internal/c/fields/fields.go
32 | fi
33 |
34 | rm -rf internal/c/**/*_test.go
35 | rm -rf internal/c/**/*.sh
36 |
--------------------------------------------------------------------------------
/vendor/go.mercari.io/datastore/test.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh -eux
2 |
3 | targets=`find . -type f \( -name '*.go' -and -not -iwholename '*vendor*' -and -not -iwholename '*testdata*' \)`
4 | packages=`go list ./... | grep -v internal/c | grep -v internal/pb`
5 |
6 | # Apply tools
7 | export PATH=$(pwd)/build-cmd:$PATH
8 | which goimports golint staticcheck gosimple unused jwg qbg
9 | goimports -w $targets
10 | go tool vet $targets
11 | # golint $packages
12 | staticcheck $packages
13 | gosimple $packages
14 | unused $packages
15 | go generate $packages
16 |
17 | export DATASTORE_EMULATOR_HOST=localhost:8081
18 | export DATASTORE_PROJECT_ID=datastore-wrapper
19 | export REDIS_HOST=
20 | export REDIS_PORT=6379
21 |
22 | # use -p 1. Cloud Datastore Emulator can't dedicated by connections. go will running package concurrently.
23 | goapp test $packages -p 1 $@
24 |
25 | # Connect Cloud Datastore (production env)
26 | # (if you need login) → gcloud auth application-default login
27 | # go test $packages -p 1 $@
28 |
--------------------------------------------------------------------------------
/vendor/go.mercari.io/datastore/time.go:
--------------------------------------------------------------------------------
1 | // Copyright 2014 Google Inc. All Rights Reserved.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | package datastore
16 |
17 | import (
18 | "math"
19 | "time"
20 | )
21 |
22 | var (
23 | minTime = time.Unix(int64(math.MinInt64)/1e6, (int64(math.MinInt64)%1e6)*1e3)
24 | maxTime = time.Unix(int64(math.MaxInt64)/1e6, (int64(math.MaxInt64)%1e6)*1e3)
25 | )
26 |
27 | func toUnixMicro(t time.Time) int64 {
28 | // We cannot use t.UnixNano() / 1e3 because we want to handle times more than
29 | // 2^63 nanoseconds (which is about 292 years) away from 1970, and those cannot
30 | // be represented in the numerator of a single int64 divide.
31 | return t.Unix()*1e6 + int64(t.Nanosecond()/1e3)
32 | }
33 |
34 | func fromUnixMicro(t int64) time.Time {
35 | return time.Unix(t/1e6, (t%1e6)*1e3)
36 | }
37 |
--------------------------------------------------------------------------------
/vendor/golang.org/x/net/AUTHORS:
--------------------------------------------------------------------------------
1 | # This source code refers to The Go Authors for copyright purposes.
2 | # The master list of authors is in the main Go distribution,
3 | # visible at http://tip.golang.org/AUTHORS.
4 |
--------------------------------------------------------------------------------
/vendor/golang.org/x/net/CONTRIBUTORS:
--------------------------------------------------------------------------------
1 | # This source code was written by the Go contributors.
2 | # The master list of contributors is in the main Go distribution,
3 | # visible at http://tip.golang.org/CONTRIBUTORS.
4 |
--------------------------------------------------------------------------------
/vendor/golang.org/x/net/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright (c) 2009 The Go Authors. All rights reserved.
2 |
3 | Redistribution and use in source and binary forms, with or without
4 | modification, are permitted provided that the following conditions are
5 | met:
6 |
7 | * Redistributions of source code must retain the above copyright
8 | notice, this list of conditions and the following disclaimer.
9 | * Redistributions in binary form must reproduce the above
10 | copyright notice, this list of conditions and the following disclaimer
11 | in the documentation and/or other materials provided with the
12 | distribution.
13 | * Neither the name of Google Inc. nor the names of its
14 | contributors may be used to endorse or promote products derived from
15 | this software without specific prior written permission.
16 |
17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 |
--------------------------------------------------------------------------------
/vendor/golang.org/x/net/PATENTS:
--------------------------------------------------------------------------------
1 | Additional IP Rights Grant (Patents)
2 |
3 | "This implementation" means the copyrightable works distributed by
4 | Google as part of the Go project.
5 |
6 | Google hereby grants to You a perpetual, worldwide, non-exclusive,
7 | no-charge, royalty-free, irrevocable (except as stated in this section)
8 | patent license to make, have made, use, offer to sell, sell, import,
9 | transfer and otherwise run, modify and propagate the contents of this
10 | implementation of Go, where such license applies only to those patent
11 | claims, both currently owned or controlled by Google and acquired in
12 | the future, licensable by Google that are necessarily infringed by this
13 | implementation of Go. This grant does not include claims that would be
14 | infringed only as a consequence of further modification of this
15 | implementation. If you or your agent or exclusive licensee institute or
16 | order or agree to the institution of patent litigation against any
17 | entity (including a cross-claim or counterclaim in a lawsuit) alleging
18 | that this implementation of Go or any code incorporated within this
19 | implementation of Go constitutes direct or contributory patent
20 | infringement, or inducement of patent infringement, then any patent
21 | rights granted to you under this License for this implementation of Go
22 | shall terminate as of the date such litigation is filed.
23 |
--------------------------------------------------------------------------------
/vendor/golang.org/x/net/context/context.go:
--------------------------------------------------------------------------------
1 | // Copyright 2014 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | // Package context defines the Context type, which carries deadlines,
6 | // cancelation signals, and other request-scoped values across API boundaries
7 | // and between processes.
8 | // As of Go 1.7 this package is available in the standard library under the
9 | // name context. https://golang.org/pkg/context.
10 | //
11 | // Incoming requests to a server should create a Context, and outgoing calls to
12 | // servers should accept a Context. The chain of function calls between must
13 | // propagate the Context, optionally replacing it with a modified copy created
14 | // using WithDeadline, WithTimeout, WithCancel, or WithValue.
15 | //
16 | // Programs that use Contexts should follow these rules to keep interfaces
17 | // consistent across packages and enable static analysis tools to check context
18 | // propagation:
19 | //
20 | // Do not store Contexts inside a struct type; instead, pass a Context
21 | // explicitly to each function that needs it. The Context should be the first
22 | // parameter, typically named ctx:
23 | //
24 | // func DoSomething(ctx context.Context, arg Arg) error {
25 | // // ... use ctx ...
26 | // }
27 | //
28 | // Do not pass a nil Context, even if a function permits it. Pass context.TODO
29 | // if you are unsure about which Context to use.
30 | //
31 | // Use context Values only for request-scoped data that transits processes and
32 | // APIs, not for passing optional parameters to functions.
33 | //
34 | // The same Context may be passed to functions running in different goroutines;
35 | // Contexts are safe for simultaneous use by multiple goroutines.
36 | //
37 | // See http://blog.golang.org/context for example code for a server that uses
38 | // Contexts.
39 | package context // import "golang.org/x/net/context"
40 |
41 | // Background returns a non-nil, empty Context. It is never canceled, has no
42 | // values, and has no deadline. It is typically used by the main function,
43 | // initialization, and tests, and as the top-level Context for incoming
44 | // requests.
45 | func Background() Context {
46 | return background
47 | }
48 |
49 | // TODO returns a non-nil, empty Context. Code should use context.TODO when
50 | // it's unclear which Context to use or it is not yet available (because the
51 | // surrounding function has not yet been extended to accept a Context
52 | // parameter). TODO is recognized by static analysis tools that determine
53 | // whether Contexts are propagated correctly in a program.
54 | func TODO() Context {
55 | return todo
56 | }
57 |
--------------------------------------------------------------------------------
/vendor/golang.org/x/net/context/ctxhttp/ctxhttp.go:
--------------------------------------------------------------------------------
1 | // Copyright 2016 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | // +build go1.7
6 |
7 | // Package ctxhttp provides helper functions for performing context-aware HTTP requests.
8 | package ctxhttp // import "golang.org/x/net/context/ctxhttp"
9 |
10 | import (
11 | "io"
12 | "net/http"
13 | "net/url"
14 | "strings"
15 |
16 | "golang.org/x/net/context"
17 | )
18 |
19 | // Do sends an HTTP request with the provided http.Client and returns
20 | // an HTTP response.
21 | //
22 | // If the client is nil, http.DefaultClient is used.
23 | //
24 | // The provided ctx must be non-nil. If it is canceled or times out,
25 | // ctx.Err() will be returned.
26 | func Do(ctx context.Context, client *http.Client, req *http.Request) (*http.Response, error) {
27 | if client == nil {
28 | client = http.DefaultClient
29 | }
30 | resp, err := client.Do(req.WithContext(ctx))
31 | // If we got an error, and the context has been canceled,
32 | // the context's error is probably more useful.
33 | if err != nil {
34 | select {
35 | case <-ctx.Done():
36 | err = ctx.Err()
37 | default:
38 | }
39 | }
40 | return resp, err
41 | }
42 |
43 | // Get issues a GET request via the Do function.
44 | func Get(ctx context.Context, client *http.Client, url string) (*http.Response, error) {
45 | req, err := http.NewRequest("GET", url, nil)
46 | if err != nil {
47 | return nil, err
48 | }
49 | return Do(ctx, client, req)
50 | }
51 |
52 | // Head issues a HEAD request via the Do function.
53 | func Head(ctx context.Context, client *http.Client, url string) (*http.Response, error) {
54 | req, err := http.NewRequest("HEAD", url, nil)
55 | if err != nil {
56 | return nil, err
57 | }
58 | return Do(ctx, client, req)
59 | }
60 |
61 | // Post issues a POST request via the Do function.
62 | func Post(ctx context.Context, client *http.Client, url string, bodyType string, body io.Reader) (*http.Response, error) {
63 | req, err := http.NewRequest("POST", url, body)
64 | if err != nil {
65 | return nil, err
66 | }
67 | req.Header.Set("Content-Type", bodyType)
68 | return Do(ctx, client, req)
69 | }
70 |
71 | // PostForm issues a POST request via the Do function.
72 | func PostForm(ctx context.Context, client *http.Client, url string, data url.Values) (*http.Response, error) {
73 | return Post(ctx, client, url, "application/x-www-form-urlencoded", strings.NewReader(data.Encode()))
74 | }
75 |
--------------------------------------------------------------------------------
/vendor/golang.org/x/net/context/go17.go:
--------------------------------------------------------------------------------
1 | // Copyright 2016 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | // +build go1.7
6 |
7 | package context
8 |
9 | import (
10 | "context" // standard library's context, as of Go 1.7
11 | "time"
12 | )
13 |
14 | var (
15 | todo = context.TODO()
16 | background = context.Background()
17 | )
18 |
19 | // Canceled is the error returned by Context.Err when the context is canceled.
20 | var Canceled = context.Canceled
21 |
22 | // DeadlineExceeded is the error returned by Context.Err when the context's
23 | // deadline passes.
24 | var DeadlineExceeded = context.DeadlineExceeded
25 |
26 | // WithCancel returns a copy of parent with a new Done channel. The returned
27 | // context's Done channel is closed when the returned cancel function is called
28 | // or when the parent context's Done channel is closed, whichever happens first.
29 | //
30 | // Canceling this context releases resources associated with it, so code should
31 | // call cancel as soon as the operations running in this Context complete.
32 | func WithCancel(parent Context) (ctx Context, cancel CancelFunc) {
33 | ctx, f := context.WithCancel(parent)
34 | return ctx, CancelFunc(f)
35 | }
36 |
37 | // WithDeadline returns a copy of the parent context with the deadline adjusted
38 | // to be no later than d. If the parent's deadline is already earlier than d,
39 | // WithDeadline(parent, d) is semantically equivalent to parent. The returned
40 | // context's Done channel is closed when the deadline expires, when the returned
41 | // cancel function is called, or when the parent context's Done channel is
42 | // closed, whichever happens first.
43 | //
44 | // Canceling this context releases resources associated with it, so code should
45 | // call cancel as soon as the operations running in this Context complete.
46 | func WithDeadline(parent Context, deadline time.Time) (Context, CancelFunc) {
47 | ctx, f := context.WithDeadline(parent, deadline)
48 | return ctx, CancelFunc(f)
49 | }
50 |
51 | // WithTimeout returns WithDeadline(parent, time.Now().Add(timeout)).
52 | //
53 | // Canceling this context releases resources associated with it, so code should
54 | // call cancel as soon as the operations running in this Context complete:
55 | //
56 | // func slowOperationWithTimeout(ctx context.Context) (Result, error) {
57 | // ctx, cancel := context.WithTimeout(ctx, 100*time.Millisecond)
58 | // defer cancel() // releases resources if slowOperation completes before timeout elapses
59 | // return slowOperation(ctx)
60 | // }
61 | func WithTimeout(parent Context, timeout time.Duration) (Context, CancelFunc) {
62 | return WithDeadline(parent, time.Now().Add(timeout))
63 | }
64 |
65 | // WithValue returns a copy of parent in which the value associated with key is
66 | // val.
67 | //
68 | // Use context Values only for request-scoped data that transits processes and
69 | // APIs, not for passing optional parameters to functions.
70 | func WithValue(parent Context, key interface{}, val interface{}) Context {
71 | return context.WithValue(parent, key, val)
72 | }
73 |
--------------------------------------------------------------------------------
/vendor/golang.org/x/net/context/go19.go:
--------------------------------------------------------------------------------
1 | // Copyright 2017 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | // +build go1.9
6 |
7 | package context
8 |
9 | import "context" // standard library's context, as of Go 1.7
10 |
11 | // A Context carries a deadline, a cancelation signal, and other values across
12 | // API boundaries.
13 | //
14 | // Context's methods may be called by multiple goroutines simultaneously.
15 | type Context = context.Context
16 |
17 | // A CancelFunc tells an operation to abandon its work.
18 | // A CancelFunc does not wait for the work to stop.
19 | // After the first call, subsequent calls to a CancelFunc do nothing.
20 | type CancelFunc = context.CancelFunc
21 |
--------------------------------------------------------------------------------
/vendor/golang.org/x/oauth2/.travis.yml:
--------------------------------------------------------------------------------
1 | language: go
2 |
3 | go:
4 | - tip
5 |
6 | install:
7 | - export GOPATH="$HOME/gopath"
8 | - mkdir -p "$GOPATH/src/golang.org/x"
9 | - mv "$TRAVIS_BUILD_DIR" "$GOPATH/src/golang.org/x/oauth2"
10 | - go get -v -t -d golang.org/x/oauth2/...
11 |
12 | script:
13 | - go test -v golang.org/x/oauth2/...
14 |
--------------------------------------------------------------------------------
/vendor/golang.org/x/oauth2/AUTHORS:
--------------------------------------------------------------------------------
1 | # This source code refers to The Go Authors for copyright purposes.
2 | # The master list of authors is in the main Go distribution,
3 | # visible at http://tip.golang.org/AUTHORS.
4 |
--------------------------------------------------------------------------------
/vendor/golang.org/x/oauth2/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | # Contributing to Go
2 |
3 | Go is an open source project.
4 |
5 | It is the work of hundreds of contributors. We appreciate your help!
6 |
7 | ## Filing issues
8 |
9 | When [filing an issue](https://github.com/golang/oauth2/issues), make sure to answer these five questions:
10 |
11 | 1. What version of Go are you using (`go version`)?
12 | 2. What operating system and processor architecture are you using?
13 | 3. What did you do?
14 | 4. What did you expect to see?
15 | 5. What did you see instead?
16 |
17 | General questions should go to the [golang-nuts mailing list](https://groups.google.com/group/golang-nuts) instead of the issue tracker.
18 | The gophers there will answer or ask you to file an issue if you've tripped over a bug.
19 |
20 | ## Contributing code
21 |
22 | Please read the [Contribution Guidelines](https://golang.org/doc/contribute.html)
23 | before sending patches.
24 |
25 | Unless otherwise noted, the Go source files are distributed under
26 | the BSD-style license found in the LICENSE file.
27 |
--------------------------------------------------------------------------------
/vendor/golang.org/x/oauth2/CONTRIBUTORS:
--------------------------------------------------------------------------------
1 | # This source code was written by the Go contributors.
2 | # The master list of contributors is in the main Go distribution,
3 | # visible at http://tip.golang.org/CONTRIBUTORS.
4 |
--------------------------------------------------------------------------------
/vendor/golang.org/x/oauth2/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright (c) 2009 The Go Authors. All rights reserved.
2 |
3 | Redistribution and use in source and binary forms, with or without
4 | modification, are permitted provided that the following conditions are
5 | met:
6 |
7 | * Redistributions of source code must retain the above copyright
8 | notice, this list of conditions and the following disclaimer.
9 | * Redistributions in binary form must reproduce the above
10 | copyright notice, this list of conditions and the following disclaimer
11 | in the documentation and/or other materials provided with the
12 | distribution.
13 | * Neither the name of Google Inc. nor the names of its
14 | contributors may be used to endorse or promote products derived from
15 | this software without specific prior written permission.
16 |
17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 |
--------------------------------------------------------------------------------
/vendor/golang.org/x/oauth2/README.md:
--------------------------------------------------------------------------------
1 | # OAuth2 for Go
2 |
3 | [](https://travis-ci.org/golang/oauth2)
4 | [](https://godoc.org/golang.org/x/oauth2)
5 |
6 | oauth2 package contains a client implementation for OAuth 2.0 spec.
7 |
8 | ## Installation
9 |
10 | ~~~~
11 | go get golang.org/x/oauth2
12 | ~~~~
13 |
14 | Or you can manually git clone the repository to
15 | `$(go env GOPATH)/src/golang.org/x/oauth2`.
16 |
17 | See godoc for further documentation and examples.
18 |
19 | * [godoc.org/golang.org/x/oauth2](http://godoc.org/golang.org/x/oauth2)
20 | * [godoc.org/golang.org/x/oauth2/google](http://godoc.org/golang.org/x/oauth2/google)
21 |
22 |
23 | ## App Engine
24 |
25 | In change 96e89be (March 2015), we removed the `oauth2.Context2` type in favor
26 | of the [`context.Context`](https://golang.org/x/net/context#Context) type from
27 | the `golang.org/x/net/context` package
28 |
29 | This means it's no longer possible to use the "Classic App Engine"
30 | `appengine.Context` type with the `oauth2` package. (You're using
31 | Classic App Engine if you import the package `"appengine"`.)
32 |
33 | To work around this, you may use the new `"google.golang.org/appengine"`
34 | package. This package has almost the same API as the `"appengine"` package,
35 | but it can be fetched with `go get` and used on "Managed VMs" and well as
36 | Classic App Engine.
37 |
38 | See the [new `appengine` package's readme](https://github.com/golang/appengine#updating-a-go-app-engine-app)
39 | for information on updating your app.
40 |
41 | If you don't want to update your entire app to use the new App Engine packages,
42 | you may use both sets of packages in parallel, using only the new packages
43 | with the `oauth2` package.
44 |
45 | ```go
46 | import (
47 | "golang.org/x/net/context"
48 | "golang.org/x/oauth2"
49 | "golang.org/x/oauth2/google"
50 | newappengine "google.golang.org/appengine"
51 | newurlfetch "google.golang.org/appengine/urlfetch"
52 |
53 | "appengine"
54 | )
55 |
56 | func handler(w http.ResponseWriter, r *http.Request) {
57 | var c appengine.Context = appengine.NewContext(r)
58 | c.Infof("Logging a message with the old package")
59 |
60 | var ctx context.Context = newappengine.NewContext(r)
61 | client := &http.Client{
62 | Transport: &oauth2.Transport{
63 | Source: google.AppEngineTokenSource(ctx, "scope"),
64 | Base: &newurlfetch.Transport{Context: ctx},
65 | },
66 | }
67 | client.Get("...")
68 | }
69 | ```
70 |
71 | ## Report Issues / Send Patches
72 |
73 | This repository uses Gerrit for code changes. To learn how to submit changes to
74 | this repository, see https://golang.org/doc/contribute.html.
75 |
76 | The main issue tracker for the oauth2 repository is located at
77 | https://github.com/golang/oauth2/issues.
78 |
--------------------------------------------------------------------------------
/vendor/golang.org/x/oauth2/google/appengine.go:
--------------------------------------------------------------------------------
1 | // Copyright 2014 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package google
6 |
7 | import (
8 | "sort"
9 | "strings"
10 | "sync"
11 | "time"
12 |
13 | "golang.org/x/net/context"
14 | "golang.org/x/oauth2"
15 | )
16 |
17 | // appengineFlex is set at init time by appengineflex_hook.go. If true, we are on App Engine Flex.
18 | var appengineFlex bool
19 |
20 | // Set at init time by appengine_hook.go. If nil, we're not on App Engine.
21 | var appengineTokenFunc func(c context.Context, scopes ...string) (token string, expiry time.Time, err error)
22 |
23 | // Set at init time by appengine_hook.go. If nil, we're not on App Engine.
24 | var appengineAppIDFunc func(c context.Context) string
25 |
26 | // AppEngineTokenSource returns a token source that fetches tokens
27 | // issued to the current App Engine application's service account.
28 | // If you are implementing a 3-legged OAuth 2.0 flow on App Engine
29 | // that involves user accounts, see oauth2.Config instead.
30 | //
31 | // The provided context must have come from appengine.NewContext.
32 | func AppEngineTokenSource(ctx context.Context, scope ...string) oauth2.TokenSource {
33 | if appengineTokenFunc == nil {
34 | panic("google: AppEngineTokenSource can only be used on App Engine.")
35 | }
36 | scopes := append([]string{}, scope...)
37 | sort.Strings(scopes)
38 | return &appEngineTokenSource{
39 | ctx: ctx,
40 | scopes: scopes,
41 | key: strings.Join(scopes, " "),
42 | }
43 | }
44 |
45 | // aeTokens helps the fetched tokens to be reused until their expiration.
46 | var (
47 | aeTokensMu sync.Mutex
48 | aeTokens = make(map[string]*tokenLock) // key is space-separated scopes
49 | )
50 |
51 | type tokenLock struct {
52 | mu sync.Mutex // guards t; held while fetching or updating t
53 | t *oauth2.Token
54 | }
55 |
56 | type appEngineTokenSource struct {
57 | ctx context.Context
58 | scopes []string
59 | key string // to aeTokens map; space-separated scopes
60 | }
61 |
62 | func (ts *appEngineTokenSource) Token() (*oauth2.Token, error) {
63 | if appengineTokenFunc == nil {
64 | panic("google: AppEngineTokenSource can only be used on App Engine.")
65 | }
66 |
67 | aeTokensMu.Lock()
68 | tok, ok := aeTokens[ts.key]
69 | if !ok {
70 | tok = &tokenLock{}
71 | aeTokens[ts.key] = tok
72 | }
73 | aeTokensMu.Unlock()
74 |
75 | tok.mu.Lock()
76 | defer tok.mu.Unlock()
77 | if tok.t.Valid() {
78 | return tok.t, nil
79 | }
80 | access, exp, err := appengineTokenFunc(ts.ctx, ts.scopes...)
81 | if err != nil {
82 | return nil, err
83 | }
84 | tok.t = &oauth2.Token{
85 | AccessToken: access,
86 | Expiry: exp,
87 | }
88 | return tok.t, nil
89 | }
90 |
--------------------------------------------------------------------------------
/vendor/golang.org/x/oauth2/google/appengine_hook.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | // +build appengine appenginevm
6 |
7 | package google
8 |
9 | import "google.golang.org/appengine"
10 |
11 | func init() {
12 | appengineTokenFunc = appengine.AccessToken
13 | appengineAppIDFunc = appengine.AppID
14 | }
15 |
--------------------------------------------------------------------------------
/vendor/golang.org/x/oauth2/google/appengineflex_hook.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | // +build appenginevm
6 |
7 | package google
8 |
9 | func init() {
10 | appengineFlex = true // Flex doesn't support appengine.AccessToken; depend on metadata server.
11 | }
12 |
--------------------------------------------------------------------------------
/vendor/golang.org/x/oauth2/google/default.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package google
6 |
7 | import (
8 | "encoding/json"
9 | "fmt"
10 | "io/ioutil"
11 | "net/http"
12 | "os"
13 | "path/filepath"
14 | "runtime"
15 |
16 | "cloud.google.com/go/compute/metadata"
17 | "golang.org/x/net/context"
18 | "golang.org/x/oauth2"
19 | )
20 |
21 | // DefaultClient returns an HTTP Client that uses the
22 | // DefaultTokenSource to obtain authentication credentials.
23 | func DefaultClient(ctx context.Context, scope ...string) (*http.Client, error) {
24 | ts, err := DefaultTokenSource(ctx, scope...)
25 | if err != nil {
26 | return nil, err
27 | }
28 | return oauth2.NewClient(ctx, ts), nil
29 | }
30 |
31 | // DefaultTokenSource returns the token source for
32 | // "Application Default Credentials".
33 | // It is a shortcut for FindDefaultCredentials(ctx, scope).TokenSource.
34 | func DefaultTokenSource(ctx context.Context, scope ...string) (oauth2.TokenSource, error) {
35 | creds, err := FindDefaultCredentials(ctx, scope...)
36 | if err != nil {
37 | return nil, err
38 | }
39 | return creds.TokenSource, nil
40 | }
41 |
42 | // Common implementation for FindDefaultCredentials.
43 | func findDefaultCredentials(ctx context.Context, scopes []string) (*DefaultCredentials, error) {
44 | // First, try the environment variable.
45 | const envVar = "GOOGLE_APPLICATION_CREDENTIALS"
46 | if filename := os.Getenv(envVar); filename != "" {
47 | creds, err := readCredentialsFile(ctx, filename, scopes)
48 | if err != nil {
49 | return nil, fmt.Errorf("google: error getting credentials using %v environment variable: %v", envVar, err)
50 | }
51 | return creds, nil
52 | }
53 |
54 | // Second, try a well-known file.
55 | filename := wellKnownFile()
56 | if creds, err := readCredentialsFile(ctx, filename, scopes); err == nil {
57 | return creds, nil
58 | } else if !os.IsNotExist(err) {
59 | return nil, fmt.Errorf("google: error getting credentials using well-known file (%v): %v", filename, err)
60 | }
61 |
62 | // Third, if we're on Google App Engine use those credentials.
63 | if appengineTokenFunc != nil && !appengineFlex {
64 | return &DefaultCredentials{
65 | ProjectID: appengineAppIDFunc(ctx),
66 | TokenSource: AppEngineTokenSource(ctx, scopes...),
67 | }, nil
68 | }
69 |
70 | // Fourth, if we're on Google Compute Engine use the metadata server.
71 | if metadata.OnGCE() {
72 | id, _ := metadata.ProjectID()
73 | return &DefaultCredentials{
74 | ProjectID: id,
75 | TokenSource: ComputeTokenSource(""),
76 | }, nil
77 | }
78 |
79 | // None are found; return helpful error.
80 | const url = "https://developers.google.com/accounts/docs/application-default-credentials"
81 | return nil, fmt.Errorf("google: could not find default credentials. See %v for more information.", url)
82 | }
83 |
84 | // Common implementation for CredentialsFromJSON.
85 | func credentialsFromJSON(ctx context.Context, jsonData []byte, scopes []string) (*DefaultCredentials, error) {
86 | var f credentialsFile
87 | if err := json.Unmarshal(jsonData, &f); err != nil {
88 | return nil, err
89 | }
90 | ts, err := f.tokenSource(ctx, append([]string(nil), scopes...))
91 | if err != nil {
92 | return nil, err
93 | }
94 | return &DefaultCredentials{
95 | ProjectID: f.ProjectID,
96 | TokenSource: ts,
97 | JSON: jsonData,
98 | }, nil
99 | }
100 |
101 | func wellKnownFile() string {
102 | const f = "application_default_credentials.json"
103 | if runtime.GOOS == "windows" {
104 | return filepath.Join(os.Getenv("APPDATA"), "gcloud", f)
105 | }
106 | return filepath.Join(guessUnixHomeDir(), ".config", "gcloud", f)
107 | }
108 |
109 | func readCredentialsFile(ctx context.Context, filename string, scopes []string) (*DefaultCredentials, error) {
110 | b, err := ioutil.ReadFile(filename)
111 | if err != nil {
112 | return nil, err
113 | }
114 | return CredentialsFromJSON(ctx, b, scopes...)
115 | }
116 |
--------------------------------------------------------------------------------
/vendor/golang.org/x/oauth2/google/doc_go19.go:
--------------------------------------------------------------------------------
1 | // Copyright 2018 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | // +build go1.9
6 |
7 | // Package google provides support for making OAuth2 authorized and authenticated
8 | // HTTP requests to Google APIs. It supports the Web server flow, client-side
9 | // credentials, service accounts, Google Compute Engine service accounts, and Google
10 | // App Engine service accounts.
11 | //
12 | // A brief overview of the package follows. For more information, please read
13 | // https://developers.google.com/accounts/docs/OAuth2
14 | // and
15 | // https://developers.google.com/accounts/docs/application-default-credentials.
16 | //
17 | // OAuth2 Configs
18 | //
19 | // Two functions in this package return golang.org/x/oauth2.Config values from Google credential
20 | // data. Google supports two JSON formats for OAuth2 credentials: one is handled by ConfigFromJSON,
21 | // the other by JWTConfigFromJSON. The returned Config can be used to obtain a TokenSource or
22 | // create an http.Client.
23 | //
24 | //
25 | // Credentials
26 | //
27 | // The Credentials type represents Google credentials, including Application Default
28 | // Credentials.
29 | //
30 | // Use FindDefaultCredentials to obtain Application Default Credentials.
31 | // FindDefaultCredentials looks in some well-known places for a credentials file, and
32 | // will call AppEngineTokenSource or ComputeTokenSource as needed.
33 | //
34 | // DefaultClient and DefaultTokenSource are convenience methods. They first call FindDefaultCredentials,
35 | // then use the credentials to construct an http.Client or an oauth2.TokenSource.
36 | //
37 | // Use CredentialsFromJSON to obtain credentials from either of the two JSON formats
38 | // described in OAuth2 Configs, above. The TokenSource in the returned value is the
39 | // same as the one obtained from the oauth2.Config returned from ConfigFromJSON or
40 | // JWTConfigFromJSON, but the Credentials may contain additional information
41 | // that is useful is some circumstances.
42 | package google // import "golang.org/x/oauth2/google"
43 |
--------------------------------------------------------------------------------
/vendor/golang.org/x/oauth2/google/doc_not_go19.go:
--------------------------------------------------------------------------------
1 | // Copyright 2018 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | // +build !go1.9
6 |
7 | // Package google provides support for making OAuth2 authorized and authenticated
8 | // HTTP requests to Google APIs. It supports the Web server flow, client-side
9 | // credentials, service accounts, Google Compute Engine service accounts, and Google
10 | // App Engine service accounts.
11 | //
12 | // A brief overview of the package follows. For more information, please read
13 | // https://developers.google.com/accounts/docs/OAuth2
14 | // and
15 | // https://developers.google.com/accounts/docs/application-default-credentials.
16 | //
17 | // OAuth2 Configs
18 | //
19 | // Two functions in this package return golang.org/x/oauth2.Config values from Google credential
20 | // data. Google supports two JSON formats for OAuth2 credentials: one is handled by ConfigFromJSON,
21 | // the other by JWTConfigFromJSON. The returned Config can be used to obtain a TokenSource or
22 | // create an http.Client.
23 | //
24 | //
25 | // Credentials
26 | //
27 | // The DefaultCredentials type represents Google Application Default Credentials, as
28 | // well as other forms of credential.
29 | //
30 | // Use FindDefaultCredentials to obtain Application Default Credentials.
31 | // FindDefaultCredentials looks in some well-known places for a credentials file, and
32 | // will call AppEngineTokenSource or ComputeTokenSource as needed.
33 | //
34 | // DefaultClient and DefaultTokenSource are convenience methods. They first call FindDefaultCredentials,
35 | // then use the credentials to construct an http.Client or an oauth2.TokenSource.
36 | //
37 | // Use CredentialsFromJSON to obtain credentials from either of the two JSON
38 | // formats described in OAuth2 Configs, above. (The DefaultCredentials returned may
39 | // not be "Application Default Credentials".) The TokenSource in the returned value
40 | // is the same as the one obtained from the oauth2.Config returned from
41 | // ConfigFromJSON or JWTConfigFromJSON, but the DefaultCredentials may contain
42 | // additional information that is useful is some circumstances.
43 | package google // import "golang.org/x/oauth2/google"
44 |
--------------------------------------------------------------------------------
/vendor/golang.org/x/oauth2/google/go19.go:
--------------------------------------------------------------------------------
1 | // Copyright 2018 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | // +build go1.9
6 |
7 | package google
8 |
9 | import (
10 | "golang.org/x/net/context"
11 | "golang.org/x/oauth2"
12 | )
13 |
14 | // Credentials holds Google credentials, including "Application Default Credentials".
15 | // For more details, see:
16 | // https://developers.google.com/accounts/docs/application-default-credentials
17 | type Credentials struct {
18 | ProjectID string // may be empty
19 | TokenSource oauth2.TokenSource
20 |
21 | // JSON contains the raw bytes from a JSON credentials file.
22 | // This field may be nil if authentication is provided by the
23 | // environment and not with a credentials file, e.g. when code is
24 | // running on Google Cloud Platform.
25 | JSON []byte
26 | }
27 |
28 | // DefaultCredentials is the old name of Credentials.
29 | //
30 | // Deprecated: use Credentials instead.
31 | type DefaultCredentials = Credentials
32 |
33 | // FindDefaultCredentials searches for "Application Default Credentials".
34 | //
35 | // It looks for credentials in the following places,
36 | // preferring the first location found:
37 | //
38 | // 1. A JSON file whose path is specified by the
39 | // GOOGLE_APPLICATION_CREDENTIALS environment variable.
40 | // 2. A JSON file in a location known to the gcloud command-line tool.
41 | // On Windows, this is %APPDATA%/gcloud/application_default_credentials.json.
42 | // On other systems, $HOME/.config/gcloud/application_default_credentials.json.
43 | // 3. On Google App Engine it uses the appengine.AccessToken function.
44 | // 4. On Google Compute Engine and Google App Engine Managed VMs, it fetches
45 | // credentials from the metadata server.
46 | // (In this final case any provided scopes are ignored.)
47 | func FindDefaultCredentials(ctx context.Context, scopes ...string) (*Credentials, error) {
48 | return findDefaultCredentials(ctx, scopes)
49 | }
50 |
51 | // CredentialsFromJSON obtains Google credentials from a JSON value. The JSON can
52 | // represent either a Google Developers Console client_credentials.json file (as in
53 | // ConfigFromJSON) or a Google Developers service account key file (as in
54 | // JWTConfigFromJSON).
55 | func CredentialsFromJSON(ctx context.Context, jsonData []byte, scopes ...string) (*Credentials, error) {
56 | return credentialsFromJSON(ctx, jsonData, scopes)
57 | }
58 |
--------------------------------------------------------------------------------
/vendor/golang.org/x/oauth2/google/jwt.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package google
6 |
7 | import (
8 | "crypto/rsa"
9 | "fmt"
10 | "time"
11 |
12 | "golang.org/x/oauth2"
13 | "golang.org/x/oauth2/internal"
14 | "golang.org/x/oauth2/jws"
15 | )
16 |
17 | // JWTAccessTokenSourceFromJSON uses a Google Developers service account JSON
18 | // key file to read the credentials that authorize and authenticate the
19 | // requests, and returns a TokenSource that does not use any OAuth2 flow but
20 | // instead creates a JWT and sends that as the access token.
21 | // The audience is typically a URL that specifies the scope of the credentials.
22 | //
23 | // Note that this is not a standard OAuth flow, but rather an
24 | // optimization supported by a few Google services.
25 | // Unless you know otherwise, you should use JWTConfigFromJSON instead.
26 | func JWTAccessTokenSourceFromJSON(jsonKey []byte, audience string) (oauth2.TokenSource, error) {
27 | cfg, err := JWTConfigFromJSON(jsonKey)
28 | if err != nil {
29 | return nil, fmt.Errorf("google: could not parse JSON key: %v", err)
30 | }
31 | pk, err := internal.ParseKey(cfg.PrivateKey)
32 | if err != nil {
33 | return nil, fmt.Errorf("google: could not parse key: %v", err)
34 | }
35 | ts := &jwtAccessTokenSource{
36 | email: cfg.Email,
37 | audience: audience,
38 | pk: pk,
39 | pkID: cfg.PrivateKeyID,
40 | }
41 | tok, err := ts.Token()
42 | if err != nil {
43 | return nil, err
44 | }
45 | return oauth2.ReuseTokenSource(tok, ts), nil
46 | }
47 |
48 | type jwtAccessTokenSource struct {
49 | email, audience string
50 | pk *rsa.PrivateKey
51 | pkID string
52 | }
53 |
54 | func (ts *jwtAccessTokenSource) Token() (*oauth2.Token, error) {
55 | iat := time.Now()
56 | exp := iat.Add(time.Hour)
57 | cs := &jws.ClaimSet{
58 | Iss: ts.email,
59 | Sub: ts.email,
60 | Aud: ts.audience,
61 | Iat: iat.Unix(),
62 | Exp: exp.Unix(),
63 | }
64 | hdr := &jws.Header{
65 | Algorithm: "RS256",
66 | Typ: "JWT",
67 | KeyID: string(ts.pkID),
68 | }
69 | msg, err := jws.Encode(hdr, cs, ts.pk)
70 | if err != nil {
71 | return nil, fmt.Errorf("google: could not encode JWT: %v", err)
72 | }
73 | return &oauth2.Token{AccessToken: msg, TokenType: "Bearer", Expiry: exp}, nil
74 | }
75 |
--------------------------------------------------------------------------------
/vendor/golang.org/x/oauth2/google/not_go19.go:
--------------------------------------------------------------------------------
1 | // Copyright 2018 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | // +build !go1.9
6 |
7 | package google
8 |
9 | import (
10 | "golang.org/x/net/context"
11 | "golang.org/x/oauth2"
12 | )
13 |
14 | // DefaultCredentials holds Google credentials, including "Application Default Credentials".
15 | // For more details, see:
16 | // https://developers.google.com/accounts/docs/application-default-credentials
17 | type DefaultCredentials struct {
18 | ProjectID string // may be empty
19 | TokenSource oauth2.TokenSource
20 |
21 | // JSON contains the raw bytes from a JSON credentials file.
22 | // This field may be nil if authentication is provided by the
23 | // environment and not with a credentials file, e.g. when code is
24 | // running on Google Cloud Platform.
25 | JSON []byte
26 | }
27 |
28 | // FindDefaultCredentials searches for "Application Default Credentials".
29 | //
30 | // It looks for credentials in the following places,
31 | // preferring the first location found:
32 | //
33 | // 1. A JSON file whose path is specified by the
34 | // GOOGLE_APPLICATION_CREDENTIALS environment variable.
35 | // 2. A JSON file in a location known to the gcloud command-line tool.
36 | // On Windows, this is %APPDATA%/gcloud/application_default_credentials.json.
37 | // On other systems, $HOME/.config/gcloud/application_default_credentials.json.
38 | // 3. On Google App Engine it uses the appengine.AccessToken function.
39 | // 4. On Google Compute Engine and Google App Engine Managed VMs, it fetches
40 | // credentials from the metadata server.
41 | // (In this final case any provided scopes are ignored.)
42 | func FindDefaultCredentials(ctx context.Context, scopes ...string) (*DefaultCredentials, error) {
43 | return findDefaultCredentials(ctx, scopes)
44 | }
45 |
46 | // CredentialsFromJSON obtains Google credentials from a JSON value. The JSON can
47 | // represent either a Google Developers Console client_credentials.json file (as in
48 | // ConfigFromJSON) or a Google Developers service account key file (as in
49 | // JWTConfigFromJSON).
50 | //
51 | // Note: despite the name, the returned credentials may not be Application Default Credentials.
52 | func CredentialsFromJSON(ctx context.Context, jsonData []byte, scopes ...string) (*DefaultCredentials, error) {
53 | return credentialsFromJSON(ctx, jsonData, scopes)
54 | }
55 |
--------------------------------------------------------------------------------
/vendor/golang.org/x/oauth2/internal/client_appengine.go:
--------------------------------------------------------------------------------
1 | // Copyright 2018 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | // +build appengine
6 |
7 | package internal
8 |
9 | import "google.golang.org/appengine/urlfetch"
10 |
11 | func init() {
12 | appengineClientHook = urlfetch.Client
13 | }
14 |
--------------------------------------------------------------------------------
/vendor/golang.org/x/oauth2/internal/doc.go:
--------------------------------------------------------------------------------
1 | // Copyright 2017 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | // Package internal contains support packages for oauth2 package.
6 | package internal
7 |
--------------------------------------------------------------------------------
/vendor/golang.org/x/oauth2/internal/oauth2.go:
--------------------------------------------------------------------------------
1 | // Copyright 2014 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package internal
6 |
7 | import (
8 | "crypto/rsa"
9 | "crypto/x509"
10 | "encoding/pem"
11 | "errors"
12 | "fmt"
13 | )
14 |
15 | // ParseKey converts the binary contents of a private key file
16 | // to an *rsa.PrivateKey. It detects whether the private key is in a
17 | // PEM container or not. If so, it extracts the the private key
18 | // from PEM container before conversion. It only supports PEM
19 | // containers with no passphrase.
20 | func ParseKey(key []byte) (*rsa.PrivateKey, error) {
21 | block, _ := pem.Decode(key)
22 | if block != nil {
23 | key = block.Bytes
24 | }
25 | parsedKey, err := x509.ParsePKCS8PrivateKey(key)
26 | if err != nil {
27 | parsedKey, err = x509.ParsePKCS1PrivateKey(key)
28 | if err != nil {
29 | return nil, fmt.Errorf("private key should be a PEM or plain PKSC1 or PKCS8; parse error: %v", err)
30 | }
31 | }
32 | parsed, ok := parsedKey.(*rsa.PrivateKey)
33 | if !ok {
34 | return nil, errors.New("private key is invalid")
35 | }
36 | return parsed, nil
37 | }
38 |
--------------------------------------------------------------------------------
/vendor/golang.org/x/oauth2/internal/transport.go:
--------------------------------------------------------------------------------
1 | // Copyright 2014 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package internal
6 |
7 | import (
8 | "net/http"
9 |
10 | "golang.org/x/net/context"
11 | )
12 |
13 | // HTTPClient is the context key to use with golang.org/x/net/context's
14 | // WithValue function to associate an *http.Client value with a context.
15 | var HTTPClient ContextKey
16 |
17 | // ContextKey is just an empty struct. It exists so HTTPClient can be
18 | // an immutable public variable with a unique type. It's immutable
19 | // because nobody else can create a ContextKey, being unexported.
20 | type ContextKey struct{}
21 |
22 | var appengineClientHook func(context.Context) *http.Client
23 |
24 | func ContextClient(ctx context.Context) *http.Client {
25 | if ctx != nil {
26 | if hc, ok := ctx.Value(HTTPClient).(*http.Client); ok {
27 | return hc
28 | }
29 | }
30 | if appengineClientHook != nil {
31 | return appengineClientHook(ctx)
32 | }
33 | return http.DefaultClient
34 | }
35 |
--------------------------------------------------------------------------------
/vendor/golang.org/x/oauth2/transport.go:
--------------------------------------------------------------------------------
1 | // Copyright 2014 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package oauth2
6 |
7 | import (
8 | "errors"
9 | "io"
10 | "net/http"
11 | "sync"
12 | )
13 |
14 | // Transport is an http.RoundTripper that makes OAuth 2.0 HTTP requests,
15 | // wrapping a base RoundTripper and adding an Authorization header
16 | // with a token from the supplied Sources.
17 | //
18 | // Transport is a low-level mechanism. Most code will use the
19 | // higher-level Config.Client method instead.
20 | type Transport struct {
21 | // Source supplies the token to add to outgoing requests'
22 | // Authorization headers.
23 | Source TokenSource
24 |
25 | // Base is the base RoundTripper used to make HTTP requests.
26 | // If nil, http.DefaultTransport is used.
27 | Base http.RoundTripper
28 |
29 | mu sync.Mutex // guards modReq
30 | modReq map[*http.Request]*http.Request // original -> modified
31 | }
32 |
33 | // RoundTrip authorizes and authenticates the request with an
34 | // access token. If no token exists or token is expired,
35 | // tries to refresh/fetch a new token.
36 | func (t *Transport) RoundTrip(req *http.Request) (*http.Response, error) {
37 | if t.Source == nil {
38 | return nil, errors.New("oauth2: Transport's Source is nil")
39 | }
40 | token, err := t.Source.Token()
41 | if err != nil {
42 | return nil, err
43 | }
44 |
45 | req2 := cloneRequest(req) // per RoundTripper contract
46 | token.SetAuthHeader(req2)
47 | t.setModReq(req, req2)
48 | res, err := t.base().RoundTrip(req2)
49 | if err != nil {
50 | t.setModReq(req, nil)
51 | return nil, err
52 | }
53 | res.Body = &onEOFReader{
54 | rc: res.Body,
55 | fn: func() { t.setModReq(req, nil) },
56 | }
57 | return res, nil
58 | }
59 |
60 | // CancelRequest cancels an in-flight request by closing its connection.
61 | func (t *Transport) CancelRequest(req *http.Request) {
62 | type canceler interface {
63 | CancelRequest(*http.Request)
64 | }
65 | if cr, ok := t.base().(canceler); ok {
66 | t.mu.Lock()
67 | modReq := t.modReq[req]
68 | delete(t.modReq, req)
69 | t.mu.Unlock()
70 | cr.CancelRequest(modReq)
71 | }
72 | }
73 |
74 | func (t *Transport) base() http.RoundTripper {
75 | if t.Base != nil {
76 | return t.Base
77 | }
78 | return http.DefaultTransport
79 | }
80 |
81 | func (t *Transport) setModReq(orig, mod *http.Request) {
82 | t.mu.Lock()
83 | defer t.mu.Unlock()
84 | if t.modReq == nil {
85 | t.modReq = make(map[*http.Request]*http.Request)
86 | }
87 | if mod == nil {
88 | delete(t.modReq, orig)
89 | } else {
90 | t.modReq[orig] = mod
91 | }
92 | }
93 |
94 | // cloneRequest returns a clone of the provided *http.Request.
95 | // The clone is a shallow copy of the struct and its Header map.
96 | func cloneRequest(r *http.Request) *http.Request {
97 | // shallow copy of the struct
98 | r2 := new(http.Request)
99 | *r2 = *r
100 | // deep copy of the Header
101 | r2.Header = make(http.Header, len(r.Header))
102 | for k, s := range r.Header {
103 | r2.Header[k] = append([]string(nil), s...)
104 | }
105 | return r2
106 | }
107 |
108 | type onEOFReader struct {
109 | rc io.ReadCloser
110 | fn func()
111 | }
112 |
113 | func (r *onEOFReader) Read(p []byte) (n int, err error) {
114 | n, err = r.rc.Read(p)
115 | if err == io.EOF {
116 | r.runFunc()
117 | }
118 | return
119 | }
120 |
121 | func (r *onEOFReader) Close() error {
122 | err := r.rc.Close()
123 | r.runFunc()
124 | return err
125 | }
126 |
127 | func (r *onEOFReader) runFunc() {
128 | if fn := r.fn; fn != nil {
129 | fn()
130 | r.fn = nil
131 | }
132 | }
133 |
--------------------------------------------------------------------------------
/vendor/google.golang.org/api/AUTHORS:
--------------------------------------------------------------------------------
1 | # This is the official list of authors for copyright purposes.
2 | # This file is distinct from the CONTRIBUTORS files.
3 | # See the latter for an explanation.
4 |
5 | # Names should be added to this file as
6 | # Name or Organization
7 | # The email address is not required for organizations.
8 |
9 | # Please keep the list sorted.
10 | Google Inc.
11 |
--------------------------------------------------------------------------------
/vendor/google.golang.org/api/CONTRIBUTORS:
--------------------------------------------------------------------------------
1 | # This is the official list of people who can contribute
2 | # (and typically have contributed) code to the repository.
3 | # The AUTHORS file lists the copyright holders; this file
4 | # lists people. For example, Google employees are listed here
5 | # but not in AUTHORS, because Google holds the copyright.
6 | #
7 | # The submission process automatically checks to make sure
8 | # that people submitting code are listed in this file (by email address).
9 | #
10 | # Names should be added to this file only after verifying that
11 | # the individual or the individual's organization has agreed to
12 | # the appropriate Contributor License Agreement, found here:
13 | #
14 | # https://cla.developers.google.com/about/google-individual
15 | # https://cla.developers.google.com/about/google-corporate
16 | #
17 | # The CLA can be filled out on the web:
18 | #
19 | # https://cla.developers.google.com/
20 | #
21 | # When adding J Random Contributor's name to this file,
22 | # either J's name or J's organization's name should be
23 | # added to the AUTHORS file, depending on whether the
24 | # individual or corporate CLA was used.
25 |
26 | # Names should be added to this file like so:
27 | # Name
28 | #
29 | # An entry with two email addresses specifies that the
30 | # first address should be used in the submit logs and
31 | # that the second address should be recognized as the
32 | # same person when interacting with Rietveld.
33 |
34 | # Please keep the list sorted.
35 |
36 | Alain Vongsouvanhalainv
37 | Andrew Gerrand
38 | Brad Fitzpatrick
39 | Eric Koleda
40 | Francesc Campoy
41 | Garrick Evans
42 | Glenn Lewis
43 | Ivan Krasin
44 | Jason Hall
45 | Johan Euphrosine
46 | Kostik Shtoyk
47 | Kunpei Sakai
48 | Matthew Whisenhunt
49 | Michael McGreevy
50 | Nick Craig-Wood
51 | Ross Light
52 | Sarah Adams
53 | Scott Van Woudenberg
54 | Takashi Matsuo
55 |
--------------------------------------------------------------------------------
/vendor/google.golang.org/api/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright (c) 2011 Google Inc. All rights reserved.
2 |
3 | Redistribution and use in source and binary forms, with or without
4 | modification, are permitted provided that the following conditions are
5 | met:
6 |
7 | * Redistributions of source code must retain the above copyright
8 | notice, this list of conditions and the following disclaimer.
9 | * Redistributions in binary form must reproduce the above
10 | copyright notice, this list of conditions and the following disclaimer
11 | in the documentation and/or other materials provided with the
12 | distribution.
13 | * Neither the name of Google Inc. nor the names of its
14 | contributors may be used to endorse or promote products derived from
15 | this software without specific prior written permission.
16 |
17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 |
--------------------------------------------------------------------------------
/vendor/google.golang.org/api/gensupport/backoff.go:
--------------------------------------------------------------------------------
1 | // Copyright 2016 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package gensupport
6 |
7 | import (
8 | "math/rand"
9 | "time"
10 | )
11 |
12 | type BackoffStrategy interface {
13 | // Pause returns the duration of the next pause and true if the operation should be
14 | // retried, or false if no further retries should be attempted.
15 | Pause() (time.Duration, bool)
16 |
17 | // Reset restores the strategy to its initial state.
18 | Reset()
19 | }
20 |
21 | // ExponentialBackoff performs exponential backoff as per https://en.wikipedia.org/wiki/Exponential_backoff.
22 | // The initial pause time is given by Base.
23 | // Once the total pause time exceeds Max, Pause will indicate no further retries.
24 | type ExponentialBackoff struct {
25 | Base time.Duration
26 | Max time.Duration
27 | total time.Duration
28 | n uint
29 | }
30 |
31 | func (eb *ExponentialBackoff) Pause() (time.Duration, bool) {
32 | if eb.total > eb.Max {
33 | return 0, false
34 | }
35 |
36 | // The next pause is selected from randomly from [0, 2^n * Base).
37 | d := time.Duration(rand.Int63n((1 << eb.n) * int64(eb.Base)))
38 | eb.total += d
39 | eb.n++
40 | return d, true
41 | }
42 |
43 | func (eb *ExponentialBackoff) Reset() {
44 | eb.n = 0
45 | eb.total = 0
46 | }
47 |
--------------------------------------------------------------------------------
/vendor/google.golang.org/api/gensupport/buffer.go:
--------------------------------------------------------------------------------
1 | // Copyright 2016 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package gensupport
6 |
7 | import (
8 | "bytes"
9 | "io"
10 |
11 | "google.golang.org/api/googleapi"
12 | )
13 |
14 | // MediaBuffer buffers data from an io.Reader to support uploading media in retryable chunks.
15 | type MediaBuffer struct {
16 | media io.Reader
17 |
18 | chunk []byte // The current chunk which is pending upload. The capacity is the chunk size.
19 | err error // Any error generated when populating chunk by reading media.
20 |
21 | // The absolute position of chunk in the underlying media.
22 | off int64
23 | }
24 |
25 | func NewMediaBuffer(media io.Reader, chunkSize int) *MediaBuffer {
26 | return &MediaBuffer{media: media, chunk: make([]byte, 0, chunkSize)}
27 | }
28 |
29 | // Chunk returns the current buffered chunk, the offset in the underlying media
30 | // from which the chunk is drawn, and the size of the chunk.
31 | // Successive calls to Chunk return the same chunk between calls to Next.
32 | func (mb *MediaBuffer) Chunk() (chunk io.Reader, off int64, size int, err error) {
33 | // There may already be data in chunk if Next has not been called since the previous call to Chunk.
34 | if mb.err == nil && len(mb.chunk) == 0 {
35 | mb.err = mb.loadChunk()
36 | }
37 | return bytes.NewReader(mb.chunk), mb.off, len(mb.chunk), mb.err
38 | }
39 |
40 | // loadChunk will read from media into chunk, up to the capacity of chunk.
41 | func (mb *MediaBuffer) loadChunk() error {
42 | bufSize := cap(mb.chunk)
43 | mb.chunk = mb.chunk[:bufSize]
44 |
45 | read := 0
46 | var err error
47 | for err == nil && read < bufSize {
48 | var n int
49 | n, err = mb.media.Read(mb.chunk[read:])
50 | read += n
51 | }
52 | mb.chunk = mb.chunk[:read]
53 | return err
54 | }
55 |
56 | // Next advances to the next chunk, which will be returned by the next call to Chunk.
57 | // Calls to Next without a corresponding prior call to Chunk will have no effect.
58 | func (mb *MediaBuffer) Next() {
59 | mb.off += int64(len(mb.chunk))
60 | mb.chunk = mb.chunk[0:0]
61 | }
62 |
63 | type readerTyper struct {
64 | io.Reader
65 | googleapi.ContentTyper
66 | }
67 |
68 | // ReaderAtToReader adapts a ReaderAt to be used as a Reader.
69 | // If ra implements googleapi.ContentTyper, then the returned reader
70 | // will also implement googleapi.ContentTyper, delegating to ra.
71 | func ReaderAtToReader(ra io.ReaderAt, size int64) io.Reader {
72 | r := io.NewSectionReader(ra, 0, size)
73 | if typer, ok := ra.(googleapi.ContentTyper); ok {
74 | return readerTyper{r, typer}
75 | }
76 | return r
77 | }
78 |
--------------------------------------------------------------------------------
/vendor/google.golang.org/api/gensupport/doc.go:
--------------------------------------------------------------------------------
1 | // Copyright 2016 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | // Package gensupport is an internal implementation detail used by code
6 | // generated by the google-api-go-generator tool.
7 | //
8 | // This package may be modified at any time without regard for backwards
9 | // compatibility. It should not be used directly by API users.
10 | package gensupport
11 |
--------------------------------------------------------------------------------
/vendor/google.golang.org/api/gensupport/go18.go:
--------------------------------------------------------------------------------
1 | // Copyright 2018 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | // +build go1.8
6 |
7 | package gensupport
8 |
9 | import (
10 | "io"
11 | "net/http"
12 | )
13 |
14 | // SetGetBody sets the GetBody field of req to f.
15 | func SetGetBody(req *http.Request, f func() (io.ReadCloser, error)) {
16 | req.GetBody = f
17 | }
18 |
--------------------------------------------------------------------------------
/vendor/google.golang.org/api/gensupport/header.go:
--------------------------------------------------------------------------------
1 | // Copyright 2017 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package gensupport
6 |
7 | import (
8 | "fmt"
9 | "runtime"
10 | "strings"
11 | )
12 |
13 | // GoogleClientHeader returns the value to use for the x-goog-api-client
14 | // header, which is used internally by Google.
15 | func GoogleClientHeader(generatorVersion, clientElement string) string {
16 | elts := []string{"gl-go/" + strings.Replace(runtime.Version(), " ", "_", -1)}
17 | if clientElement != "" {
18 | elts = append(elts, clientElement)
19 | }
20 | elts = append(elts, fmt.Sprintf("gdcl/%s", generatorVersion))
21 | return strings.Join(elts, " ")
22 | }
23 |
--------------------------------------------------------------------------------
/vendor/google.golang.org/api/gensupport/jsonfloat.go:
--------------------------------------------------------------------------------
1 | // Copyright 2016 Google Inc. All Rights Reserved.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | package gensupport
16 |
17 | import (
18 | "encoding/json"
19 | "errors"
20 | "fmt"
21 | "math"
22 | )
23 |
24 | // JSONFloat64 is a float64 that supports proper unmarshaling of special float
25 | // values in JSON, according to
26 | // https://developers.google.com/protocol-buffers/docs/proto3#json. Although
27 | // that is a proto-to-JSON spec, it applies to all Google APIs.
28 | //
29 | // The jsonpb package
30 | // (https://github.com/golang/protobuf/blob/master/jsonpb/jsonpb.go) has
31 | // similar functionality, but only for direct translation from proto messages
32 | // to JSON.
33 | type JSONFloat64 float64
34 |
35 | func (f *JSONFloat64) UnmarshalJSON(data []byte) error {
36 | var ff float64
37 | if err := json.Unmarshal(data, &ff); err == nil {
38 | *f = JSONFloat64(ff)
39 | return nil
40 | }
41 | var s string
42 | if err := json.Unmarshal(data, &s); err == nil {
43 | switch s {
44 | case "NaN":
45 | ff = math.NaN()
46 | case "Infinity":
47 | ff = math.Inf(1)
48 | case "-Infinity":
49 | ff = math.Inf(-1)
50 | default:
51 | return fmt.Errorf("google.golang.org/api/internal: bad float string %q", s)
52 | }
53 | *f = JSONFloat64(ff)
54 | return nil
55 | }
56 | return errors.New("google.golang.org/api/internal: data not float or string")
57 | }
58 |
--------------------------------------------------------------------------------
/vendor/google.golang.org/api/gensupport/not_go18.go:
--------------------------------------------------------------------------------
1 | // Copyright 2018 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | // +build !go1.8
6 |
7 | package gensupport
8 |
9 | import (
10 | "io"
11 | "net/http"
12 | )
13 |
14 | func SetGetBody(req *http.Request, f func() (io.ReadCloser, error)) {}
15 |
--------------------------------------------------------------------------------
/vendor/google.golang.org/api/gensupport/params.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package gensupport
6 |
7 | import (
8 | "net/url"
9 |
10 | "google.golang.org/api/googleapi"
11 | )
12 |
13 | // URLParams is a simplified replacement for url.Values
14 | // that safely builds up URL parameters for encoding.
15 | type URLParams map[string][]string
16 |
17 | // Get returns the first value for the given key, or "".
18 | func (u URLParams) Get(key string) string {
19 | vs := u[key]
20 | if len(vs) == 0 {
21 | return ""
22 | }
23 | return vs[0]
24 | }
25 |
26 | // Set sets the key to value.
27 | // It replaces any existing values.
28 | func (u URLParams) Set(key, value string) {
29 | u[key] = []string{value}
30 | }
31 |
32 | // SetMulti sets the key to an array of values.
33 | // It replaces any existing values.
34 | // Note that values must not be modified after calling SetMulti
35 | // so the caller is responsible for making a copy if necessary.
36 | func (u URLParams) SetMulti(key string, values []string) {
37 | u[key] = values
38 | }
39 |
40 | // Encode encodes the values into ``URL encoded'' form
41 | // ("bar=baz&foo=quux") sorted by key.
42 | func (u URLParams) Encode() string {
43 | return url.Values(u).Encode()
44 | }
45 |
46 | func SetOptions(u URLParams, opts ...googleapi.CallOption) {
47 | for _, o := range opts {
48 | u.Set(o.Get())
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/vendor/google.golang.org/api/gensupport/retry.go:
--------------------------------------------------------------------------------
1 | // Copyright 2017 Google Inc. All Rights Reserved.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | package gensupport
16 |
17 | import (
18 | "io"
19 | "net"
20 | "net/http"
21 | "time"
22 |
23 | "golang.org/x/net/context"
24 | )
25 |
26 | // Retry invokes the given function, retrying it multiple times if the connection failed or
27 | // the HTTP status response indicates the request should be attempted again. ctx may be nil.
28 | func Retry(ctx context.Context, f func() (*http.Response, error), backoff BackoffStrategy) (*http.Response, error) {
29 | for {
30 | resp, err := f()
31 |
32 | var status int
33 | if resp != nil {
34 | status = resp.StatusCode
35 | }
36 |
37 | // Return if we shouldn't retry.
38 | pause, retry := backoff.Pause()
39 | if !shouldRetry(status, err) || !retry {
40 | return resp, err
41 | }
42 |
43 | // Ensure the response body is closed, if any.
44 | if resp != nil && resp.Body != nil {
45 | resp.Body.Close()
46 | }
47 |
48 | // Pause, but still listen to ctx.Done if context is not nil.
49 | var done <-chan struct{}
50 | if ctx != nil {
51 | done = ctx.Done()
52 | }
53 | select {
54 | case <-done:
55 | return nil, ctx.Err()
56 | case <-time.After(pause):
57 | }
58 | }
59 | }
60 |
61 | // DefaultBackoffStrategy returns a default strategy to use for retrying failed upload requests.
62 | func DefaultBackoffStrategy() BackoffStrategy {
63 | return &ExponentialBackoff{
64 | Base: 250 * time.Millisecond,
65 | Max: 16 * time.Second,
66 | }
67 | }
68 |
69 | // shouldRetry returns true if the HTTP response / error indicates that the
70 | // request should be attempted again.
71 | func shouldRetry(status int, err error) bool {
72 | if 500 <= status && status <= 599 {
73 | return true
74 | }
75 | if status == statusTooManyRequests {
76 | return true
77 | }
78 | if err == io.ErrUnexpectedEOF {
79 | return true
80 | }
81 | if err, ok := err.(net.Error); ok {
82 | return err.Temporary()
83 | }
84 | return false
85 | }
86 |
--------------------------------------------------------------------------------
/vendor/google.golang.org/api/gensupport/send.go:
--------------------------------------------------------------------------------
1 | // Copyright 2016 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package gensupport
6 |
7 | import (
8 | "encoding/json"
9 | "errors"
10 | "net/http"
11 |
12 | "golang.org/x/net/context"
13 | "golang.org/x/net/context/ctxhttp"
14 | )
15 |
16 | // Hook is the type of a function that is called once before each HTTP request
17 | // that is sent by a generated API. It returns a function that is called after
18 | // the request returns.
19 | // Hooks are not called if the context is nil.
20 | type Hook func(ctx context.Context, req *http.Request) func(resp *http.Response)
21 |
22 | var hooks []Hook
23 |
24 | // RegisterHook registers a Hook to be called before each HTTP request by a
25 | // generated API. Hooks are called in the order they are registered. Each
26 | // hook can return a function; if it is non-nil, it is called after the HTTP
27 | // request returns. These functions are called in the reverse order.
28 | // RegisterHook should not be called concurrently with itself or SendRequest.
29 | func RegisterHook(h Hook) {
30 | hooks = append(hooks, h)
31 | }
32 |
33 | // SendRequest sends a single HTTP request using the given client.
34 | // If ctx is non-nil, it calls all hooks, then sends the request with
35 | // ctxhttp.Do, then calls any functions returned by the hooks in reverse order.
36 | func SendRequest(ctx context.Context, client *http.Client, req *http.Request) (*http.Response, error) {
37 | // Disallow Accept-Encoding because it interferes with the automatic gzip handling
38 | // done by the default http.Transport. See https://github.com/google/google-api-go-client/issues/219.
39 | if _, ok := req.Header["Accept-Encoding"]; ok {
40 | return nil, errors.New("google api: custom Accept-Encoding headers not allowed")
41 | }
42 | if ctx == nil {
43 | return client.Do(req)
44 | }
45 | // Call hooks in order of registration, store returned funcs.
46 | post := make([]func(resp *http.Response), len(hooks))
47 | for i, h := range hooks {
48 | fn := h(ctx, req)
49 | post[i] = fn
50 | }
51 |
52 | // Send request.
53 | resp, err := ctxhttp.Do(ctx, client, req)
54 |
55 | // Call returned funcs in reverse order.
56 | for i := len(post) - 1; i >= 0; i-- {
57 | if fn := post[i]; fn != nil {
58 | fn(resp)
59 | }
60 | }
61 | return resp, err
62 | }
63 |
64 | // DecodeResponse decodes the body of res into target. If there is no body,
65 | // target is unchanged.
66 | func DecodeResponse(target interface{}, res *http.Response) error {
67 | if res.StatusCode == http.StatusNoContent {
68 | return nil
69 | }
70 | return json.NewDecoder(res.Body).Decode(target)
71 | }
72 |
--------------------------------------------------------------------------------
/vendor/google.golang.org/api/googleapi/internal/uritemplates/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright (c) 2013 Joshua Tacoma
2 |
3 | Permission is hereby granted, free of charge, to any person obtaining a copy of
4 | this software and associated documentation files (the "Software"), to deal in
5 | the Software without restriction, including without limitation the rights to
6 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
7 | the Software, and to permit persons to whom the Software is furnished to do so,
8 | subject to the following conditions:
9 |
10 | The above copyright notice and this permission notice shall be included in all
11 | copies or substantial portions of the Software.
12 |
13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
15 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
16 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
17 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
18 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19 |
--------------------------------------------------------------------------------
/vendor/google.golang.org/api/googleapi/internal/uritemplates/utils.go:
--------------------------------------------------------------------------------
1 | // Copyright 2016 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package uritemplates
6 |
7 | // Expand parses then expands a URI template with a set of values to produce
8 | // the resultant URI. Two forms of the result are returned: one with all the
9 | // elements escaped, and one with the elements unescaped.
10 | func Expand(path string, values map[string]string) (escaped, unescaped string, err error) {
11 | template, err := parse(path)
12 | if err != nil {
13 | return "", "", err
14 | }
15 | escaped, unescaped = template.Expand(values)
16 | return escaped, unescaped, nil
17 | }
18 |
--------------------------------------------------------------------------------
/vendor/google.golang.org/appengine/.travis.yml:
--------------------------------------------------------------------------------
1 | language: go
2 |
3 | go:
4 | - 1.6.x
5 | - 1.7.x
6 | - 1.8.x
7 | - 1.9.x
8 |
9 | go_import_path: google.golang.org/appengine
10 |
11 | install:
12 | - go get -u -v $(go list -f '{{join .Imports "\n"}}{{"\n"}}{{join .TestImports "\n"}}' ./... | sort | uniq | grep -v appengine)
13 | - mkdir /tmp/sdk
14 | - curl -o /tmp/sdk.zip "https://storage.googleapis.com/appengine-sdks/featured/go_appengine_sdk_linux_amd64-1.9.40.zip"
15 | - unzip -q /tmp/sdk.zip -d /tmp/sdk
16 | - export PATH="$PATH:/tmp/sdk/go_appengine"
17 | - export APPENGINE_DEV_APPSERVER=/tmp/sdk/go_appengine/dev_appserver.py
18 |
19 | script:
20 | - goapp version
21 | - go version
22 | - go test -v google.golang.org/appengine/...
23 | - go test -v -race google.golang.org/appengine/...
24 | - goapp test -v google.golang.org/appengine/...
25 |
--------------------------------------------------------------------------------
/vendor/google.golang.org/appengine/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | # Contributing
2 |
3 | 1. Sign one of the contributor license agreements below.
4 | 1. Get the package:
5 |
6 | `go get -d google.golang.org/appengine`
7 | 1. Change into the checked out source:
8 |
9 | `cd $GOPATH/src/google.golang.org/appengine`
10 | 1. Fork the repo.
11 | 1. Set your fork as a remote:
12 |
13 | `git remote add fork git@github.com:GITHUB_USERNAME/appengine.git`
14 | 1. Make changes, commit to your fork.
15 | 1. Send a pull request with your changes.
16 | The first line of your commit message is conventionally a one-line summary of the change, prefixed by the primary affected package, and is used as the title of your pull request.
17 |
18 | # Testing
19 |
20 | ## Running system tests
21 |
22 | Download and install the [Go App Engine SDK](https://cloud.google.com/appengine/docs/go/download). Make sure the `go_appengine` dir is in your `PATH`.
23 |
24 | Set the `APPENGINE_DEV_APPSERVER` environment variable to `/path/to/go_appengine/dev_appserver.py`.
25 |
26 | Run tests with `goapp test`:
27 |
28 | ```
29 | goapp test -v google.golang.org/appengine/...
30 | ```
31 |
32 | ## Contributor License Agreements
33 |
34 | Before we can accept your pull requests you'll need to sign a Contributor
35 | License Agreement (CLA):
36 |
37 | - **If you are an individual writing original source code** and **you own the
38 | intellectual property**, then you'll need to sign an [individual CLA][indvcla].
39 | - **If you work for a company that wants to allow you to contribute your work**,
40 | then you'll need to sign a [corporate CLA][corpcla].
41 |
42 | You can sign these electronically (just scroll to the bottom). After that,
43 | we'll be able to accept your pull requests.
44 |
45 | ## Contributor Code of Conduct
46 |
47 | As contributors and maintainers of this project,
48 | and in the interest of fostering an open and welcoming community,
49 | we pledge to respect all people who contribute through reporting issues,
50 | posting feature requests, updating documentation,
51 | submitting pull requests or patches, and other activities.
52 |
53 | We are committed to making participation in this project
54 | a harassment-free experience for everyone,
55 | regardless of level of experience, gender, gender identity and expression,
56 | sexual orientation, disability, personal appearance,
57 | body size, race, ethnicity, age, religion, or nationality.
58 |
59 | Examples of unacceptable behavior by participants include:
60 |
61 | * The use of sexualized language or imagery
62 | * Personal attacks
63 | * Trolling or insulting/derogatory comments
64 | * Public or private harassment
65 | * Publishing other's private information,
66 | such as physical or electronic
67 | addresses, without explicit permission
68 | * Other unethical or unprofessional conduct.
69 |
70 | Project maintainers have the right and responsibility to remove, edit, or reject
71 | comments, commits, code, wiki edits, issues, and other contributions
72 | that are not aligned to this Code of Conduct.
73 | By adopting this Code of Conduct,
74 | project maintainers commit themselves to fairly and consistently
75 | applying these principles to every aspect of managing this project.
76 | Project maintainers who do not follow or enforce the Code of Conduct
77 | may be permanently removed from the project team.
78 |
79 | This code of conduct applies both within project spaces and in public spaces
80 | when an individual is representing the project or its community.
81 |
82 | Instances of abusive, harassing, or otherwise unacceptable behavior
83 | may be reported by opening an issue
84 | or contacting one or more of the project maintainers.
85 |
86 | This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.2.0,
87 | available at [http://contributor-covenant.org/version/1/2/0/](http://contributor-covenant.org/version/1/2/0/)
88 |
89 | [indvcla]: https://developers.google.com/open-source/cla/individual
90 | [corpcla]: https://developers.google.com/open-source/cla/corporate
91 |
--------------------------------------------------------------------------------
/vendor/google.golang.org/appengine/README.md:
--------------------------------------------------------------------------------
1 | # Go App Engine packages
2 |
3 | [](https://travis-ci.org/golang/appengine)
4 |
5 | This repository supports the Go runtime on *App Engine standard*.
6 | It provides APIs for interacting with App Engine services.
7 | Its canonical import path is `google.golang.org/appengine`.
8 |
9 | See https://cloud.google.com/appengine/docs/go/
10 | for more information.
11 |
12 | File issue reports and feature requests on the [GitHub's issue
13 | tracker](https://github.com/golang/appengine/issues).
14 |
15 | ## Upgrading an App Engine app to the flexible environment
16 |
17 | This package does not work on *App Engine flexible*.
18 |
19 | There are many differences between the App Engine standard environment and
20 | the flexible environment.
21 |
22 | See the [documentation on upgrading to the flexible environment](https://cloud.google.com/appengine/docs/flexible/go/upgrading).
23 |
24 | ## Directory structure
25 |
26 | The top level directory of this repository is the `appengine` package. It
27 | contains the
28 | basic APIs (e.g. `appengine.NewContext`) that apply across APIs. Specific API
29 | packages are in subdirectories (e.g. `datastore`).
30 |
31 | There is an `internal` subdirectory that contains service protocol buffers,
32 | plus packages required for connectivity to make API calls. App Engine apps
33 | should not directly import any package under `internal`.
34 |
35 | ## Updating from legacy (`import "appengine"`) packages
36 |
37 | If you're currently using the bare `appengine` packages
38 | (that is, not these ones, imported via `google.golang.org/appengine`),
39 | then you can use the `aefix` tool to help automate an upgrade to these packages.
40 |
41 | Run `go get google.golang.org/appengine/cmd/aefix` to install it.
42 |
43 | ### 1. Update import paths
44 |
45 | The import paths for App Engine packages are now fully qualified, based at `google.golang.org/appengine`.
46 | You will need to update your code to use import paths starting with that; for instance,
47 | code importing `appengine/datastore` will now need to import `google.golang.org/appengine/datastore`.
48 |
49 | ### 2. Update code using deprecated, removed or modified APIs
50 |
51 | Most App Engine services are available with exactly the same API.
52 | A few APIs were cleaned up, and there are some differences:
53 |
54 | * `appengine.Context` has been replaced with the `Context` type from `golang.org/x/net/context`.
55 | * Logging methods that were on `appengine.Context` are now functions in `google.golang.org/appengine/log`.
56 | * `appengine.Timeout` has been removed. Use `context.WithTimeout` instead.
57 | * `appengine.Datacenter` now takes a `context.Context` argument.
58 | * `datastore.PropertyLoadSaver` has been simplified to use slices in place of channels.
59 | * `delay.Call` now returns an error.
60 | * `search.FieldLoadSaver` now handles document metadata.
61 | * `urlfetch.Transport` no longer has a Deadline field; set a deadline on the
62 | `context.Context` instead.
63 | * `aetest` no longer declares its own Context type, and uses the standard one instead.
64 | * `taskqueue.QueueStats` no longer takes a maxTasks argument. That argument has been
65 | deprecated and unused for a long time.
66 | * `appengine.BackendHostname` and `appengine.BackendInstance` were for the deprecated backends feature.
67 | Use `appengine.ModuleHostname`and `appengine.ModuleName` instead.
68 | * Most of `appengine/file` and parts of `appengine/blobstore` are deprecated.
69 | Use [Google Cloud Storage](https://godoc.org/cloud.google.com/go/storage) if the
70 | feature you require is not present in the new
71 | [blobstore package](https://google.golang.org/appengine/blobstore).
72 | * `appengine/socket` is not required on App Engine flexible environment / Managed VMs.
73 | Use the standard `net` package instead.
74 |
--------------------------------------------------------------------------------
/vendor/google.golang.org/appengine/appengine.go:
--------------------------------------------------------------------------------
1 | // Copyright 2011 Google Inc. All rights reserved.
2 | // Use of this source code is governed by the Apache 2.0
3 | // license that can be found in the LICENSE file.
4 |
5 | // Package appengine provides basic functionality for Google App Engine.
6 | //
7 | // For more information on how to write Go apps for Google App Engine, see:
8 | // https://cloud.google.com/appengine/docs/go/
9 | package appengine // import "google.golang.org/appengine"
10 |
11 | import (
12 | "net/http"
13 |
14 | "github.com/golang/protobuf/proto"
15 | "golang.org/x/net/context"
16 |
17 | "google.golang.org/appengine/internal"
18 | )
19 |
20 | // The gophers party all night; the rabbits provide the beats.
21 |
22 | // Main is the principal entry point for an app running in App Engine.
23 | //
24 | // On App Engine Flexible it installs a trivial health checker if one isn't
25 | // already registered, and starts listening on port 8080 (overridden by the
26 | // $PORT environment variable).
27 | //
28 | // See https://cloud.google.com/appengine/docs/flexible/custom-runtimes#health_check_requests
29 | // for details on how to do your own health checking.
30 | //
31 | // On App Engine Standard it ensures the server has started and is prepared to
32 | // receive requests.
33 | //
34 | // Main never returns.
35 | //
36 | // Main is designed so that the app's main package looks like this:
37 | //
38 | // package main
39 | //
40 | // import (
41 | // "google.golang.org/appengine"
42 | //
43 | // _ "myapp/package0"
44 | // _ "myapp/package1"
45 | // )
46 | //
47 | // func main() {
48 | // appengine.Main()
49 | // }
50 | //
51 | // The "myapp/packageX" packages are expected to register HTTP handlers
52 | // in their init functions.
53 | func Main() {
54 | internal.Main()
55 | }
56 |
57 | // IsDevAppServer reports whether the App Engine app is running in the
58 | // development App Server.
59 | func IsDevAppServer() bool {
60 | return internal.IsDevAppServer()
61 | }
62 |
63 | // NewContext returns a context for an in-flight HTTP request.
64 | // This function is cheap.
65 | func NewContext(req *http.Request) context.Context {
66 | return internal.ReqContext(req)
67 | }
68 |
69 | // WithContext returns a copy of the parent context
70 | // and associates it with an in-flight HTTP request.
71 | // This function is cheap.
72 | func WithContext(parent context.Context, req *http.Request) context.Context {
73 | return internal.WithContext(parent, req)
74 | }
75 |
76 | // TODO(dsymonds): Add a Call function here? Otherwise other packages can't access internal.Call.
77 |
78 | // BlobKey is a key for a blobstore blob.
79 | //
80 | // Conceptually, this type belongs in the blobstore package, but it lives in
81 | // the appengine package to avoid a circular dependency: blobstore depends on
82 | // datastore, and datastore needs to refer to the BlobKey type.
83 | type BlobKey string
84 |
85 | // GeoPoint represents a location as latitude/longitude in degrees.
86 | type GeoPoint struct {
87 | Lat, Lng float64
88 | }
89 |
90 | // Valid returns whether a GeoPoint is within [-90, 90] latitude and [-180, 180] longitude.
91 | func (g GeoPoint) Valid() bool {
92 | return -90 <= g.Lat && g.Lat <= 90 && -180 <= g.Lng && g.Lng <= 180
93 | }
94 |
95 | // APICallFunc defines a function type for handling an API call.
96 | // See WithCallOverride.
97 | type APICallFunc func(ctx context.Context, service, method string, in, out proto.Message) error
98 |
99 | // WithAPICallFunc returns a copy of the parent context
100 | // that will cause API calls to invoke f instead of their normal operation.
101 | //
102 | // This is intended for advanced users only.
103 | func WithAPICallFunc(ctx context.Context, f APICallFunc) context.Context {
104 | return internal.WithCallOverride(ctx, internal.CallOverrideFunc(f))
105 | }
106 |
107 | // APICall performs an API call.
108 | //
109 | // This is not intended for general use; it is exported for use in conjunction
110 | // with WithAPICallFunc.
111 | func APICall(ctx context.Context, service, method string, in, out proto.Message) error {
112 | return internal.Call(ctx, service, method, in, out)
113 | }
114 |
--------------------------------------------------------------------------------
/vendor/google.golang.org/appengine/appengine_vm.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 Google Inc. All rights reserved.
2 | // Use of this source code is governed by the Apache 2.0
3 | // license that can be found in the LICENSE file.
4 |
5 | // +build !appengine
6 |
7 | package appengine
8 |
9 | import (
10 | "golang.org/x/net/context"
11 |
12 | "google.golang.org/appengine/internal"
13 | )
14 |
15 | // BackgroundContext returns a context not associated with a request.
16 | // This should only be used when not servicing a request.
17 | // This only works in App Engine "flexible environment".
18 | func BackgroundContext() context.Context {
19 | return internal.BackgroundContext()
20 | }
21 |
--------------------------------------------------------------------------------
/vendor/google.golang.org/appengine/datastore/metadata.go:
--------------------------------------------------------------------------------
1 | // Copyright 2016 Google Inc. All rights reserved.
2 | // Use of this source code is governed by the Apache 2.0
3 | // license that can be found in the LICENSE file.
4 |
5 | package datastore
6 |
7 | import "golang.org/x/net/context"
8 |
9 | // Datastore kinds for the metadata entities.
10 | const (
11 | namespaceKind = "__namespace__"
12 | kindKind = "__kind__"
13 | propertyKind = "__property__"
14 | )
15 |
16 | // Namespaces returns all the datastore namespaces.
17 | func Namespaces(ctx context.Context) ([]string, error) {
18 | // TODO(djd): Support range queries.
19 | q := NewQuery(namespaceKind).KeysOnly()
20 | keys, err := q.GetAll(ctx, nil)
21 | if err != nil {
22 | return nil, err
23 | }
24 | // The empty namespace key uses a numeric ID (==1), but luckily
25 | // the string ID defaults to "" for numeric IDs anyway.
26 | return keyNames(keys), nil
27 | }
28 |
29 | // Kinds returns the names of all the kinds in the current namespace.
30 | func Kinds(ctx context.Context) ([]string, error) {
31 | // TODO(djd): Support range queries.
32 | q := NewQuery(kindKind).KeysOnly()
33 | keys, err := q.GetAll(ctx, nil)
34 | if err != nil {
35 | return nil, err
36 | }
37 | return keyNames(keys), nil
38 | }
39 |
40 | // keyNames returns a slice of the provided keys' names (string IDs).
41 | func keyNames(keys []*Key) []string {
42 | n := make([]string, 0, len(keys))
43 | for _, k := range keys {
44 | n = append(n, k.StringID())
45 | }
46 | return n
47 | }
48 |
49 | // KindProperties returns all the indexed properties for the given kind.
50 | // The properties are returned as a map of property names to a slice of the
51 | // representation types. The representation types for the supported Go property
52 | // types are:
53 | // "INT64": signed integers and time.Time
54 | // "DOUBLE": float32 and float64
55 | // "BOOLEAN": bool
56 | // "STRING": string, []byte and ByteString
57 | // "POINT": appengine.GeoPoint
58 | // "REFERENCE": *Key
59 | // "USER": (not used in the Go runtime)
60 | func KindProperties(ctx context.Context, kind string) (map[string][]string, error) {
61 | // TODO(djd): Support range queries.
62 | kindKey := NewKey(ctx, kindKind, kind, 0, nil)
63 | q := NewQuery(propertyKind).Ancestor(kindKey)
64 |
65 | propMap := map[string][]string{}
66 | props := []struct {
67 | Repr []string `datastore:"property_representation"`
68 | }{}
69 |
70 | keys, err := q.GetAll(ctx, &props)
71 | if err != nil {
72 | return nil, err
73 | }
74 | for i, p := range props {
75 | propMap[keys[i].StringID()] = p.Repr
76 | }
77 | return propMap, nil
78 | }
79 |
--------------------------------------------------------------------------------
/vendor/google.golang.org/appengine/datastore/transaction.go:
--------------------------------------------------------------------------------
1 | // Copyright 2011 Google Inc. All rights reserved.
2 | // Use of this source code is governed by the Apache 2.0
3 | // license that can be found in the LICENSE file.
4 |
5 | package datastore
6 |
7 | import (
8 | "errors"
9 |
10 | "golang.org/x/net/context"
11 |
12 | "google.golang.org/appengine/internal"
13 | pb "google.golang.org/appengine/internal/datastore"
14 | )
15 |
16 | func init() {
17 | internal.RegisterTransactionSetter(func(x *pb.Query, t *pb.Transaction) {
18 | x.Transaction = t
19 | })
20 | internal.RegisterTransactionSetter(func(x *pb.GetRequest, t *pb.Transaction) {
21 | x.Transaction = t
22 | })
23 | internal.RegisterTransactionSetter(func(x *pb.PutRequest, t *pb.Transaction) {
24 | x.Transaction = t
25 | })
26 | internal.RegisterTransactionSetter(func(x *pb.DeleteRequest, t *pb.Transaction) {
27 | x.Transaction = t
28 | })
29 | }
30 |
31 | // ErrConcurrentTransaction is returned when a transaction is rolled back due
32 | // to a conflict with a concurrent transaction.
33 | var ErrConcurrentTransaction = errors.New("datastore: concurrent transaction")
34 |
35 | // RunInTransaction runs f in a transaction. It calls f with a transaction
36 | // context tc that f should use for all App Engine operations.
37 | //
38 | // If f returns nil, RunInTransaction attempts to commit the transaction,
39 | // returning nil if it succeeds. If the commit fails due to a conflicting
40 | // transaction, RunInTransaction retries f, each time with a new transaction
41 | // context. It gives up and returns ErrConcurrentTransaction after three
42 | // failed attempts. The number of attempts can be configured by specifying
43 | // TransactionOptions.Attempts.
44 | //
45 | // If f returns non-nil, then any datastore changes will not be applied and
46 | // RunInTransaction returns that same error. The function f is not retried.
47 | //
48 | // Note that when f returns, the transaction is not yet committed. Calling code
49 | // must be careful not to assume that any of f's changes have been committed
50 | // until RunInTransaction returns nil.
51 | //
52 | // Since f may be called multiple times, f should usually be idempotent.
53 | // datastore.Get is not idempotent when unmarshaling slice fields.
54 | //
55 | // Nested transactions are not supported; c may not be a transaction context.
56 | func RunInTransaction(c context.Context, f func(tc context.Context) error, opts *TransactionOptions) error {
57 | xg := false
58 | if opts != nil {
59 | xg = opts.XG
60 | }
61 | readOnly := false
62 | if opts != nil {
63 | readOnly = opts.ReadOnly
64 | }
65 | attempts := 3
66 | if opts != nil && opts.Attempts > 0 {
67 | attempts = opts.Attempts
68 | }
69 | var t *pb.Transaction
70 | var err error
71 | for i := 0; i < attempts; i++ {
72 | if t, err = internal.RunTransactionOnce(c, f, xg, readOnly, t); err != internal.ErrConcurrentTransaction {
73 | return err
74 | }
75 | }
76 | return ErrConcurrentTransaction
77 | }
78 |
79 | // TransactionOptions are the options for running a transaction.
80 | type TransactionOptions struct {
81 | // XG is whether the transaction can cross multiple entity groups. In
82 | // comparison, a single group transaction is one where all datastore keys
83 | // used have the same root key. Note that cross group transactions do not
84 | // have the same behavior as single group transactions. In particular, it
85 | // is much more likely to see partially applied transactions in different
86 | // entity groups, in global queries.
87 | // It is valid to set XG to true even if the transaction is within a
88 | // single entity group.
89 | XG bool
90 | // Attempts controls the number of retries to perform when commits fail
91 | // due to a conflicting transaction. If omitted, it defaults to 3.
92 | Attempts int
93 | // ReadOnly controls whether the transaction is a read only transaction.
94 | // Read only transactions are potentially more efficient.
95 | ReadOnly bool
96 | }
97 |
--------------------------------------------------------------------------------
/vendor/google.golang.org/appengine/errors.go:
--------------------------------------------------------------------------------
1 | // Copyright 2011 Google Inc. All rights reserved.
2 | // Use of this source code is governed by the Apache 2.0
3 | // license that can be found in the LICENSE file.
4 |
5 | // This file provides error functions for common API failure modes.
6 |
7 | package appengine
8 |
9 | import (
10 | "fmt"
11 |
12 | "google.golang.org/appengine/internal"
13 | )
14 |
15 | // IsOverQuota reports whether err represents an API call failure
16 | // due to insufficient available quota.
17 | func IsOverQuota(err error) bool {
18 | callErr, ok := err.(*internal.CallError)
19 | return ok && callErr.Code == 4
20 | }
21 |
22 | // MultiError is returned by batch operations when there are errors with
23 | // particular elements. Errors will be in a one-to-one correspondence with
24 | // the input elements; successful elements will have a nil entry.
25 | type MultiError []error
26 |
27 | func (m MultiError) Error() string {
28 | s, n := "", 0
29 | for _, e := range m {
30 | if e != nil {
31 | if n == 0 {
32 | s = e.Error()
33 | }
34 | n++
35 | }
36 | }
37 | switch n {
38 | case 0:
39 | return "(0 errors)"
40 | case 1:
41 | return s
42 | case 2:
43 | return s + " (and 1 other error)"
44 | }
45 | return fmt.Sprintf("%s (and %d other errors)", s, n-1)
46 | }
47 |
--------------------------------------------------------------------------------
/vendor/google.golang.org/appengine/internal/app_id.go:
--------------------------------------------------------------------------------
1 | // Copyright 2011 Google Inc. All rights reserved.
2 | // Use of this source code is governed by the Apache 2.0
3 | // license that can be found in the LICENSE file.
4 |
5 | package internal
6 |
7 | import (
8 | "strings"
9 | )
10 |
11 | func parseFullAppID(appid string) (partition, domain, displayID string) {
12 | if i := strings.Index(appid, "~"); i != -1 {
13 | partition, appid = appid[:i], appid[i+1:]
14 | }
15 | if i := strings.Index(appid, ":"); i != -1 {
16 | domain, appid = appid[:i], appid[i+1:]
17 | }
18 | return partition, domain, appid
19 | }
20 |
21 | // appID returns "appid" or "domain.com:appid".
22 | func appID(fullAppID string) string {
23 | _, dom, dis := parseFullAppID(fullAppID)
24 | if dom != "" {
25 | return dom + ":" + dis
26 | }
27 | return dis
28 | }
29 |
--------------------------------------------------------------------------------
/vendor/google.golang.org/appengine/internal/app_identity/app_identity_service.proto:
--------------------------------------------------------------------------------
1 | syntax = "proto2";
2 | option go_package = "app_identity";
3 |
4 | package appengine;
5 |
6 | message AppIdentityServiceError {
7 | enum ErrorCode {
8 | SUCCESS = 0;
9 | UNKNOWN_SCOPE = 9;
10 | BLOB_TOO_LARGE = 1000;
11 | DEADLINE_EXCEEDED = 1001;
12 | NOT_A_VALID_APP = 1002;
13 | UNKNOWN_ERROR = 1003;
14 | NOT_ALLOWED = 1005;
15 | NOT_IMPLEMENTED = 1006;
16 | }
17 | }
18 |
19 | message SignForAppRequest {
20 | optional bytes bytes_to_sign = 1;
21 | }
22 |
23 | message SignForAppResponse {
24 | optional string key_name = 1;
25 | optional bytes signature_bytes = 2;
26 | }
27 |
28 | message GetPublicCertificateForAppRequest {
29 | }
30 |
31 | message PublicCertificate {
32 | optional string key_name = 1;
33 | optional string x509_certificate_pem = 2;
34 | }
35 |
36 | message GetPublicCertificateForAppResponse {
37 | repeated PublicCertificate public_certificate_list = 1;
38 | optional int64 max_client_cache_time_in_second = 2;
39 | }
40 |
41 | message GetServiceAccountNameRequest {
42 | }
43 |
44 | message GetServiceAccountNameResponse {
45 | optional string service_account_name = 1;
46 | }
47 |
48 | message GetAccessTokenRequest {
49 | repeated string scope = 1;
50 | optional int64 service_account_id = 2;
51 | optional string service_account_name = 3;
52 | }
53 |
54 | message GetAccessTokenResponse {
55 | optional string access_token = 1;
56 | optional int64 expiration_time = 2;
57 | }
58 |
59 | message GetDefaultGcsBucketNameRequest {
60 | }
61 |
62 | message GetDefaultGcsBucketNameResponse {
63 | optional string default_gcs_bucket_name = 1;
64 | }
65 |
--------------------------------------------------------------------------------
/vendor/google.golang.org/appengine/internal/base/api_base.proto:
--------------------------------------------------------------------------------
1 | // Built-in base types for API calls. Primarily useful as return types.
2 |
3 | syntax = "proto2";
4 | option go_package = "base";
5 |
6 | package appengine.base;
7 |
8 | message StringProto {
9 | required string value = 1;
10 | }
11 |
12 | message Integer32Proto {
13 | required int32 value = 1;
14 | }
15 |
16 | message Integer64Proto {
17 | required int64 value = 1;
18 | }
19 |
20 | message BoolProto {
21 | required bool value = 1;
22 | }
23 |
24 | message DoubleProto {
25 | required double value = 1;
26 | }
27 |
28 | message BytesProto {
29 | required bytes value = 1 [ctype=CORD];
30 | }
31 |
32 | message VoidProto {
33 | }
34 |
--------------------------------------------------------------------------------
/vendor/google.golang.org/appengine/internal/identity.go:
--------------------------------------------------------------------------------
1 | // Copyright 2011 Google Inc. All rights reserved.
2 | // Use of this source code is governed by the Apache 2.0
3 | // license that can be found in the LICENSE file.
4 |
5 | package internal
6 |
7 | import netcontext "golang.org/x/net/context"
8 |
9 | // These functions are implementations of the wrapper functions
10 | // in ../appengine/identity.go. See that file for commentary.
11 |
12 | func AppID(c netcontext.Context) string {
13 | return appID(FullyQualifiedAppID(c))
14 | }
15 |
--------------------------------------------------------------------------------
/vendor/google.golang.org/appengine/internal/identity_classic.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 Google Inc. All rights reserved.
2 | // Use of this source code is governed by the Apache 2.0
3 | // license that can be found in the LICENSE file.
4 |
5 | // +build appengine
6 |
7 | package internal
8 |
9 | import (
10 | "appengine"
11 |
12 | netcontext "golang.org/x/net/context"
13 | )
14 |
15 | func DefaultVersionHostname(ctx netcontext.Context) string {
16 | c := fromContext(ctx)
17 | if c == nil {
18 | panic(errNotAppEngineContext)
19 | }
20 | return appengine.DefaultVersionHostname(c)
21 | }
22 |
23 | func Datacenter(_ netcontext.Context) string { return appengine.Datacenter() }
24 | func ServerSoftware() string { return appengine.ServerSoftware() }
25 | func InstanceID() string { return appengine.InstanceID() }
26 | func IsDevAppServer() bool { return appengine.IsDevAppServer() }
27 |
28 | func RequestID(ctx netcontext.Context) string {
29 | c := fromContext(ctx)
30 | if c == nil {
31 | panic(errNotAppEngineContext)
32 | }
33 | return appengine.RequestID(c)
34 | }
35 |
36 | func ModuleName(ctx netcontext.Context) string {
37 | c := fromContext(ctx)
38 | if c == nil {
39 | panic(errNotAppEngineContext)
40 | }
41 | return appengine.ModuleName(c)
42 | }
43 | func VersionID(ctx netcontext.Context) string {
44 | c := fromContext(ctx)
45 | if c == nil {
46 | panic(errNotAppEngineContext)
47 | }
48 | return appengine.VersionID(c)
49 | }
50 |
51 | func fullyQualifiedAppID(ctx netcontext.Context) string {
52 | c := fromContext(ctx)
53 | if c == nil {
54 | panic(errNotAppEngineContext)
55 | }
56 | return c.FullyQualifiedAppID()
57 | }
58 |
--------------------------------------------------------------------------------
/vendor/google.golang.org/appengine/internal/identity_vm.go:
--------------------------------------------------------------------------------
1 | // Copyright 2011 Google Inc. All rights reserved.
2 | // Use of this source code is governed by the Apache 2.0
3 | // license that can be found in the LICENSE file.
4 |
5 | // +build !appengine
6 |
7 | package internal
8 |
9 | import (
10 | "net/http"
11 | "os"
12 |
13 | netcontext "golang.org/x/net/context"
14 | )
15 |
16 | // These functions are implementations of the wrapper functions
17 | // in ../appengine/identity.go. See that file for commentary.
18 |
19 | const (
20 | hDefaultVersionHostname = "X-AppEngine-Default-Version-Hostname"
21 | hRequestLogId = "X-AppEngine-Request-Log-Id"
22 | hDatacenter = "X-AppEngine-Datacenter"
23 | )
24 |
25 | func ctxHeaders(ctx netcontext.Context) http.Header {
26 | c := fromContext(ctx)
27 | if c == nil {
28 | return nil
29 | }
30 | return c.Request().Header
31 | }
32 |
33 | func DefaultVersionHostname(ctx netcontext.Context) string {
34 | return ctxHeaders(ctx).Get(hDefaultVersionHostname)
35 | }
36 |
37 | func RequestID(ctx netcontext.Context) string {
38 | return ctxHeaders(ctx).Get(hRequestLogId)
39 | }
40 |
41 | func Datacenter(ctx netcontext.Context) string {
42 | return ctxHeaders(ctx).Get(hDatacenter)
43 | }
44 |
45 | func ServerSoftware() string {
46 | // TODO(dsymonds): Remove fallback when we've verified this.
47 | if s := os.Getenv("SERVER_SOFTWARE"); s != "" {
48 | return s
49 | }
50 | return "Google App Engine/1.x.x"
51 | }
52 |
53 | // TODO(dsymonds): Remove the metadata fetches.
54 |
55 | func ModuleName(_ netcontext.Context) string {
56 | if s := os.Getenv("GAE_MODULE_NAME"); s != "" {
57 | return s
58 | }
59 | return string(mustGetMetadata("instance/attributes/gae_backend_name"))
60 | }
61 |
62 | func VersionID(_ netcontext.Context) string {
63 | if s1, s2 := os.Getenv("GAE_MODULE_VERSION"), os.Getenv("GAE_MINOR_VERSION"); s1 != "" && s2 != "" {
64 | return s1 + "." + s2
65 | }
66 | return string(mustGetMetadata("instance/attributes/gae_backend_version")) + "." + string(mustGetMetadata("instance/attributes/gae_backend_minor_version"))
67 | }
68 |
69 | func InstanceID() string {
70 | if s := os.Getenv("GAE_MODULE_INSTANCE"); s != "" {
71 | return s
72 | }
73 | return string(mustGetMetadata("instance/attributes/gae_backend_instance"))
74 | }
75 |
76 | func partitionlessAppID() string {
77 | // gae_project has everything except the partition prefix.
78 | appID := os.Getenv("GAE_LONG_APP_ID")
79 | if appID == "" {
80 | appID = string(mustGetMetadata("instance/attributes/gae_project"))
81 | }
82 | return appID
83 | }
84 |
85 | func fullyQualifiedAppID(_ netcontext.Context) string {
86 | appID := partitionlessAppID()
87 |
88 | part := os.Getenv("GAE_PARTITION")
89 | if part == "" {
90 | part = string(mustGetMetadata("instance/attributes/gae_partition"))
91 | }
92 |
93 | if part != "" {
94 | appID = part + "~" + appID
95 | }
96 | return appID
97 | }
98 |
99 | func IsDevAppServer() bool {
100 | return os.Getenv("RUN_WITH_DEVAPPSERVER") != ""
101 | }
102 |
--------------------------------------------------------------------------------
/vendor/google.golang.org/appengine/internal/internal.go:
--------------------------------------------------------------------------------
1 | // Copyright 2011 Google Inc. All rights reserved.
2 | // Use of this source code is governed by the Apache 2.0
3 | // license that can be found in the LICENSE file.
4 |
5 | // Package internal provides support for package appengine.
6 | //
7 | // Programs should not use this package directly. Its API is not stable.
8 | // Use packages appengine and appengine/* instead.
9 | package internal
10 |
11 | import (
12 | "fmt"
13 |
14 | "github.com/golang/protobuf/proto"
15 |
16 | remotepb "google.golang.org/appengine/internal/remote_api"
17 | )
18 |
19 | // errorCodeMaps is a map of service name to the error code map for the service.
20 | var errorCodeMaps = make(map[string]map[int32]string)
21 |
22 | // RegisterErrorCodeMap is called from API implementations to register their
23 | // error code map. This should only be called from init functions.
24 | func RegisterErrorCodeMap(service string, m map[int32]string) {
25 | errorCodeMaps[service] = m
26 | }
27 |
28 | type timeoutCodeKey struct {
29 | service string
30 | code int32
31 | }
32 |
33 | // timeoutCodes is the set of service+code pairs that represent timeouts.
34 | var timeoutCodes = make(map[timeoutCodeKey]bool)
35 |
36 | func RegisterTimeoutErrorCode(service string, code int32) {
37 | timeoutCodes[timeoutCodeKey{service, code}] = true
38 | }
39 |
40 | // APIError is the type returned by appengine.Context's Call method
41 | // when an API call fails in an API-specific way. This may be, for instance,
42 | // a taskqueue API call failing with TaskQueueServiceError::UNKNOWN_QUEUE.
43 | type APIError struct {
44 | Service string
45 | Detail string
46 | Code int32 // API-specific error code
47 | }
48 |
49 | func (e *APIError) Error() string {
50 | if e.Code == 0 {
51 | if e.Detail == "" {
52 | return "APIError "
53 | }
54 | return e.Detail
55 | }
56 | s := fmt.Sprintf("API error %d", e.Code)
57 | if m, ok := errorCodeMaps[e.Service]; ok {
58 | s += " (" + e.Service + ": " + m[e.Code] + ")"
59 | } else {
60 | // Shouldn't happen, but provide a bit more detail if it does.
61 | s = e.Service + " " + s
62 | }
63 | if e.Detail != "" {
64 | s += ": " + e.Detail
65 | }
66 | return s
67 | }
68 |
69 | func (e *APIError) IsTimeout() bool {
70 | return timeoutCodes[timeoutCodeKey{e.Service, e.Code}]
71 | }
72 |
73 | // CallError is the type returned by appengine.Context's Call method when an
74 | // API call fails in a generic way, such as RpcError::CAPABILITY_DISABLED.
75 | type CallError struct {
76 | Detail string
77 | Code int32
78 | // TODO: Remove this if we get a distinguishable error code.
79 | Timeout bool
80 | }
81 |
82 | func (e *CallError) Error() string {
83 | var msg string
84 | switch remotepb.RpcError_ErrorCode(e.Code) {
85 | case remotepb.RpcError_UNKNOWN:
86 | return e.Detail
87 | case remotepb.RpcError_OVER_QUOTA:
88 | msg = "Over quota"
89 | case remotepb.RpcError_CAPABILITY_DISABLED:
90 | msg = "Capability disabled"
91 | case remotepb.RpcError_CANCELLED:
92 | msg = "Canceled"
93 | default:
94 | msg = fmt.Sprintf("Call error %d", e.Code)
95 | }
96 | s := msg + ": " + e.Detail
97 | if e.Timeout {
98 | s += " (timeout)"
99 | }
100 | return s
101 | }
102 |
103 | func (e *CallError) IsTimeout() bool {
104 | return e.Timeout
105 | }
106 |
107 | // NamespaceMods is a map from API service to a function that will mutate an RPC request to attach a namespace.
108 | // The function should be prepared to be called on the same message more than once; it should only modify the
109 | // RPC request the first time.
110 | var NamespaceMods = make(map[string]func(m proto.Message, namespace string))
111 |
--------------------------------------------------------------------------------
/vendor/google.golang.org/appengine/internal/main.go:
--------------------------------------------------------------------------------
1 | // Copyright 2011 Google Inc. All rights reserved.
2 | // Use of this source code is governed by the Apache 2.0
3 | // license that can be found in the LICENSE file.
4 |
5 | // +build appengine
6 |
7 | package internal
8 |
9 | import (
10 | "appengine_internal"
11 | )
12 |
13 | func Main() {
14 | appengine_internal.Main()
15 | }
16 |
--------------------------------------------------------------------------------
/vendor/google.golang.org/appengine/internal/main_vm.go:
--------------------------------------------------------------------------------
1 | // Copyright 2011 Google Inc. All rights reserved.
2 | // Use of this source code is governed by the Apache 2.0
3 | // license that can be found in the LICENSE file.
4 |
5 | // +build !appengine
6 |
7 | package internal
8 |
9 | import (
10 | "io"
11 | "log"
12 | "net/http"
13 | "net/url"
14 | "os"
15 | )
16 |
17 | func Main() {
18 | installHealthChecker(http.DefaultServeMux)
19 |
20 | port := "8080"
21 | if s := os.Getenv("PORT"); s != "" {
22 | port = s
23 | }
24 |
25 | host := ""
26 | if IsDevAppServer() {
27 | host = "127.0.0.1"
28 | }
29 | if err := http.ListenAndServe(host+":"+port, http.HandlerFunc(handleHTTP)); err != nil {
30 | log.Fatalf("http.ListenAndServe: %v", err)
31 | }
32 | }
33 |
34 | func installHealthChecker(mux *http.ServeMux) {
35 | // If no health check handler has been installed by this point, add a trivial one.
36 | const healthPath = "/_ah/health"
37 | hreq := &http.Request{
38 | Method: "GET",
39 | URL: &url.URL{
40 | Path: healthPath,
41 | },
42 | }
43 | if _, pat := mux.Handler(hreq); pat != healthPath {
44 | mux.HandleFunc(healthPath, func(w http.ResponseWriter, r *http.Request) {
45 | io.WriteString(w, "ok")
46 | })
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/vendor/google.golang.org/appengine/internal/metadata.go:
--------------------------------------------------------------------------------
1 | // Copyright 2014 Google Inc. All rights reserved.
2 | // Use of this source code is governed by the Apache 2.0
3 | // license that can be found in the LICENSE file.
4 |
5 | package internal
6 |
7 | // This file has code for accessing metadata.
8 | //
9 | // References:
10 | // https://cloud.google.com/compute/docs/metadata
11 |
12 | import (
13 | "fmt"
14 | "io/ioutil"
15 | "log"
16 | "net/http"
17 | "net/url"
18 | )
19 |
20 | const (
21 | metadataHost = "metadata"
22 | metadataPath = "/computeMetadata/v1/"
23 | )
24 |
25 | var (
26 | metadataRequestHeaders = http.Header{
27 | "Metadata-Flavor": []string{"Google"},
28 | }
29 | )
30 |
31 | // TODO(dsymonds): Do we need to support default values, like Python?
32 | func mustGetMetadata(key string) []byte {
33 | b, err := getMetadata(key)
34 | if err != nil {
35 | log.Fatalf("Metadata fetch failed: %v", err)
36 | }
37 | return b
38 | }
39 |
40 | func getMetadata(key string) ([]byte, error) {
41 | // TODO(dsymonds): May need to use url.Parse to support keys with query args.
42 | req := &http.Request{
43 | Method: "GET",
44 | URL: &url.URL{
45 | Scheme: "http",
46 | Host: metadataHost,
47 | Path: metadataPath + key,
48 | },
49 | Header: metadataRequestHeaders,
50 | Host: metadataHost,
51 | }
52 | resp, err := http.DefaultClient.Do(req)
53 | if err != nil {
54 | return nil, err
55 | }
56 | defer resp.Body.Close()
57 | if resp.StatusCode != 200 {
58 | return nil, fmt.Errorf("metadata server returned HTTP %d", resp.StatusCode)
59 | }
60 | return ioutil.ReadAll(resp.Body)
61 | }
62 |
--------------------------------------------------------------------------------
/vendor/google.golang.org/appengine/internal/modules/modules_service.proto:
--------------------------------------------------------------------------------
1 | syntax = "proto2";
2 | option go_package = "modules";
3 |
4 | package appengine;
5 |
6 | message ModulesServiceError {
7 | enum ErrorCode {
8 | OK = 0;
9 | INVALID_MODULE = 1;
10 | INVALID_VERSION = 2;
11 | INVALID_INSTANCES = 3;
12 | TRANSIENT_ERROR = 4;
13 | UNEXPECTED_STATE = 5;
14 | }
15 | }
16 |
17 | message GetModulesRequest {
18 | }
19 |
20 | message GetModulesResponse {
21 | repeated string module = 1;
22 | }
23 |
24 | message GetVersionsRequest {
25 | optional string module = 1;
26 | }
27 |
28 | message GetVersionsResponse {
29 | repeated string version = 1;
30 | }
31 |
32 | message GetDefaultVersionRequest {
33 | optional string module = 1;
34 | }
35 |
36 | message GetDefaultVersionResponse {
37 | required string version = 1;
38 | }
39 |
40 | message GetNumInstancesRequest {
41 | optional string module = 1;
42 | optional string version = 2;
43 | }
44 |
45 | message GetNumInstancesResponse {
46 | required int64 instances = 1;
47 | }
48 |
49 | message SetNumInstancesRequest {
50 | optional string module = 1;
51 | optional string version = 2;
52 | required int64 instances = 3;
53 | }
54 |
55 | message SetNumInstancesResponse {}
56 |
57 | message StartModuleRequest {
58 | required string module = 1;
59 | required string version = 2;
60 | }
61 |
62 | message StartModuleResponse {}
63 |
64 | message StopModuleRequest {
65 | optional string module = 1;
66 | optional string version = 2;
67 | }
68 |
69 | message StopModuleResponse {}
70 |
71 | message GetHostnameRequest {
72 | optional string module = 1;
73 | optional string version = 2;
74 | optional string instance = 3;
75 | }
76 |
77 | message GetHostnameResponse {
78 | required string hostname = 1;
79 | }
80 |
81 |
--------------------------------------------------------------------------------
/vendor/google.golang.org/appengine/internal/net.go:
--------------------------------------------------------------------------------
1 | // Copyright 2014 Google Inc. All rights reserved.
2 | // Use of this source code is governed by the Apache 2.0
3 | // license that can be found in the LICENSE file.
4 |
5 | package internal
6 |
7 | // This file implements a network dialer that limits the number of concurrent connections.
8 | // It is only used for API calls.
9 |
10 | import (
11 | "log"
12 | "net"
13 | "runtime"
14 | "sync"
15 | "time"
16 | )
17 |
18 | var limitSem = make(chan int, 100) // TODO(dsymonds): Use environment variable.
19 |
20 | func limitRelease() {
21 | // non-blocking
22 | select {
23 | case <-limitSem:
24 | default:
25 | // This should not normally happen.
26 | log.Print("appengine: unbalanced limitSem release!")
27 | }
28 | }
29 |
30 | func limitDial(network, addr string) (net.Conn, error) {
31 | limitSem <- 1
32 |
33 | // Dial with a timeout in case the API host is MIA.
34 | // The connection should normally be very fast.
35 | conn, err := net.DialTimeout(network, addr, 500*time.Millisecond)
36 | if err != nil {
37 | limitRelease()
38 | return nil, err
39 | }
40 | lc := &limitConn{Conn: conn}
41 | runtime.SetFinalizer(lc, (*limitConn).Close) // shouldn't usually be required
42 | return lc, nil
43 | }
44 |
45 | type limitConn struct {
46 | close sync.Once
47 | net.Conn
48 | }
49 |
50 | func (lc *limitConn) Close() error {
51 | defer lc.close.Do(func() {
52 | limitRelease()
53 | runtime.SetFinalizer(lc, nil)
54 | })
55 | return lc.Conn.Close()
56 | }
57 |
--------------------------------------------------------------------------------
/vendor/google.golang.org/appengine/internal/regen.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash -e
2 | #
3 | # This script rebuilds the generated code for the protocol buffers.
4 | # To run this you will need protoc and goprotobuf installed;
5 | # see https://github.com/golang/protobuf for instructions.
6 |
7 | PKG=google.golang.org/appengine
8 |
9 | function die() {
10 | echo 1>&2 $*
11 | exit 1
12 | }
13 |
14 | # Sanity check that the right tools are accessible.
15 | for tool in go protoc protoc-gen-go; do
16 | q=$(which $tool) || die "didn't find $tool"
17 | echo 1>&2 "$tool: $q"
18 | done
19 |
20 | echo -n 1>&2 "finding package dir... "
21 | pkgdir=$(go list -f '{{.Dir}}' $PKG)
22 | echo 1>&2 $pkgdir
23 | base=$(echo $pkgdir | sed "s,/$PKG\$,,")
24 | echo 1>&2 "base: $base"
25 | cd $base
26 |
27 | # Run protoc once per package.
28 | for dir in $(find $PKG/internal -name '*.proto' | xargs dirname | sort | uniq); do
29 | echo 1>&2 "* $dir"
30 | protoc --go_out=. $dir/*.proto
31 | done
32 |
33 | for f in $(find $PKG/internal -name '*.pb.go'); do
34 | # Remove proto.RegisterEnum calls.
35 | # These cause duplicate registration panics when these packages
36 | # are used on classic App Engine. proto.RegisterEnum only affects
37 | # parsing the text format; we don't care about that.
38 | # https://code.google.com/p/googleappengine/issues/detail?id=11670#c17
39 | sed -i '/proto.RegisterEnum/d' $f
40 | done
41 |
--------------------------------------------------------------------------------
/vendor/google.golang.org/appengine/internal/remote_api/remote_api.proto:
--------------------------------------------------------------------------------
1 | syntax = "proto2";
2 | option go_package = "remote_api";
3 |
4 | package remote_api;
5 |
6 | message Request {
7 | required string service_name = 2;
8 | required string method = 3;
9 | required bytes request = 4;
10 | optional string request_id = 5;
11 | }
12 |
13 | message ApplicationError {
14 | required int32 code = 1;
15 | required string detail = 2;
16 | }
17 |
18 | message RpcError {
19 | enum ErrorCode {
20 | UNKNOWN = 0;
21 | CALL_NOT_FOUND = 1;
22 | PARSE_ERROR = 2;
23 | SECURITY_VIOLATION = 3;
24 | OVER_QUOTA = 4;
25 | REQUEST_TOO_LARGE = 5;
26 | CAPABILITY_DISABLED = 6;
27 | FEATURE_DISABLED = 7;
28 | BAD_REQUEST = 8;
29 | RESPONSE_TOO_LARGE = 9;
30 | CANCELLED = 10;
31 | REPLAY_ERROR = 11;
32 | DEADLINE_EXCEEDED = 12;
33 | }
34 | required int32 code = 1;
35 | optional string detail = 2;
36 | }
37 |
38 | message Response {
39 | optional bytes response = 1;
40 | optional bytes exception = 2;
41 | optional ApplicationError application_error = 3;
42 | optional bytes java_exception = 4;
43 | optional RpcError rpc_error = 5;
44 | }
45 |
--------------------------------------------------------------------------------
/vendor/google.golang.org/appengine/internal/transaction.go:
--------------------------------------------------------------------------------
1 | // Copyright 2014 Google Inc. All rights reserved.
2 | // Use of this source code is governed by the Apache 2.0
3 | // license that can be found in the LICENSE file.
4 |
5 | package internal
6 |
7 | // This file implements hooks for applying datastore transactions.
8 |
9 | import (
10 | "errors"
11 | "reflect"
12 |
13 | "github.com/golang/protobuf/proto"
14 | netcontext "golang.org/x/net/context"
15 |
16 | basepb "google.golang.org/appengine/internal/base"
17 | pb "google.golang.org/appengine/internal/datastore"
18 | )
19 |
20 | var transactionSetters = make(map[reflect.Type]reflect.Value)
21 |
22 | // RegisterTransactionSetter registers a function that sets transaction information
23 | // in a protocol buffer message. f should be a function with two arguments,
24 | // the first being a protocol buffer type, and the second being *datastore.Transaction.
25 | func RegisterTransactionSetter(f interface{}) {
26 | v := reflect.ValueOf(f)
27 | transactionSetters[v.Type().In(0)] = v
28 | }
29 |
30 | // applyTransaction applies the transaction t to message pb
31 | // by using the relevant setter passed to RegisterTransactionSetter.
32 | func applyTransaction(pb proto.Message, t *pb.Transaction) {
33 | v := reflect.ValueOf(pb)
34 | if f, ok := transactionSetters[v.Type()]; ok {
35 | f.Call([]reflect.Value{v, reflect.ValueOf(t)})
36 | }
37 | }
38 |
39 | var transactionKey = "used for *Transaction"
40 |
41 | func transactionFromContext(ctx netcontext.Context) *transaction {
42 | t, _ := ctx.Value(&transactionKey).(*transaction)
43 | return t
44 | }
45 |
46 | func withTransaction(ctx netcontext.Context, t *transaction) netcontext.Context {
47 | return netcontext.WithValue(ctx, &transactionKey, t)
48 | }
49 |
50 | type transaction struct {
51 | transaction pb.Transaction
52 | finished bool
53 | }
54 |
55 | var ErrConcurrentTransaction = errors.New("internal: concurrent transaction")
56 |
57 | func RunTransactionOnce(c netcontext.Context, f func(netcontext.Context) error, xg bool, readOnly bool, previousTransaction *pb.Transaction) (*pb.Transaction, error) {
58 | if transactionFromContext(c) != nil {
59 | return nil, errors.New("nested transactions are not supported")
60 | }
61 |
62 | // Begin the transaction.
63 | t := &transaction{}
64 | req := &pb.BeginTransactionRequest{
65 | App: proto.String(FullyQualifiedAppID(c)),
66 | }
67 | if xg {
68 | req.AllowMultipleEg = proto.Bool(true)
69 | }
70 | if previousTransaction != nil {
71 | req.PreviousTransaction = previousTransaction
72 | }
73 | if readOnly {
74 | req.Mode = pb.BeginTransactionRequest_READ_ONLY.Enum()
75 | }
76 | if err := Call(c, "datastore_v3", "BeginTransaction", req, &t.transaction); err != nil {
77 | return nil, err
78 | }
79 |
80 | // Call f, rolling back the transaction if f returns a non-nil error, or panics.
81 | // The panic is not recovered.
82 | defer func() {
83 | if t.finished {
84 | return
85 | }
86 | t.finished = true
87 | // Ignore the error return value, since we are already returning a non-nil
88 | // error (or we're panicking).
89 | Call(c, "datastore_v3", "Rollback", &t.transaction, &basepb.VoidProto{})
90 | }()
91 | if err := f(withTransaction(c, t)); err != nil {
92 | return &t.transaction, err
93 | }
94 | t.finished = true
95 |
96 | // Commit the transaction.
97 | res := &pb.CommitResponse{}
98 | err := Call(c, "datastore_v3", "Commit", &t.transaction, res)
99 | if ae, ok := err.(*APIError); ok {
100 | /* TODO: restore this conditional
101 | if appengine.IsDevAppServer() {
102 | */
103 | // The Python Dev AppServer raises an ApplicationError with error code 2 (which is
104 | // Error.CONCURRENT_TRANSACTION) and message "Concurrency exception.".
105 | if ae.Code == int32(pb.Error_BAD_REQUEST) && ae.Detail == "ApplicationError: 2 Concurrency exception." {
106 | return &t.transaction, ErrConcurrentTransaction
107 | }
108 | if ae.Code == int32(pb.Error_CONCURRENT_TRANSACTION) {
109 | return &t.transaction, ErrConcurrentTransaction
110 | }
111 | }
112 | return &t.transaction, err
113 | }
114 |
--------------------------------------------------------------------------------
/vendor/google.golang.org/appengine/internal/urlfetch/urlfetch_service.proto:
--------------------------------------------------------------------------------
1 | syntax = "proto2";
2 | option go_package = "urlfetch";
3 |
4 | package appengine;
5 |
6 | message URLFetchServiceError {
7 | enum ErrorCode {
8 | OK = 0;
9 | INVALID_URL = 1;
10 | FETCH_ERROR = 2;
11 | UNSPECIFIED_ERROR = 3;
12 | RESPONSE_TOO_LARGE = 4;
13 | DEADLINE_EXCEEDED = 5;
14 | SSL_CERTIFICATE_ERROR = 6;
15 | DNS_ERROR = 7;
16 | CLOSED = 8;
17 | INTERNAL_TRANSIENT_ERROR = 9;
18 | TOO_MANY_REDIRECTS = 10;
19 | MALFORMED_REPLY = 11;
20 | CONNECTION_ERROR = 12;
21 | }
22 | }
23 |
24 | message URLFetchRequest {
25 | enum RequestMethod {
26 | GET = 1;
27 | POST = 2;
28 | HEAD = 3;
29 | PUT = 4;
30 | DELETE = 5;
31 | PATCH = 6;
32 | }
33 | required RequestMethod Method = 1;
34 | required string Url = 2;
35 | repeated group Header = 3 {
36 | required string Key = 4;
37 | required string Value = 5;
38 | }
39 | optional bytes Payload = 6 [ctype=CORD];
40 |
41 | optional bool FollowRedirects = 7 [default=true];
42 |
43 | optional double Deadline = 8;
44 |
45 | optional bool MustValidateServerCertificate = 9 [default=true];
46 | }
47 |
48 | message URLFetchResponse {
49 | optional bytes Content = 1;
50 | required int32 StatusCode = 2;
51 | repeated group Header = 3 {
52 | required string Key = 4;
53 | required string Value = 5;
54 | }
55 | optional bool ContentWasTruncated = 6 [default=false];
56 | optional int64 ExternalBytesSent = 7;
57 | optional int64 ExternalBytesReceived = 8;
58 |
59 | optional string FinalUrl = 9;
60 |
61 | optional int64 ApiCpuMilliseconds = 10 [default=0];
62 | optional int64 ApiBytesSent = 11 [default=0];
63 | optional int64 ApiBytesReceived = 12 [default=0];
64 | }
65 |
--------------------------------------------------------------------------------
/vendor/google.golang.org/appengine/internal/user/user_service.proto:
--------------------------------------------------------------------------------
1 | syntax = "proto2";
2 | option go_package = "user";
3 |
4 | package appengine;
5 |
6 | message UserServiceError {
7 | enum ErrorCode {
8 | OK = 0;
9 | REDIRECT_URL_TOO_LONG = 1;
10 | NOT_ALLOWED = 2;
11 | OAUTH_INVALID_TOKEN = 3;
12 | OAUTH_INVALID_REQUEST = 4;
13 | OAUTH_ERROR = 5;
14 | }
15 | }
16 |
17 | message CreateLoginURLRequest {
18 | required string destination_url = 1;
19 | optional string auth_domain = 2;
20 | optional string federated_identity = 3 [default = ""];
21 | }
22 |
23 | message CreateLoginURLResponse {
24 | required string login_url = 1;
25 | }
26 |
27 | message CreateLogoutURLRequest {
28 | required string destination_url = 1;
29 | optional string auth_domain = 2;
30 | }
31 |
32 | message CreateLogoutURLResponse {
33 | required string logout_url = 1;
34 | }
35 |
36 | message GetOAuthUserRequest {
37 | optional string scope = 1;
38 |
39 | repeated string scopes = 2;
40 | }
41 |
42 | message GetOAuthUserResponse {
43 | required string email = 1;
44 | required string user_id = 2;
45 | required string auth_domain = 3;
46 | optional string user_organization = 4 [default = ""];
47 | optional bool is_admin = 5 [default = false];
48 | optional string client_id = 6 [default = ""];
49 |
50 | repeated string scopes = 7;
51 | }
52 |
53 | message CheckOAuthSignatureRequest {
54 | }
55 |
56 | message CheckOAuthSignatureResponse {
57 | required string oauth_consumer_key = 1;
58 | }
59 |
--------------------------------------------------------------------------------
/vendor/google.golang.org/appengine/log/api.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 Google Inc. All rights reserved.
2 | // Use of this source code is governed by the Apache 2.0
3 | // license that can be found in the LICENSE file.
4 |
5 | package log
6 |
7 | // This file implements the logging API.
8 |
9 | import (
10 | "golang.org/x/net/context"
11 |
12 | "google.golang.org/appengine/internal"
13 | )
14 |
15 | // Debugf formats its arguments according to the format, analogous to fmt.Printf,
16 | // and records the text as a log message at Debug level. The message will be associated
17 | // with the request linked with the provided context.
18 | func Debugf(ctx context.Context, format string, args ...interface{}) {
19 | internal.Logf(ctx, 0, format, args...)
20 | }
21 |
22 | // Infof is like Debugf, but at Info level.
23 | func Infof(ctx context.Context, format string, args ...interface{}) {
24 | internal.Logf(ctx, 1, format, args...)
25 | }
26 |
27 | // Warningf is like Debugf, but at Warning level.
28 | func Warningf(ctx context.Context, format string, args ...interface{}) {
29 | internal.Logf(ctx, 2, format, args...)
30 | }
31 |
32 | // Errorf is like Debugf, but at Error level.
33 | func Errorf(ctx context.Context, format string, args ...interface{}) {
34 | internal.Logf(ctx, 3, format, args...)
35 | }
36 |
37 | // Criticalf is like Debugf, but at Critical level.
38 | func Criticalf(ctx context.Context, format string, args ...interface{}) {
39 | internal.Logf(ctx, 4, format, args...)
40 | }
41 |
--------------------------------------------------------------------------------
/vendor/google.golang.org/appengine/namespace.go:
--------------------------------------------------------------------------------
1 | // Copyright 2012 Google Inc. All rights reserved.
2 | // Use of this source code is governed by the Apache 2.0
3 | // license that can be found in the LICENSE file.
4 |
5 | package appengine
6 |
7 | import (
8 | "fmt"
9 | "regexp"
10 |
11 | "golang.org/x/net/context"
12 |
13 | "google.golang.org/appengine/internal"
14 | )
15 |
16 | // Namespace returns a replacement context that operates within the given namespace.
17 | func Namespace(c context.Context, namespace string) (context.Context, error) {
18 | if !validNamespace.MatchString(namespace) {
19 | return nil, fmt.Errorf("appengine: namespace %q does not match /%s/", namespace, validNamespace)
20 | }
21 | return internal.NamespacedContext(c, namespace), nil
22 | }
23 |
24 | // validNamespace matches valid namespace names.
25 | var validNamespace = regexp.MustCompile(`^[0-9A-Za-z._-]{0,100}$`)
26 |
--------------------------------------------------------------------------------
/vendor/google.golang.org/appengine/timeout.go:
--------------------------------------------------------------------------------
1 | // Copyright 2013 Google Inc. All rights reserved.
2 | // Use of this source code is governed by the Apache 2.0
3 | // license that can be found in the LICENSE file.
4 |
5 | package appengine
6 |
7 | import "golang.org/x/net/context"
8 |
9 | // IsTimeoutError reports whether err is a timeout error.
10 | func IsTimeoutError(err error) bool {
11 | if err == context.DeadlineExceeded {
12 | return true
13 | }
14 | if t, ok := err.(interface {
15 | IsTimeout() bool
16 | }); ok {
17 | return t.IsTimeout()
18 | }
19 | return false
20 | }
21 |
--------------------------------------------------------------------------------
/vendor/google.golang.org/appengine/user/oauth.go:
--------------------------------------------------------------------------------
1 | // Copyright 2012 Google Inc. All rights reserved.
2 | // Use of this source code is governed by the Apache 2.0
3 | // license that can be found in the LICENSE file.
4 |
5 | package user
6 |
7 | import (
8 | "golang.org/x/net/context"
9 |
10 | "google.golang.org/appengine/internal"
11 | pb "google.golang.org/appengine/internal/user"
12 | )
13 |
14 | // CurrentOAuth returns the user associated with the OAuth consumer making this
15 | // request. If the OAuth consumer did not make a valid OAuth request, or the
16 | // scopes is non-empty and the current user does not have at least one of the
17 | // scopes, this method will return an error.
18 | func CurrentOAuth(c context.Context, scopes ...string) (*User, error) {
19 | req := &pb.GetOAuthUserRequest{}
20 | if len(scopes) != 1 || scopes[0] != "" {
21 | // The signature for this function used to be CurrentOAuth(Context, string).
22 | // Ignore the singular "" scope to preserve existing behavior.
23 | req.Scopes = scopes
24 | }
25 |
26 | res := &pb.GetOAuthUserResponse{}
27 |
28 | err := internal.Call(c, "user", "GetOAuthUser", req, res)
29 | if err != nil {
30 | return nil, err
31 | }
32 | return &User{
33 | Email: *res.Email,
34 | AuthDomain: *res.AuthDomain,
35 | Admin: res.GetIsAdmin(),
36 | ID: *res.UserId,
37 | ClientID: res.GetClientId(),
38 | }, nil
39 | }
40 |
41 | // OAuthConsumerKey returns the OAuth consumer key provided with the current
42 | // request. This method will return an error if the OAuth request was invalid.
43 | func OAuthConsumerKey(c context.Context) (string, error) {
44 | req := &pb.CheckOAuthSignatureRequest{}
45 | res := &pb.CheckOAuthSignatureResponse{}
46 |
47 | err := internal.Call(c, "user", "CheckOAuthSignature", req, res)
48 | if err != nil {
49 | return "", err
50 | }
51 | return *res.OauthConsumerKey, err
52 | }
53 |
--------------------------------------------------------------------------------
/vendor/google.golang.org/appengine/user/user.go:
--------------------------------------------------------------------------------
1 | // Copyright 2011 Google Inc. All rights reserved.
2 | // Use of this source code is governed by the Apache 2.0
3 | // license that can be found in the LICENSE file.
4 |
5 | // Package user provides a client for App Engine's user authentication service.
6 | package user // import "google.golang.org/appengine/user"
7 |
8 | import (
9 | "strings"
10 |
11 | "github.com/golang/protobuf/proto"
12 | "golang.org/x/net/context"
13 |
14 | "google.golang.org/appengine/internal"
15 | pb "google.golang.org/appengine/internal/user"
16 | )
17 |
18 | // User represents a user of the application.
19 | type User struct {
20 | Email string
21 | AuthDomain string
22 | Admin bool
23 |
24 | // ID is the unique permanent ID of the user.
25 | // It is populated if the Email is associated
26 | // with a Google account, or empty otherwise.
27 | ID string
28 |
29 | // ClientID is the ID of the pre-registered client so its identity can be verified.
30 | // See https://developers.google.com/console/help/#generatingoauth2 for more information.
31 | ClientID string
32 |
33 | FederatedIdentity string
34 | FederatedProvider string
35 | }
36 |
37 | // String returns a displayable name for the user.
38 | func (u *User) String() string {
39 | if u.AuthDomain != "" && strings.HasSuffix(u.Email, "@"+u.AuthDomain) {
40 | return u.Email[:len(u.Email)-len("@"+u.AuthDomain)]
41 | }
42 | if u.FederatedIdentity != "" {
43 | return u.FederatedIdentity
44 | }
45 | return u.Email
46 | }
47 |
48 | // LoginURL returns a URL that, when visited, prompts the user to sign in,
49 | // then redirects the user to the URL specified by dest.
50 | func LoginURL(c context.Context, dest string) (string, error) {
51 | return LoginURLFederated(c, dest, "")
52 | }
53 |
54 | // LoginURLFederated is like LoginURL but accepts a user's OpenID identifier.
55 | func LoginURLFederated(c context.Context, dest, identity string) (string, error) {
56 | req := &pb.CreateLoginURLRequest{
57 | DestinationUrl: proto.String(dest),
58 | }
59 | if identity != "" {
60 | req.FederatedIdentity = proto.String(identity)
61 | }
62 | res := &pb.CreateLoginURLResponse{}
63 | if err := internal.Call(c, "user", "CreateLoginURL", req, res); err != nil {
64 | return "", err
65 | }
66 | return *res.LoginUrl, nil
67 | }
68 |
69 | // LogoutURL returns a URL that, when visited, signs the user out,
70 | // then redirects the user to the URL specified by dest.
71 | func LogoutURL(c context.Context, dest string) (string, error) {
72 | req := &pb.CreateLogoutURLRequest{
73 | DestinationUrl: proto.String(dest),
74 | }
75 | res := &pb.CreateLogoutURLResponse{}
76 | if err := internal.Call(c, "user", "CreateLogoutURL", req, res); err != nil {
77 | return "", err
78 | }
79 | return *res.LogoutUrl, nil
80 | }
81 |
82 | func init() {
83 | internal.RegisterErrorCodeMap("user", pb.UserServiceError_ErrorCode_name)
84 | }
85 |
--------------------------------------------------------------------------------
/vendor/google.golang.org/appengine/user/user_classic.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 Google Inc. All rights reserved.
2 | // Use of this source code is governed by the Apache 2.0
3 | // license that can be found in the LICENSE file.
4 |
5 | // +build appengine
6 |
7 | package user
8 |
9 | import (
10 | "appengine/user"
11 |
12 | "golang.org/x/net/context"
13 |
14 | "google.golang.org/appengine/internal"
15 | )
16 |
17 | func Current(ctx context.Context) *User {
18 | c, err := internal.ClassicContextFromContext(ctx)
19 | if err != nil {
20 | panic(err)
21 | }
22 | u := user.Current(c)
23 | if u == nil {
24 | return nil
25 | }
26 | // Map appengine/user.User to this package's User type.
27 | return &User{
28 | Email: u.Email,
29 | AuthDomain: u.AuthDomain,
30 | Admin: u.Admin,
31 | ID: u.ID,
32 | FederatedIdentity: u.FederatedIdentity,
33 | FederatedProvider: u.FederatedProvider,
34 | }
35 | }
36 |
37 | func IsAdmin(ctx context.Context) bool {
38 | c, err := internal.ClassicContextFromContext(ctx)
39 | if err != nil {
40 | panic(err)
41 | }
42 |
43 | return user.IsAdmin(c)
44 | }
45 |
--------------------------------------------------------------------------------
/vendor/google.golang.org/appengine/user/user_vm.go:
--------------------------------------------------------------------------------
1 | // Copyright 2014 Google Inc. All rights reserved.
2 | // Use of this source code is governed by the Apache 2.0
3 | // license that can be found in the LICENSE file.
4 |
5 | // +build !appengine
6 |
7 | package user
8 |
9 | import (
10 | "golang.org/x/net/context"
11 |
12 | "google.golang.org/appengine/internal"
13 | )
14 |
15 | // Current returns the currently logged-in user,
16 | // or nil if the user is not signed in.
17 | func Current(c context.Context) *User {
18 | h := internal.IncomingHeaders(c)
19 | u := &User{
20 | Email: h.Get("X-AppEngine-User-Email"),
21 | AuthDomain: h.Get("X-AppEngine-Auth-Domain"),
22 | ID: h.Get("X-AppEngine-User-Id"),
23 | Admin: h.Get("X-AppEngine-User-Is-Admin") == "1",
24 | FederatedIdentity: h.Get("X-AppEngine-Federated-Identity"),
25 | FederatedProvider: h.Get("X-AppEngine-Federated-Provider"),
26 | }
27 | if u.Email == "" && u.FederatedIdentity == "" {
28 | return nil
29 | }
30 | return u
31 | }
32 |
33 | // IsAdmin returns true if the current user is signed in and
34 | // is currently registered as an administrator of the application.
35 | func IsAdmin(c context.Context) bool {
36 | h := internal.IncomingHeaders(c)
37 | return h.Get("X-AppEngine-User-Is-Admin") == "1"
38 | }
39 |
--------------------------------------------------------------------------------