Commit 78a6a77a authored by Wojciech Tyczynski's avatar Wojciech Tyczynski

Update Google API dependencies

parent dbb8bf52
......@@ -2530,31 +2530,31 @@
},
{
"ImportPath": "google.golang.org/api/cloudmonitoring/v2beta2",
"Rev": "a69f0f19d246419bb931b0ac8f4f8d3f3e6d4feb"
"Rev": "55146ba61254fdb1c26d65ff3c04bc1611ad73fb"
},
{
"ImportPath": "google.golang.org/api/compute/v1",
"Rev": "a69f0f19d246419bb931b0ac8f4f8d3f3e6d4feb"
"Rev": "55146ba61254fdb1c26d65ff3c04bc1611ad73fb"
},
{
"ImportPath": "google.golang.org/api/container/v1",
"Rev": "a69f0f19d246419bb931b0ac8f4f8d3f3e6d4feb"
"Rev": "55146ba61254fdb1c26d65ff3c04bc1611ad73fb"
},
{
"ImportPath": "google.golang.org/api/dns/v1",
"Rev": "a69f0f19d246419bb931b0ac8f4f8d3f3e6d4feb"
"Rev": "55146ba61254fdb1c26d65ff3c04bc1611ad73fb"
},
{
"ImportPath": "google.golang.org/api/gensupport",
"Rev": "a69f0f19d246419bb931b0ac8f4f8d3f3e6d4feb"
"Rev": "55146ba61254fdb1c26d65ff3c04bc1611ad73fb"
},
{
"ImportPath": "google.golang.org/api/googleapi",
"Rev": "a69f0f19d246419bb931b0ac8f4f8d3f3e6d4feb"
"Rev": "55146ba61254fdb1c26d65ff3c04bc1611ad73fb"
},
{
"ImportPath": "google.golang.org/api/googleapi/internal/uritemplates",
"Rev": "a69f0f19d246419bb931b0ac8f4f8d3f3e6d4feb"
"Rev": "55146ba61254fdb1c26d65ff3c04bc1611ad73fb"
},
{
"ImportPath": "google.golang.org/appengine",
......
{
"kind": "discovery#restDescription",
"etag": "\"bRFOOrZKfO9LweMbPqu0kcu6De8/A2G_NAa29vne9MPSojupRQ5bVuo\"",
"etag": "\"tbys6C40o18GZwyMen5GMkdK-3s/mLggzdz9EvP0lVEQoxoRvdSJShg\"",
"discoveryVersion": "v1",
"id": "cloudmonitoring:v2beta2",
"name": "cloudmonitoring",
"canonicalName": "Cloud Monitoring",
"version": "v2beta2",
"revision": "20160314",
"revision": "20161031",
"title": "Cloud Monitoring API",
"description": "Accesses Google Cloud Monitoring data.",
"ownerDomain": "google.com",
"ownerName": "Google",
"icons": {
"x16": "http://www.google.com/images/icons/product/search-16.gif",
"x32": "http://www.google.com/images/icons/product/search-32.gif"
"x16": "https://www.gstatic.com/images/branding/product/1x/googleg_16dp.png",
"x32": "https://www.gstatic.com/images/branding/product/1x/googleg_32dp.png"
},
"documentationLink": "https://cloud.google.com/monitoring/v2beta2/",
"protocol": "rest",
......
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
{
"kind": "discovery#restDescription",
"etag": "\"jQLIOHBVnDZie4rQHGH1WJF-INE/ctEt-71wWAltEdgLnIcGLfJZeFE\"",
"etag": "\"tbys6C40o18GZwyMen5GMkdK-3s/RqBsQyB2YZT-ZAkK7pcLByI9SZs\"",
"discoveryVersion": "v1",
"id": "dns:v1",
"name": "dns",
"version": "v1",
"revision": "20160413",
"revision": "20161110",
"title": "Google Cloud DNS API",
"description": "Configures and serves authoritative DNS records.",
"ownerDomain": "google.com",
"ownerName": "Google",
"icons": {
"x16": "http://www.google.com/images/icons/product/search-16.gif",
"x32": "http://www.google.com/images/icons/product/search-32.gif"
"x16": "https://www.gstatic.com/images/branding/product/1x/googleg_16dp.png",
"x32": "https://www.gstatic.com/images/branding/product/1x/googleg_32dp.png"
},
"documentationLink": "https://developers.google.com/cloud-dns",
"protocol": "rest",
......@@ -183,7 +183,7 @@
},
"name": {
"type": "string",
"description": "User assigned name for this resource. Must be unique within the project. The name must be 1-32 characters long, must begin with a letter, end with a letter or digit, and only contain lowercase letters, digits or dashes."
"description": "User assigned name for this resource. Must be unique within the project. The name must be 1-63 characters long, must begin with a letter, end with a letter or digit, and only contain lowercase letters, digits or dashes."
},
"nameServerSet": {
"type": "string",
......
......@@ -12,13 +12,13 @@ import (
)
// MarshalJSON returns a JSON encoding of schema containing only selected fields.
// A field is selected if:
// * it has a non-empty value, or
// * its field name is present in forceSendFields, and
// * it is not a nil pointer or nil interface.
// A field is selected if any of the following is true:
// * it has a non-empty value
// * its field name is present in forceSendFields and it is not a nil pointer or nil interface
// * its field name is present in nullFields.
// The JSON key for each selected field is taken from the field's json: struct tag.
func MarshalJSON(schema interface{}, forceSendFields []string) ([]byte, error) {
if len(forceSendFields) == 0 {
func MarshalJSON(schema interface{}, forceSendFields, nullFields []string) ([]byte, error) {
if len(forceSendFields) == 0 && len(nullFields) == 0 {
return json.Marshal(schema)
}
......@@ -26,15 +26,19 @@ func MarshalJSON(schema interface{}, forceSendFields []string) ([]byte, error) {
for _, f := range forceSendFields {
mustInclude[f] = struct{}{}
}
useNull := make(map[string]struct{})
for _, f := range nullFields {
useNull[f] = struct{}{}
}
dataMap, err := schemaToMap(schema, mustInclude)
dataMap, err := schemaToMap(schema, mustInclude, useNull)
if err != nil {
return nil, err
}
return json.Marshal(dataMap)
}
func schemaToMap(schema interface{}, mustInclude map[string]struct{}) (map[string]interface{}, error) {
func schemaToMap(schema interface{}, mustInclude, useNull map[string]struct{}) (map[string]interface{}, error) {
m := make(map[string]interface{})
s := reflect.ValueOf(schema)
st := s.Type()
......@@ -54,6 +58,14 @@ func schemaToMap(schema interface{}, mustInclude map[string]struct{}) (map[strin
v := s.Field(i)
f := st.Field(i)
if _, ok := useNull[f.Name]; ok {
if !isEmptyValue(v) {
return nil, fmt.Errorf("field %q in NullFields has non-empty value", f.Name)
}
m[tag.apiName] = nil
continue
}
if !includeField(v, f, mustInclude) {
continue
}
......
......@@ -5,6 +5,7 @@
package gensupport
import (
"errors"
"fmt"
"io"
"net/http"
......@@ -15,10 +16,6 @@ import (
)
const (
// statusResumeIncomplete is the code returned by the Google uploader
// when the transfer is not yet complete.
statusResumeIncomplete = 308
// statusTooManyRequests is returned by the storage API if the
// per-project limits have been temporarily exceeded. The request
// should be retried.
......@@ -79,8 +76,23 @@ func (rx *ResumableUpload) doUploadRequest(ctx context.Context, data io.Reader,
req.Header.Set("Content-Range", contentRange)
req.Header.Set("Content-Type", rx.MediaType)
req.Header.Set("User-Agent", rx.UserAgent)
// Google's upload endpoint uses status code 308 for a
// different purpose than the "308 Permanent Redirect"
// since-standardized in RFC 7238. Because of the conflict in
// semantics, Google added this new request header which
// causes it to not use "308" and instead reply with 200 OK
// and sets the upload-specific "X-HTTP-Status-Code-Override:
// 308" response header.
req.Header.Set("X-GUploader-No-308", "yes")
return SendRequest(ctx, rx.Client, req)
}
func statusResumeIncomplete(resp *http.Response) bool {
// This is how the server signals "status resume incomplete"
// when X-GUploader-No-308 is set to "yes":
return resp != nil && resp.Header.Get("X-Http-Status-Code-Override") == "308"
}
// reportProgress calls a user-supplied callback to report upload progress.
......@@ -111,11 +123,17 @@ func (rx *ResumableUpload) transferChunk(ctx context.Context) (*http.Response, e
return res, err
}
if res.StatusCode == statusResumeIncomplete || res.StatusCode == http.StatusOK {
// We sent "X-GUploader-No-308: yes" (see comment elsewhere in
// this file), so we don't expect to get a 308.
if res.StatusCode == 308 {
return nil, errors.New("unexpected 308 response status code")
}
if res.StatusCode == http.StatusOK {
rx.reportProgress(off, off+int64(size))
}
if res.StatusCode == statusResumeIncomplete {
if statusResumeIncomplete(res) {
rx.Media.Next()
}
return res, nil
......@@ -177,7 +195,7 @@ func (rx *ResumableUpload) Upload(ctx context.Context) (resp *http.Response, err
// If the chunk was uploaded successfully, but there's still
// more to go, upload the next chunk without any delay.
if status == statusResumeIncomplete {
if statusResumeIncomplete(resp) {
pause = 0
backoff.Reset()
resp.Body.Close()
......
......@@ -55,23 +55,17 @@ func DefaultBackoffStrategy() BackoffStrategy {
// shouldRetry returns true if the HTTP response / error indicates that the
// request should be attempted again.
func shouldRetry(status int, err error) bool {
// Retry for 5xx response codes.
if 500 <= status && status < 600 {
if 500 <= status && status <= 599 {
return true
}
// Retry on statusTooManyRequests{
if status == statusTooManyRequests {
return true
}
// Retry on unexpected EOFs and temporary network errors.
if err == io.ErrUnexpectedEOF {
return true
}
if err, ok := err.(net.Error); ok {
return err.Temporary()
}
return false
}
......@@ -50,7 +50,7 @@ const (
// UserAgent is the header string used to identify this package.
UserAgent = "google-api-go-client/" + Version
// The default chunk size to use for resumable uplods if not specified by the user.
// The default chunk size to use for resumable uploads if not specified by the user.
DefaultUploadChunkSize = 8 * 1024 * 1024
// The minimum chunk size that can be used for resumable uploads. All
......
......@@ -6,6 +6,7 @@ package googleapi
import (
"encoding/json"
"errors"
"strconv"
)
......@@ -149,6 +150,25 @@ func (s Float64s) MarshalJSON() ([]byte, error) {
})
}
// RawMessage is a raw encoded JSON value.
// It is identical to json.RawMessage, except it does not suffer from
// https://golang.org/issue/14493.
type RawMessage []byte
// MarshalJSON returns m.
func (m RawMessage) MarshalJSON() ([]byte, error) {
return m, nil
}
// UnmarshalJSON sets *m to a copy of data.
func (m *RawMessage) UnmarshalJSON(data []byte) error {
if m == nil {
return errors.New("googleapi.RawMessage: UnmarshalJSON on nil pointer")
}
*m = append((*m)[:0], data...)
return nil
}
/*
* Helper routines for simplifying the creation of optional fields of basic type.
*/
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment