chore: update azure go-autorest dependencies
Signed-off-by: David Justice <david@devigned.com>
This commit is contained in:
parent
eda4e7152a
commit
3e68d47da6
509 changed files with 78876 additions and 112493 deletions
208
vendor/github.com/Azure/azure-sdk-for-go/storage/client.go
generated
vendored
208
vendor/github.com/Azure/azure-sdk-for-go/storage/client.go
generated
vendored
|
@ -1,19 +1,8 @@
|
|||
// Package storage provides clients for Microsoft Azure Storage Services.
|
||||
package storage
|
||||
|
||||
// Copyright 2017 Microsoft Corporation
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
|
@ -46,7 +35,7 @@ const (
|
|||
|
||||
// DefaultAPIVersion is the Azure Storage API version string used when a
|
||||
// basic client is created.
|
||||
DefaultAPIVersion = "2016-05-31"
|
||||
DefaultAPIVersion = "2018-03-28"
|
||||
|
||||
defaultUseHTTPS = true
|
||||
defaultRetryAttempts = 5
|
||||
|
@ -85,6 +74,7 @@ const (
|
|||
|
||||
var (
|
||||
validStorageAccount = regexp.MustCompile("^[0-9a-z]{3,24}$")
|
||||
validCosmosAccount = regexp.MustCompile("^[0-9a-z-]{3,44}$")
|
||||
defaultValidStatusCodes = []int{
|
||||
http.StatusRequestTimeout, // 408
|
||||
http.StatusInternalServerError, // 500
|
||||
|
@ -117,7 +107,7 @@ func (ds *DefaultSender) Send(c *Client, req *http.Request) (resp *http.Response
|
|||
return resp, err
|
||||
}
|
||||
resp, err = c.HTTPClient.Do(rr.Request())
|
||||
if err != nil || !autorest.ResponseHasStatusCode(resp, ds.ValidStatusCodes...) {
|
||||
if err == nil && !autorest.ResponseHasStatusCode(resp, ds.ValidStatusCodes...) {
|
||||
return resp, err
|
||||
}
|
||||
drainRespBody(resp)
|
||||
|
@ -141,15 +131,16 @@ type Client struct {
|
|||
// automatic retry strategy built in. The Sender can be customized.
|
||||
Sender Sender
|
||||
|
||||
accountName string
|
||||
accountKey []byte
|
||||
useHTTPS bool
|
||||
UseSharedKeyLite bool
|
||||
baseURL string
|
||||
apiVersion string
|
||||
userAgent string
|
||||
sasClient bool
|
||||
accountSASToken url.Values
|
||||
accountName string
|
||||
accountKey []byte
|
||||
useHTTPS bool
|
||||
UseSharedKeyLite bool
|
||||
baseURL string
|
||||
apiVersion string
|
||||
userAgent string
|
||||
sasClient bool
|
||||
accountSASToken url.Values
|
||||
additionalHeaders map[string]string
|
||||
}
|
||||
|
||||
type odataResponse struct {
|
||||
|
@ -174,6 +165,23 @@ type AzureStorageServiceError struct {
|
|||
APIVersion string
|
||||
}
|
||||
|
||||
// AzureTablesServiceError contains fields of the error response from
|
||||
// Azure Table Storage Service REST API in Atom format.
|
||||
// See https://msdn.microsoft.com/en-us/library/azure/dd179382.aspx
|
||||
type AzureTablesServiceError struct {
|
||||
Code string `xml:"code"`
|
||||
Message string `xml:"message"`
|
||||
StatusCode int
|
||||
RequestID string
|
||||
Date string
|
||||
APIVersion string
|
||||
}
|
||||
|
||||
func (e AzureTablesServiceError) Error() string {
|
||||
return fmt.Sprintf("storage: service returned error: StatusCode=%d, ErrorCode=%s, ErrorMessage=%s, RequestInitiated=%s, RequestId=%s, API Version=%s",
|
||||
e.StatusCode, e.Code, e.Message, e.Date, e.RequestID, e.APIVersion)
|
||||
}
|
||||
|
||||
type odataErrorMessage struct {
|
||||
Lang string `json:"lang"`
|
||||
Value string `json:"value"`
|
||||
|
@ -308,10 +316,36 @@ func NewClient(accountName, accountKey, serviceBaseURL, apiVersion string, useHT
|
|||
return c, fmt.Errorf("azure: malformed storage account key: %v", err)
|
||||
}
|
||||
|
||||
c = Client{
|
||||
return newClient(accountName, key, serviceBaseURL, apiVersion, useHTTPS)
|
||||
}
|
||||
|
||||
// NewCosmosClient constructs a Client for Azure CosmosDB. This should be used if the caller wants
|
||||
// to specify whether to use HTTPS, a specific REST API version or a custom
|
||||
// cosmos endpoint than Azure Public Cloud.
|
||||
func NewCosmosClient(accountName, accountKey, serviceBaseURL, apiVersion string, useHTTPS bool) (Client, error) {
|
||||
var c Client
|
||||
if !IsValidCosmosAccount(accountName) {
|
||||
return c, fmt.Errorf("azure: account name is not valid: The name can contain only lowercase letters, numbers and the '-' character, and must be between 3 and 44 characters: %v", accountName)
|
||||
} else if accountKey == "" {
|
||||
return c, fmt.Errorf("azure: account key required")
|
||||
} else if serviceBaseURL == "" {
|
||||
return c, fmt.Errorf("azure: base storage service url required")
|
||||
}
|
||||
|
||||
key, err := base64.StdEncoding.DecodeString(accountKey)
|
||||
if err != nil {
|
||||
return c, fmt.Errorf("azure: malformed cosmos account key: %v", err)
|
||||
}
|
||||
|
||||
return newClient(accountName, key, serviceBaseURL, apiVersion, useHTTPS)
|
||||
}
|
||||
|
||||
// newClient constructs a Client with given parameters.
|
||||
func newClient(accountName string, accountKey []byte, serviceBaseURL, apiVersion string, useHTTPS bool) (Client, error) {
|
||||
c := Client{
|
||||
HTTPClient: http.DefaultClient,
|
||||
accountName: accountName,
|
||||
accountKey: key,
|
||||
accountKey: accountKey,
|
||||
useHTTPS: useHTTPS,
|
||||
baseURL: serviceBaseURL,
|
||||
apiVersion: apiVersion,
|
||||
|
@ -333,18 +367,16 @@ func IsValidStorageAccount(account string) bool {
|
|||
return validStorageAccount.MatchString(account)
|
||||
}
|
||||
|
||||
// IsValidCosmosAccount checks if the Cosmos account name is valid.
|
||||
// See https://docs.microsoft.com/en-us/azure/cosmos-db/how-to-manage-database-account
|
||||
func IsValidCosmosAccount(account string) bool {
|
||||
return validCosmosAccount.MatchString(account)
|
||||
}
|
||||
|
||||
// NewAccountSASClient contructs a client that uses accountSAS authorization
|
||||
// for its operations.
|
||||
func NewAccountSASClient(account string, token url.Values, env azure.Environment) Client {
|
||||
c := newSASClient()
|
||||
c.accountSASToken = token
|
||||
c.accountName = account
|
||||
c.baseURL = env.StorageEndpointSuffix
|
||||
|
||||
// Get API version and protocol from token
|
||||
c.apiVersion = token.Get("sv")
|
||||
c.useHTTPS = token.Get("spr") == "https"
|
||||
return c
|
||||
return newSASClient(account, env.StorageEndpointSuffix, token)
|
||||
}
|
||||
|
||||
// NewAccountSASClientFromEndpointToken constructs a client that uses accountSAS authorization
|
||||
|
@ -354,12 +386,39 @@ func NewAccountSASClientFromEndpointToken(endpoint string, sasToken string) (Cli
|
|||
if err != nil {
|
||||
return Client{}, err
|
||||
}
|
||||
|
||||
token, err := url.ParseQuery(sasToken)
|
||||
_, err = url.ParseQuery(sasToken)
|
||||
if err != nil {
|
||||
return Client{}, err
|
||||
}
|
||||
u.RawQuery = sasToken
|
||||
return newSASClientFromURL(u)
|
||||
}
|
||||
|
||||
func newSASClient(accountName, baseURL string, sasToken url.Values) Client {
|
||||
c := Client{
|
||||
HTTPClient: http.DefaultClient,
|
||||
apiVersion: DefaultAPIVersion,
|
||||
sasClient: true,
|
||||
Sender: &DefaultSender{
|
||||
RetryAttempts: defaultRetryAttempts,
|
||||
ValidStatusCodes: defaultValidStatusCodes,
|
||||
RetryDuration: defaultRetryDuration,
|
||||
},
|
||||
accountName: accountName,
|
||||
baseURL: baseURL,
|
||||
accountSASToken: sasToken,
|
||||
useHTTPS: defaultUseHTTPS,
|
||||
}
|
||||
c.userAgent = c.getDefaultUserAgent()
|
||||
// Get API version and protocol from token
|
||||
c.apiVersion = sasToken.Get("sv")
|
||||
if spr := sasToken.Get("spr"); spr != "" {
|
||||
c.useHTTPS = spr == "https"
|
||||
}
|
||||
return c
|
||||
}
|
||||
|
||||
func newSASClientFromURL(u *url.URL) (Client, error) {
|
||||
// the host name will look something like this
|
||||
// - foo.blob.core.windows.net
|
||||
// "foo" is the account name
|
||||
|
@ -377,30 +436,13 @@ func NewAccountSASClientFromEndpointToken(endpoint string, sasToken string) (Cli
|
|||
return Client{}, fmt.Errorf("failed to find '.' in %s", u.Host[i1+1:])
|
||||
}
|
||||
|
||||
c := newSASClient()
|
||||
c.accountSASToken = token
|
||||
c.accountName = u.Host[:i1]
|
||||
c.baseURL = u.Host[i1+i2+2:]
|
||||
|
||||
// Get API version and protocol from token
|
||||
c.apiVersion = token.Get("sv")
|
||||
c.useHTTPS = token.Get("spr") == "https"
|
||||
return c, nil
|
||||
}
|
||||
|
||||
func newSASClient() Client {
|
||||
c := Client{
|
||||
HTTPClient: http.DefaultClient,
|
||||
apiVersion: DefaultAPIVersion,
|
||||
sasClient: true,
|
||||
Sender: &DefaultSender{
|
||||
RetryAttempts: defaultRetryAttempts,
|
||||
ValidStatusCodes: defaultValidStatusCodes,
|
||||
RetryDuration: defaultRetryDuration,
|
||||
},
|
||||
sasToken := u.Query()
|
||||
c := newSASClient(u.Host[:i1], u.Host[i1+i2+2:], sasToken)
|
||||
if spr := sasToken.Get("spr"); spr == "" {
|
||||
// infer from URL if not in the query params set
|
||||
c.useHTTPS = u.Scheme == "https"
|
||||
}
|
||||
c.userAgent = c.getDefaultUserAgent()
|
||||
return c
|
||||
return c, nil
|
||||
}
|
||||
|
||||
func (c Client) isServiceSASClient() bool {
|
||||
|
@ -430,6 +472,16 @@ func (c *Client) AddToUserAgent(extension string) error {
|
|||
return fmt.Errorf("Extension was empty, User Agent stayed as %s", c.userAgent)
|
||||
}
|
||||
|
||||
// AddAdditionalHeaders adds additional standard headers
|
||||
func (c *Client) AddAdditionalHeaders(headers map[string]string) {
|
||||
if headers != nil {
|
||||
c.additionalHeaders = map[string]string{}
|
||||
for k, v := range headers {
|
||||
c.additionalHeaders[k] = v
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// protectUserAgent is used in funcs that include extraheaders as a parameter.
|
||||
// It prevents the User-Agent header to be overwritten, instead if it happens to
|
||||
// be present, it gets added to the current User-Agent. Use it before getStandardHeaders
|
||||
|
@ -694,11 +746,16 @@ func (c Client) GetFileService() FileServiceClient {
|
|||
}
|
||||
|
||||
func (c Client) getStandardHeaders() map[string]string {
|
||||
return map[string]string{
|
||||
userAgentHeader: c.userAgent,
|
||||
"x-ms-version": c.apiVersion,
|
||||
"x-ms-date": currentTimeRfc1123Formatted(),
|
||||
headers := map[string]string{}
|
||||
for k, v := range c.additionalHeaders {
|
||||
headers[k] = v
|
||||
}
|
||||
|
||||
headers[userAgentHeader] = c.userAgent
|
||||
headers["x-ms-version"] = c.apiVersion
|
||||
headers["x-ms-date"] = currentTimeRfc1123Formatted()
|
||||
|
||||
return headers
|
||||
}
|
||||
|
||||
func (c Client) exec(verb, url string, headers map[string]string, body io.Reader, auth authentication) (*http.Response, error) {
|
||||
|
@ -777,8 +834,21 @@ func (c Client) execInternalJSONCommon(verb, url string, headers map[string]stri
|
|||
err = serviceErrFromStatusCode(resp.StatusCode, resp.Status, requestID, date, version)
|
||||
return respToRet, req, resp, err
|
||||
}
|
||||
// try unmarshal as odata.error json
|
||||
err = json.Unmarshal(respBody, &respToRet.odata)
|
||||
// response contains storage service error object, unmarshal
|
||||
if resp.Header.Get("Content-Type") == "application/xml" {
|
||||
storageErr := AzureTablesServiceError{
|
||||
StatusCode: resp.StatusCode,
|
||||
RequestID: requestID,
|
||||
Date: date,
|
||||
APIVersion: version,
|
||||
}
|
||||
if err := xml.Unmarshal(respBody, &storageErr); err != nil {
|
||||
storageErr.Message = fmt.Sprintf("Response body could no be unmarshaled: %v. Body: %v.", err, string(respBody))
|
||||
}
|
||||
err = storageErr
|
||||
} else {
|
||||
err = json.Unmarshal(respBody, &respToRet.odata)
|
||||
}
|
||||
}
|
||||
|
||||
return respToRet, req, resp, err
|
||||
|
@ -883,8 +953,10 @@ func readAndCloseBody(body io.ReadCloser) ([]byte, error) {
|
|||
|
||||
// reads the response body then closes it
|
||||
func drainRespBody(resp *http.Response) {
|
||||
io.Copy(ioutil.Discard, resp.Body)
|
||||
resp.Body.Close()
|
||||
if resp != nil {
|
||||
io.Copy(ioutil.Discard, resp.Body)
|
||||
resp.Body.Close()
|
||||
}
|
||||
}
|
||||
|
||||
func serviceErrFromXML(body []byte, storageErr *AzureStorageServiceError) error {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue