From 3f1859af26406461ddb4eed5addd8430d2f0c73a Mon Sep 17 00:00:00 2001 From: Milos Gajdos Date: Wed, 16 Aug 2023 08:39:20 +0100 Subject: [PATCH] Remove oss storage driver and alicdn storage driver middleware This commit removes `oss` storage driver from distribution as well as `alicdn` storage middleware which only works with the `oss` driver. There are several reasons for it: * no real-life expertise among the maintainers * oss is compatible with S3 API operations required by S3 storage driver Signed-off-by: Milos Gajdos --- BUILDING.md | 2 - Dockerfile | 2 +- cmd/registry/main.go | 2 - dockerfiles/lint.Dockerfile | 2 +- docs/configuration.md | 36 - docs/introduction.md | 8 +- docs/storage-drivers/index.md | 2 +- docs/storage-drivers/oss.md | 23 - go.mod | 1 - go.sum | 2 - .../driver/middleware/alicdn/middleware.go | 115 -- registry/storage/driver/oss/doc.go | 3 - registry/storage/driver/oss/oss.go | 710 -------- registry/storage/driver/oss/oss_test.go | 149 -- .../denverdino/aliyungo/LICENSE.txt | 191 --- .../aliyungo/cdn/auth/random_uuid.go | 97 -- .../denverdino/aliyungo/cdn/auth/sign_url.go | 80 - .../denverdino/aliyungo/common/client.go | 550 ------- .../denverdino/aliyungo/common/endpoint.go | 208 --- .../denverdino/aliyungo/common/endpoints.xml | 1370 ---------------- .../denverdino/aliyungo/common/regions.go | 55 - .../denverdino/aliyungo/common/request.go | 105 -- .../denverdino/aliyungo/common/types.go | 107 -- .../denverdino/aliyungo/common/version.go | 3 - .../aliyungo/oss/authenticate_callback.go | 88 - .../denverdino/aliyungo/oss/client.go | 1421 ----------------- .../denverdino/aliyungo/oss/export.go | 23 - .../denverdino/aliyungo/oss/multi.go | 489 ------ .../denverdino/aliyungo/oss/regions.go | 80 - .../denverdino/aliyungo/oss/signature.go | 125 -- .../denverdino/aliyungo/util/attempt.go | 76 - .../denverdino/aliyungo/util/encoding.go | 331 ---- .../denverdino/aliyungo/util/iso6801.go | 80 - .../denverdino/aliyungo/util/signature.go | 39 - .../denverdino/aliyungo/util/util.go | 185 --- vendor/modules.txt | 6 - 36 files changed, 7 insertions(+), 6759 deletions(-) delete mode 100644 docs/storage-drivers/oss.md delete mode 100755 registry/storage/driver/middleware/alicdn/middleware.go delete mode 100644 registry/storage/driver/oss/doc.go delete mode 100644 registry/storage/driver/oss/oss.go delete mode 100644 registry/storage/driver/oss/oss_test.go delete mode 100644 vendor/github.com/denverdino/aliyungo/LICENSE.txt delete mode 100644 vendor/github.com/denverdino/aliyungo/cdn/auth/random_uuid.go delete mode 100644 vendor/github.com/denverdino/aliyungo/cdn/auth/sign_url.go delete mode 100644 vendor/github.com/denverdino/aliyungo/common/client.go delete mode 100644 vendor/github.com/denverdino/aliyungo/common/endpoint.go delete mode 100644 vendor/github.com/denverdino/aliyungo/common/endpoints.xml delete mode 100644 vendor/github.com/denverdino/aliyungo/common/regions.go delete mode 100644 vendor/github.com/denverdino/aliyungo/common/request.go delete mode 100644 vendor/github.com/denverdino/aliyungo/common/types.go delete mode 100644 vendor/github.com/denverdino/aliyungo/common/version.go delete mode 100644 vendor/github.com/denverdino/aliyungo/oss/authenticate_callback.go delete mode 100644 vendor/github.com/denverdino/aliyungo/oss/client.go delete mode 100644 vendor/github.com/denverdino/aliyungo/oss/export.go delete mode 100644 vendor/github.com/denverdino/aliyungo/oss/multi.go delete mode 100644 vendor/github.com/denverdino/aliyungo/oss/regions.go delete mode 100644 vendor/github.com/denverdino/aliyungo/oss/signature.go delete mode 100644 vendor/github.com/denverdino/aliyungo/util/attempt.go delete mode 100644 vendor/github.com/denverdino/aliyungo/util/encoding.go delete mode 100644 vendor/github.com/denverdino/aliyungo/util/iso6801.go delete mode 100644 vendor/github.com/denverdino/aliyungo/util/signature.go delete mode 100644 vendor/github.com/denverdino/aliyungo/util/util.go diff --git a/BUILDING.md b/BUILDING.md index 4b405309..75487bbc 100644 --- a/BUILDING.md +++ b/BUILDING.md @@ -104,6 +104,4 @@ the environment variable `BUILDTAGS`.
Compiles without resumable digest support
include_gcs
Adds support for Google Cloud Storage
-
include_oss
-
Adds support for Alibaba Cloud Object Storage Service (OSS)
diff --git a/Dockerfile b/Dockerfile index 233044ac..13c2ec29 100644 --- a/Dockerfile +++ b/Dockerfile @@ -22,7 +22,7 @@ RUN --mount=target=. \ FROM base AS build ARG TARGETPLATFORM ARG LDFLAGS="-s -w" -ARG BUILDTAGS="include_oss,include_gcs" +ARG BUILDTAGS="include_gcs" RUN --mount=type=bind,target=/src,rw \ --mount=type=cache,target=/root/.cache/go-build \ --mount=target=/go/pkg/mod,type=cache \ diff --git a/cmd/registry/main.go b/cmd/registry/main.go index a71d078e..88cccf1d 100644 --- a/cmd/registry/main.go +++ b/cmd/registry/main.go @@ -12,10 +12,8 @@ import ( _ "github.com/distribution/distribution/v3/registry/storage/driver/filesystem" _ "github.com/distribution/distribution/v3/registry/storage/driver/gcs" _ "github.com/distribution/distribution/v3/registry/storage/driver/inmemory" - _ "github.com/distribution/distribution/v3/registry/storage/driver/middleware/alicdn" _ "github.com/distribution/distribution/v3/registry/storage/driver/middleware/cloudfront" _ "github.com/distribution/distribution/v3/registry/storage/driver/middleware/redirect" - _ "github.com/distribution/distribution/v3/registry/storage/driver/oss" _ "github.com/distribution/distribution/v3/registry/storage/driver/s3-aws" ) diff --git a/dockerfiles/lint.Dockerfile b/dockerfiles/lint.Dockerfile index a40c5ce1..f69ad37f 100644 --- a/dockerfiles/lint.Dockerfile +++ b/dockerfiles/lint.Dockerfile @@ -3,7 +3,7 @@ ARG GO_VERSION=1.19.10 ARG ALPINE_VERSION=3.18 ARG GOLANGCI_LINT_VERSION=v1.52 -ARG BUILDTAGS="include_oss,include_gcs" +ARG BUILDTAGS="include_gcs" FROM golangci/golangci-lint:${GOLANGCI_LINT_VERSION}-alpine AS golangci-lint diff --git a/docs/configuration.md b/docs/configuration.md index 23ce0dda..24aed660 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -139,18 +139,6 @@ storage: multipartcopythresholdsize: 33554432 rootdirectory: /s3/object/name/prefix usedualstack: false - oss: - accesskeyid: accesskeyid - accesskeysecret: accesskeysecret - region: OSS region name - endpoint: optional endpoints - internal: optional internal endpoint - bucket: OSS bucket - encrypt: optional enable server-side encryption - encryptionkeyid: optional KMS key id for encryption - secure: optional ssl setting - chunksize: optional size value - rootdirectory: optional root directory inmemory: # This driver takes no parameters delete: enabled: false @@ -435,18 +423,6 @@ storage: multipartcopymaxconcurrency: 100 multipartcopythresholdsize: 33554432 rootdirectory: /s3/object/name/prefix - oss: - accesskeyid: accesskeyid - accesskeysecret: accesskeysecret - region: OSS region name - endpoint: optional endpoints - internal: optional internal endpoint - bucket: OSS bucket - encrypt: optional enable server-side encryption - encryptionkeyid: optional KMS key id for encryption - secure: optional ssl setting - chunksize: optional size valye - rootdirectory: optional root directory inmemory: delete: enabled: false @@ -475,7 +451,6 @@ returns an error. You can choose any of these backend storage drivers: | `azure` | Uses Microsoft Azure Blob Storage. See the [driver's reference documentation](https://github.com/docker/docker.github.io/tree/master/registry/storage-drivers/azure.md). | | `gcs` | Uses Google Cloud Storage. See the [driver's reference documentation](https://github.com/docker/docker.github.io/tree/master/registry/storage-drivers/gcs.md). | | `s3` | Uses Amazon Simple Storage Service (S3) and compatible Storage Services. See the [driver's reference documentation](https://github.com/docker/docker.github.io/tree/master/registry/storage-drivers/s3.md). | -| `oss` | Uses Aliyun OSS for object storage. See the [driver's reference documentation](https://github.com/docker/docker.github.io/tree/master/registry/storage-drivers/oss.md). | For testing only, you can use the [`inmemory` storage driver](https://github.com/docker/docker.github.io/tree/master/registry/storage-drivers/inmemory.md). @@ -719,17 +694,6 @@ Value of `ipfilteredby` can be: | `aws` | IP from AWS goes to S3 directly | | `awsregion` | IP from certain AWS regions goes to S3 directly, use together with `awsregion`. | -### `alicdn` - -`alicdn` storage middleware allows the registry to serve layers via a content delivery network provided by Alibaba Cloud. Alicdn requires the OSS storage driver. - -| Parameter | Required | Description | -|--------------|----------|-------------------------------------------------------------------------| -| `baseurl` | yes | The `SCHEME://HOST` at which Alicdn is served. | -| `authtype` | yes | The URL authentication type for Alicdn, which should be `a`, `b` or `c`. See the [Authentication configuration](https://www.alibabacloud.com/help/doc-detail/85117.htm).| -| `privatekey` | yes | The URL authentication key for Alicdn. | -| `duration` | no | An integer and unit for the duration of the Alicdn session. Valid time units are `ns`, `us` (or `µs`), `ms`, `s`, `m`, or `h`.| - ### `redirect` You can use the `redirect` storage middleware to specify a custom URL to a diff --git a/docs/introduction.md b/docs/introduction.md index 8deb9e12..6fd5aa15 100644 --- a/docs/introduction.md +++ b/docs/introduction.md @@ -15,10 +15,10 @@ Users interact with a registry by using docker push and pull commands. Storage itself is delegated to drivers. The default storage driver is the local posix filesystem, which is suitable for development or small deployments. -Additional cloud-based storage drivers like S3, Microsoft Azure, Google Cloud Storage -and Aliyun OSS are also supported. People looking into using other storage -backends may do so by writing their own driver implementing the -[Storage API](storage-drivers/index.md). +Additional cloud-based storage drivers like S3, Microsoft Azure and Google Cloud Storage +are supported. People looking into using other storage drivers should consider if +the driver they'd like to be supported is S3 compatible like many cloud storage systems +as adding new storage driver support has been put on hold for the time being. Since securing access to your hosted images is paramount, the Registry natively supports TLS and basic authentication. diff --git a/docs/storage-drivers/index.md b/docs/storage-drivers/index.md index c0184717..bc96371b 100644 --- a/docs/storage-drivers/index.md +++ b/docs/storage-drivers/index.md @@ -17,7 +17,7 @@ This storage driver package comes bundled with several drivers: - [s3](s3.md): A driver storing objects in an Amazon Simple Storage Service (S3) bucket. - [azure](azure.md): A driver storing objects in [Microsoft Azure Blob Storage](https://azure.microsoft.com/en-us/services/storage/). - [gcs](gcs.md): A driver storing objects in a [Google Cloud Storage](https://cloud.google.com/storage/) bucket. -- [oss](oss.md): A driver storing objects in [Aliyun OSS](https://www.aliyun.com/product/oss). +- oss: *NO LONGER SUPPORTED* - swift: *NO LONGER SUPPORTED* ## Storage driver API diff --git a/docs/storage-drivers/oss.md b/docs/storage-drivers/oss.md deleted file mode 100644 index 23016dd5..00000000 --- a/docs/storage-drivers/oss.md +++ /dev/null @@ -1,23 +0,0 @@ ---- -description: Explains how to use the Aliyun OSS storage driver -keywords: registry, service, driver, images, storage, OSS, aliyun -title: Aliyun OSS storage driver ---- - -An implementation of the `storagedriver.StorageDriver` interface which uses -[Aliyun OSS](https://www.alibabacloud.com/product/oss) for object storage. - -## Parameters - -| Parameter | Required | Description | -|:--------------|:---------|:--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| -| `accesskeyid` | yes | Your access key ID. | -| `accesskeysecret` | yes | Your access key secret. | -| `region` | yes | The name of the OSS region in which you would like to store objects (for example oss-cn-beijing). For a list of regions, you can look at the [official documentation](https://www.alibabacloud.com/help/doc-detail/31837.html). | -| `endpoint` | no | An endpoint which defaults to `[bucket].[region].aliyuncs.com` or `[bucket].[region]-internal.aliyuncs.com` (when `internal=true`). You can change the default endpoint by changing this value. | -| `internal` | no | An internal endpoint or the public endpoint for OSS access. The default is false. For a list of regions, you can look at the [official documentation](https://www.alibabacloud.com/help/doc-detail/31837.html). | -| `bucket` | yes | The name of your OSS bucket where you wish to store objects (needs to already be created prior to driver initialization). | -| `encrypt` | no | Specifies whether you would like your data encrypted on the server side. Defaults to false if not specified. | -| `secure` | no | Specifies whether to transfer data to the bucket over ssl or not. If you omit this value, `true` is used. | -| `chunksize` | no | The default part size for multipart uploads (performed by WriteStream) to OSS. The default is 10 MB. Keep in mind that the minimum part size for OSS is 5MB. You might experience better performance for larger chunk sizes depending on the speed of your connection to OSS. | -| `rootdirectory` | no | The root directory tree in which to store all registry files. Defaults to an empty string (bucket root). | diff --git a/go.mod b/go.mod index b8bca8ec..73b039e4 100644 --- a/go.mod +++ b/go.mod @@ -12,7 +12,6 @@ require ( github.com/aws/aws-sdk-go v1.43.16 github.com/bshuster-repo/logrus-logstash-hook v1.0.0 github.com/bugsnag/bugsnag-go v0.0.0-20141110184014-b1d153021fcd - github.com/denverdino/aliyungo v0.0.0-20190125010748-a747050bb1ba github.com/docker/go-events v0.0.0-20190806004212-e31b211e4f1c github.com/docker/go-metrics v0.0.1 github.com/docker/libtrust v0.0.0-20150114040149-fa567046d9b1 diff --git a/go.sum b/go.sum index 887b0020..aef4257d 100644 --- a/go.sum +++ b/go.sum @@ -96,8 +96,6 @@ github.com/cyphar/filepath-securejoin v0.2.3/go.mod h1:aPGpWjXOXUn2NCNjFvBE6aRxG github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/denverdino/aliyungo v0.0.0-20190125010748-a747050bb1ba h1:p6poVbjHDkKa+wtC8frBMwQtT3BmqGYBjzMwJ63tuR4= -github.com/denverdino/aliyungo v0.0.0-20190125010748-a747050bb1ba/go.mod h1:dV8lFg6daOBZbT6/BDGIz6Y3WFGn8juu6G+CQ6LHtl0= github.com/dnaeon/go-vcr v1.2.0 h1:zHCHvJYTMh1N7xnV7zf1m1GPBF9Ad0Jk/whtQ1663qI= github.com/docker/go-events v0.0.0-20190806004212-e31b211e4f1c h1:+pKlWGMw7gf6bQ+oDZB4KHQFypsfjYlq/C4rfL7D3g8= github.com/docker/go-events v0.0.0-20190806004212-e31b211e4f1c/go.mod h1:Uw6UezgYA44ePAFQYUehOuCzmy5zmg/+nl2ZfMWGkpA= diff --git a/registry/storage/driver/middleware/alicdn/middleware.go b/registry/storage/driver/middleware/alicdn/middleware.go deleted file mode 100755 index 033a9daf..00000000 --- a/registry/storage/driver/middleware/alicdn/middleware.go +++ /dev/null @@ -1,115 +0,0 @@ -package alicdn - -import ( - "context" - "fmt" - "net/url" - "strings" - "time" - - dcontext "github.com/distribution/distribution/v3/context" - storagedriver "github.com/distribution/distribution/v3/registry/storage/driver" - storagemiddleware "github.com/distribution/distribution/v3/registry/storage/driver/middleware" - - "github.com/denverdino/aliyungo/cdn/auth" -) - -// aliCDNStorageMiddleware provides a simple implementation of layerHandler that -// constructs temporary signed AliCDN URLs from the storagedriver layer URL, -// then issues HTTP Temporary Redirects to this AliCDN content URL. -type aliCDNStorageMiddleware struct { - storagedriver.StorageDriver - baseURL string - urlSigner *auth.URLSigner - duration time.Duration -} - -var _ storagedriver.StorageDriver = &aliCDNStorageMiddleware{} - -// newAliCDNStorageMiddleware constructs and returns a new AliCDN -// StorageDriver implementation. -// Required options: baseurl, authtype, privatekey -// Optional options: duration -func newAliCDNStorageMiddleware(storageDriver storagedriver.StorageDriver, options map[string]interface{}) (storagedriver.StorageDriver, error) { - // parse baseurl - base, ok := options["baseurl"] - if !ok { - return nil, fmt.Errorf("no baseurl provided") - } - baseURL, ok := base.(string) - if !ok { - return nil, fmt.Errorf("baseurl must be a string") - } - if !strings.Contains(baseURL, "://") { - baseURL = "https://" + baseURL - } - if _, err := url.Parse(baseURL); err != nil { - return nil, fmt.Errorf("invalid baseurl: %v", err) - } - - // parse authtype - at, ok := options["authtype"] - if !ok { - return nil, fmt.Errorf("no authtype provided") - } - authType, ok := at.(string) - if !ok { - return nil, fmt.Errorf("authtype must be a string") - } - if authType != "a" && authType != "b" && authType != "c" { - return nil, fmt.Errorf("invalid authentication type") - } - - // parse privatekey - pk, ok := options["privatekey"] - if !ok { - return nil, fmt.Errorf("no privatekey provided") - } - privateKey, ok := pk.(string) - if !ok { - return nil, fmt.Errorf("privatekey must be a string") - } - - urlSigner := auth.NewURLSigner(authType, privateKey) - - // parse duration - duration := 20 * time.Minute - d, ok := options["duration"] - if ok { - switch d := d.(type) { - case time.Duration: - duration = d - case string: - dur, err := time.ParseDuration(d) - if err != nil { - return nil, fmt.Errorf("invalid duration: %s", err) - } - duration = dur - } - } - - return &aliCDNStorageMiddleware{ - StorageDriver: storageDriver, - baseURL: baseURL, - urlSigner: urlSigner, - duration: duration, - }, nil -} - -// URLFor attempts to find a url which may be used to retrieve the file at the given path. -func (ac *aliCDNStorageMiddleware) URLFor(ctx context.Context, path string, options map[string]interface{}) (string, error) { - if ac.StorageDriver.Name() != "oss" { - dcontext.GetLogger(ctx).Warn("the AliCDN middleware does not support this backend storage driver") - return ac.StorageDriver.URLFor(ctx, path, options) - } - acURL, err := ac.urlSigner.Sign(ac.baseURL+path, time.Now().Add(ac.duration)) - if err != nil { - return "", err - } - return acURL, nil -} - -// init registers the alicdn layerHandler backend. -func init() { - storagemiddleware.Register("alicdn", newAliCDNStorageMiddleware) -} diff --git a/registry/storage/driver/oss/doc.go b/registry/storage/driver/oss/doc.go deleted file mode 100644 index d1bc932f..00000000 --- a/registry/storage/driver/oss/doc.go +++ /dev/null @@ -1,3 +0,0 @@ -// Package oss implements the Aliyun OSS Storage driver backend. Support can be -// enabled by including the "include_oss" build tag. -package oss diff --git a/registry/storage/driver/oss/oss.go b/registry/storage/driver/oss/oss.go deleted file mode 100644 index aa3f0893..00000000 --- a/registry/storage/driver/oss/oss.go +++ /dev/null @@ -1,710 +0,0 @@ -//go:build include_oss -// +build include_oss - -// Package oss provides a storagedriver.StorageDriver implementation to -// store blobs in Aliyun OSS cloud storage. -// -// This package leverages the denverdino/aliyungo client library for interfacing with -// oss. -// -// Because OSS is a key, value store the Stat call does not support last modification -// time for directories (directories are an abstraction for key, value stores) -package oss - -import ( - "bytes" - "context" - "fmt" - "io" - "net/http" - "reflect" - "strconv" - "strings" - "time" - - "github.com/denverdino/aliyungo/oss" - storagedriver "github.com/distribution/distribution/v3/registry/storage/driver" - "github.com/distribution/distribution/v3/registry/storage/driver/base" - "github.com/distribution/distribution/v3/registry/storage/driver/factory" - "github.com/sirupsen/logrus" -) - -const driverName = "oss" - -// minChunkSize defines the minimum multipart upload chunk size -// OSS API requires multipart upload chunks to be at least 5MB -const minChunkSize = 5 << 20 - -const ( - defaultChunkSize = 2 * minChunkSize - defaultTimeout = 2 * time.Minute // 2 minute timeout per chunk -) - -// listMax is the largest amount of objects you can request from OSS in a list call -const listMax = 1000 - -// DriverParameters A struct that encapsulates all of the driver parameters after all values have been set -type DriverParameters struct { - AccessKeyID string - AccessKeySecret string - Bucket string - Region oss.Region - Internal bool - Encrypt bool - Secure bool - ChunkSize int64 - RootDirectory string - Endpoint string - EncryptionKeyID string -} - -func init() { - factory.Register(driverName, &ossDriverFactory{}) -} - -// ossDriverFactory implements the factory.StorageDriverFactory interface -type ossDriverFactory struct{} - -func (factory *ossDriverFactory) Create(parameters map[string]interface{}) (storagedriver.StorageDriver, error) { - return FromParameters(parameters) -} - -var _ storagedriver.StorageDriver = &driver{} - -type driver struct { - Client *oss.Client - Bucket *oss.Bucket - ChunkSize int64 - Encrypt bool - RootDirectory string - EncryptionKeyID string -} - -type baseEmbed struct { - base.Base -} - -// Driver is a storagedriver.StorageDriver implementation backed by Aliyun OSS -// Objects are stored at absolute keys in the provided bucket. -type Driver struct { - baseEmbed -} - -// FromParameters constructs a new Driver with a given parameters map -// Required parameters: -// - accesskey -// - secretkey -// - region -// - bucket -// - encrypt -func FromParameters(parameters map[string]interface{}) (*Driver, error) { - // Providing no values for these is valid in case the user is authenticating - - accessKey, ok := parameters["accesskeyid"] - if !ok { - return nil, fmt.Errorf("No accesskeyid parameter provided") - } - secretKey, ok := parameters["accesskeysecret"] - if !ok { - return nil, fmt.Errorf("No accesskeysecret parameter provided") - } - - regionName, ok := parameters["region"] - if !ok || fmt.Sprint(regionName) == "" { - return nil, fmt.Errorf("No region parameter provided") - } - - bucket, ok := parameters["bucket"] - if !ok || fmt.Sprint(bucket) == "" { - return nil, fmt.Errorf("No bucket parameter provided") - } - - internalBool := false - internal, ok := parameters["internal"] - if ok { - internalBool, ok = internal.(bool) - if !ok { - return nil, fmt.Errorf("The internal parameter should be a boolean") - } - } - - encryptBool := false - encrypt, ok := parameters["encrypt"] - if ok { - encryptBool, ok = encrypt.(bool) - if !ok { - return nil, fmt.Errorf("The encrypt parameter should be a boolean") - } - } - - encryptionKeyID, ok := parameters["encryptionkeyid"] - if !ok { - encryptionKeyID = "" - } - - secureBool := true - secure, ok := parameters["secure"] - if ok { - secureBool, ok = secure.(bool) - if !ok { - return nil, fmt.Errorf("The secure parameter should be a boolean") - } - } - - chunkSize := int64(defaultChunkSize) - chunkSizeParam, ok := parameters["chunksize"] - if ok { - switch v := chunkSizeParam.(type) { - case string: - vv, err := strconv.ParseInt(v, 0, 64) - if err != nil { - return nil, fmt.Errorf("chunksize parameter must be an integer, %v invalid", chunkSizeParam) - } - chunkSize = vv - case int64: - chunkSize = v - case int, uint, int32, uint32, uint64: - chunkSize = reflect.ValueOf(v).Convert(reflect.TypeOf(chunkSize)).Int() - default: - return nil, fmt.Errorf("invalid valud for chunksize: %#v", chunkSizeParam) - } - - if chunkSize < minChunkSize { - return nil, fmt.Errorf("The chunksize %#v parameter should be a number that is larger than or equal to %d", chunkSize, minChunkSize) - } - } - - rootDirectory, ok := parameters["rootdirectory"] - if !ok { - rootDirectory = "" - } - - endpoint, ok := parameters["endpoint"] - if !ok { - endpoint = "" - } - - params := DriverParameters{ - AccessKeyID: fmt.Sprint(accessKey), - AccessKeySecret: fmt.Sprint(secretKey), - Bucket: fmt.Sprint(bucket), - Region: oss.Region(fmt.Sprint(regionName)), - ChunkSize: chunkSize, - RootDirectory: fmt.Sprint(rootDirectory), - Encrypt: encryptBool, - Secure: secureBool, - Internal: internalBool, - Endpoint: fmt.Sprint(endpoint), - EncryptionKeyID: fmt.Sprint(encryptionKeyID), - } - - return New(params) -} - -// New constructs a new Driver with the given Aliyun credentials, region, encryption flag, and -// bucketName -func New(params DriverParameters) (*Driver, error) { - client := oss.NewOSSClient(params.Region, params.Internal, params.AccessKeyID, params.AccessKeySecret, params.Secure) - client.SetEndpoint(params.Endpoint) - bucket := client.Bucket(params.Bucket) - client.SetDebug(false) - - // Validate that the given credentials have at least read permissions in the - // given bucket scope. - if _, err := bucket.List(strings.TrimRight(params.RootDirectory, "/"), "", "", 1); err != nil { - return nil, err - } - - // TODO(tg123): Currently multipart uploads have no timestamps, so this would be unwise - // if you initiated a new OSS client while another one is running on the same bucket. - - d := &driver{ - Client: client, - Bucket: bucket, - ChunkSize: params.ChunkSize, - Encrypt: params.Encrypt, - RootDirectory: params.RootDirectory, - EncryptionKeyID: params.EncryptionKeyID, - } - - return &Driver{ - baseEmbed: baseEmbed{ - Base: base.Base{ - StorageDriver: d, - }, - }, - }, nil -} - -// Implement the storagedriver.StorageDriver interface - -func (d *driver) Name() string { - return driverName -} - -// GetContent retrieves the content stored at "path" as a []byte. -func (d *driver) GetContent(ctx context.Context, path string) ([]byte, error) { - content, err := d.Bucket.Get(d.ossPath(path)) - if err != nil { - return nil, parseError(path, err) - } - return content, nil -} - -// PutContent stores the []byte content at a location designated by "path". -func (d *driver) PutContent(ctx context.Context, path string, contents []byte) error { - return parseError(path, d.Bucket.Put(d.ossPath(path), contents, d.getContentType(), getPermissions(), d.getOptions())) -} - -// Reader retrieves an io.ReadCloser for the content stored at "path" with a -// given byte offset. -func (d *driver) Reader(ctx context.Context, path string, offset int64) (io.ReadCloser, error) { - headers := make(http.Header) - headers.Add("Range", "bytes="+strconv.FormatInt(offset, 10)+"-") - - resp, err := d.Bucket.GetResponseWithHeaders(d.ossPath(path), headers) - if err != nil { - return nil, parseError(path, err) - } - - // Due to Aliyun OSS API, status 200 and whole object will be return instead of an - // InvalidRange error when range is invalid. - // - // OSS sever will always return http.StatusPartialContent if range is acceptable. - if resp.StatusCode != http.StatusPartialContent { - resp.Body.Close() - return io.NopCloser(bytes.NewReader(nil)), nil - } - - return resp.Body, nil -} - -// Writer returns a FileWriter which will store the content written to it -// at the location designated by "path" after the call to Commit. -func (d *driver) Writer(ctx context.Context, path string, append bool) (storagedriver.FileWriter, error) { - key := d.ossPath(path) - if !append { - // TODO (brianbland): cancel other uploads at this path - multi, err := d.Bucket.InitMulti(key, d.getContentType(), getPermissions(), d.getOptions()) - if err != nil { - return nil, err - } - return d.newWriter(key, multi, nil), nil - } - multis, _, err := d.Bucket.ListMulti(key, "") - if err != nil { - return nil, parseError(path, err) - } - for _, multi := range multis { - if key != multi.Key { - continue - } - parts, err := multi.ListParts() - if err != nil { - return nil, parseError(path, err) - } - var multiSize int64 - for _, part := range parts { - multiSize += part.Size - } - return d.newWriter(key, multi, parts), nil - } - return nil, storagedriver.PathNotFoundError{Path: path} -} - -// Stat retrieves the FileInfo for the given path, including the current size -// in bytes and the creation time. -func (d *driver) Stat(ctx context.Context, path string) (storagedriver.FileInfo, error) { - listResponse, err := d.Bucket.List(d.ossPath(path), "", "", 1) - if err != nil { - return nil, err - } - - fi := storagedriver.FileInfoFields{ - Path: path, - } - - if len(listResponse.Contents) == 1 { - if listResponse.Contents[0].Key != d.ossPath(path) { - fi.IsDir = true - } else { - fi.IsDir = false - fi.Size = listResponse.Contents[0].Size - - timestamp, err := time.Parse(time.RFC3339Nano, listResponse.Contents[0].LastModified) - if err != nil { - return nil, err - } - fi.ModTime = timestamp - } - } else if len(listResponse.CommonPrefixes) == 1 { - fi.IsDir = true - } else { - return nil, storagedriver.PathNotFoundError{Path: path} - } - - return storagedriver.FileInfoInternal{FileInfoFields: fi}, nil -} - -// List returns a list of the objects that are direct descendants of the given path. -func (d *driver) List(ctx context.Context, opath string) ([]string, error) { - path := opath - if path != "/" && opath[len(path)-1] != '/' { - path = path + "/" - } - - // This is to cover for the cases when the rootDirectory of the driver is either "" or "/". - // In those cases, there is no root prefix to replace and we must actually add a "/" to all - // results in order to keep them as valid paths as recognized by storagedriver.PathRegexp - prefix := "" - if d.ossPath("") == "" { - prefix = "/" - } - - ossPath := d.ossPath(path) - listResponse, err := d.Bucket.List(ossPath, "/", "", listMax) - if err != nil { - return nil, parseError(opath, err) - } - - files := []string{} - directories := []string{} - - for { - for _, key := range listResponse.Contents { - files = append(files, strings.Replace(key.Key, d.ossPath(""), prefix, 1)) - } - - for _, commonPrefix := range listResponse.CommonPrefixes { - directories = append(directories, strings.Replace(commonPrefix[0:len(commonPrefix)-1], d.ossPath(""), prefix, 1)) - } - - if listResponse.IsTruncated { - listResponse, err = d.Bucket.List(ossPath, "/", listResponse.NextMarker, listMax) - if err != nil { - return nil, err - } - } else { - break - } - } - - // This is to cover for the cases when the first key equal to ossPath. - if len(files) > 0 && files[0] == strings.Replace(ossPath, d.ossPath(""), prefix, 1) { - files = files[1:] - } - - if opath != "/" { - if len(files) == 0 && len(directories) == 0 { - // Treat empty response as missing directory, since we don't actually - // have directories in s3. - return nil, storagedriver.PathNotFoundError{Path: opath} - } - } - - return append(files, directories...), nil -} - -const maxConcurrency = 10 - -// Move moves an object stored at sourcePath to destPath, removing the original -// object. -func (d *driver) Move(ctx context.Context, sourcePath string, destPath string) error { - logrus.Infof("Move from %s to %s", d.ossPath(sourcePath), d.ossPath(destPath)) - err := d.Bucket.CopyLargeFileInParallel(d.ossPath(sourcePath), d.ossPath(destPath), - d.getContentType(), - getPermissions(), - d.getOptions(), - maxConcurrency) - if err != nil { - logrus.Errorf("Failed for move from %s to %s: %v", d.ossPath(sourcePath), d.ossPath(destPath), err) - return parseError(sourcePath, err) - } - - return d.Delete(ctx, sourcePath) -} - -// Delete recursively deletes all objects stored at "path" and its subpaths. -func (d *driver) Delete(ctx context.Context, path string) error { - ossPath := d.ossPath(path) - listResponse, err := d.Bucket.List(ossPath, "", "", listMax) - if err != nil || len(listResponse.Contents) == 0 { - return storagedriver.PathNotFoundError{Path: path} - } - - ossObjects := make([]oss.Object, listMax) - - for len(listResponse.Contents) > 0 { - numOssObjects := len(listResponse.Contents) - for index, key := range listResponse.Contents { - // Stop if we encounter a key that is not a subpath (so that deleting "/a" does not delete "/ab"). - if len(key.Key) > len(ossPath) && (key.Key)[len(ossPath)] != '/' { - numOssObjects = index - break - } - ossObjects[index].Key = key.Key - } - - err := d.Bucket.DelMulti(oss.Delete{Quiet: false, Objects: ossObjects[0:numOssObjects]}) - if err != nil { - return nil - } - - if numOssObjects < len(listResponse.Contents) { - return nil - } - - listResponse, err = d.Bucket.List(d.ossPath(path), "", "", listMax) - if err != nil { - return err - } - } - - return nil -} - -// URLFor returns a URL which may be used to retrieve the content stored at the given path. -// May return an UnsupportedMethodErr in certain StorageDriver implementations. -func (d *driver) URLFor(ctx context.Context, path string, options map[string]interface{}) (string, error) { - methodString := http.MethodGet - method, ok := options["method"] - if ok { - methodString, ok = method.(string) - if !ok || (methodString != http.MethodGet) { - return "", storagedriver.ErrUnsupportedMethod{} - } - } - - expiresTime := time.Now().Add(20 * time.Minute) - - expires, ok := options["expiry"] - if ok { - et, ok := expires.(time.Time) - if ok { - expiresTime = et - } - } - logrus.Infof("methodString: %s, expiresTime: %v", methodString, expiresTime) - signedURL := d.Bucket.SignedURLWithMethod(methodString, d.ossPath(path), expiresTime, nil, nil) - logrus.Infof("signed URL: %s", signedURL) - return signedURL, nil -} - -// Walk traverses a filesystem defined within driver, starting -// from the given path, calling f on each file -func (d *driver) Walk(ctx context.Context, path string, f storagedriver.WalkFn) error { - return storagedriver.WalkFallback(ctx, d, path, f) -} - -func (d *driver) ossPath(path string) string { - return strings.TrimLeft(strings.TrimRight(d.RootDirectory, "/")+path, "/") -} - -func parseError(path string, err error) error { - if ossErr, ok := err.(*oss.Error); ok && ossErr.StatusCode == http.StatusNotFound && (ossErr.Code == "NoSuchKey" || ossErr.Code == "") { - return storagedriver.PathNotFoundError{Path: path} - } - - return err -} - -func (d *driver) getOptions() oss.Options { - return oss.Options{ - ServerSideEncryption: d.Encrypt, - ServerSideEncryptionKeyID: d.EncryptionKeyID, - } -} - -func (d *driver) getCopyOptions() oss.CopyOptions { - return oss.CopyOptions{ - ServerSideEncryption: d.Encrypt, - ServerSideEncryptionKeyID: d.EncryptionKeyID, - } -} - -func getPermissions() oss.ACL { - return oss.Private -} - -func (d *driver) getContentType() string { - return "application/octet-stream" -} - -// writer attempts to upload parts to S3 in a buffered fashion where the last -// part is at least as large as the chunksize, so the multipart upload could be -// cleanly resumed in the future. This is violated if Close is called after less -// than a full chunk is written. -type writer struct { - driver *driver - key string - multi *oss.Multi - parts []oss.Part - size int64 - readyPart []byte - pendingPart []byte - closed bool - committed bool - cancelled bool -} - -func (d *driver) newWriter(key string, multi *oss.Multi, parts []oss.Part) storagedriver.FileWriter { - var size int64 - for _, part := range parts { - size += part.Size - } - return &writer{ - driver: d, - key: key, - multi: multi, - parts: parts, - size: size, - } -} - -func (w *writer) Write(p []byte) (int, error) { - if w.closed { - return 0, fmt.Errorf("already closed") - } else if w.committed { - return 0, fmt.Errorf("already committed") - } else if w.cancelled { - return 0, fmt.Errorf("already cancelled") - } - - // If the last written part is smaller than minChunkSize, we need to make a - // new multipart upload :sadface: - if len(w.parts) > 0 && int(w.parts[len(w.parts)-1].Size) < minChunkSize { - err := w.multi.Complete(w.parts) - if err != nil { - w.multi.Abort() - return 0, err - } - - multi, err := w.driver.Bucket.InitMulti(w.key, w.driver.getContentType(), getPermissions(), w.driver.getOptions()) - if err != nil { - return 0, err - } - w.multi = multi - - // If the entire written file is smaller than minChunkSize, we need to make - // a new part from scratch :double sad face: - if w.size < minChunkSize { - contents, err := w.driver.Bucket.Get(w.key) - if err != nil { - return 0, err - } - w.parts = nil - w.readyPart = contents - } else { - // Otherwise we can use the old file as the new first part - _, part, err := multi.PutPartCopy(1, w.driver.getCopyOptions(), w.driver.Bucket.Name+"/"+w.key) - if err != nil { - return 0, err - } - w.parts = []oss.Part{part} - } - } - - var n int - - for len(p) > 0 { - // If no parts are ready to write, fill up the first part - if neededBytes := int(w.driver.ChunkSize) - len(w.readyPart); neededBytes > 0 { - if len(p) >= neededBytes { - w.readyPart = append(w.readyPart, p[:neededBytes]...) - n += neededBytes - p = p[neededBytes:] - } else { - w.readyPart = append(w.readyPart, p...) - n += len(p) - p = nil - } - } - - if neededBytes := int(w.driver.ChunkSize) - len(w.pendingPart); neededBytes > 0 { - if len(p) >= neededBytes { - w.pendingPart = append(w.pendingPart, p[:neededBytes]...) - n += neededBytes - p = p[neededBytes:] - err := w.flushPart() - if err != nil { - w.size += int64(n) - return n, err - } - } else { - w.pendingPart = append(w.pendingPart, p...) - n += len(p) - p = nil - } - } - } - w.size += int64(n) - return n, nil -} - -func (w *writer) Size() int64 { - return w.size -} - -func (w *writer) Close() error { - if w.closed { - return fmt.Errorf("already closed") - } - w.closed = true - return w.flushPart() -} - -func (w *writer) Cancel(ctx context.Context) error { - if w.closed { - return fmt.Errorf("already closed") - } else if w.committed { - return fmt.Errorf("already committed") - } - w.cancelled = true - err := w.multi.Abort() - return err -} - -func (w *writer) Commit() error { - if w.closed { - return fmt.Errorf("already closed") - } else if w.committed { - return fmt.Errorf("already committed") - } else if w.cancelled { - return fmt.Errorf("already cancelled") - } - err := w.flushPart() - if err != nil { - return err - } - w.committed = true - err = w.multi.Complete(w.parts) - if err != nil { - w.multi.Abort() - return err - } - return nil -} - -// flushPart flushes buffers to write a part to S3. -// Only called by Write (with both buffers full) and Close/Commit (always) -func (w *writer) flushPart() error { - if len(w.readyPart) == 0 && len(w.pendingPart) == 0 { - // nothing to write - return nil - } - if len(w.pendingPart) < int(w.driver.ChunkSize) { - // closing with a small pending part - // combine ready and pending to avoid writing a small part - w.readyPart = append(w.readyPart, w.pendingPart...) - w.pendingPart = nil - } - - part, err := w.multi.PutPart(len(w.parts)+1, bytes.NewReader(w.readyPart)) - if err != nil { - return err - } - w.parts = append(w.parts, part) - w.readyPart = w.pendingPart - w.pendingPart = nil - return nil -} diff --git a/registry/storage/driver/oss/oss_test.go b/registry/storage/driver/oss/oss_test.go deleted file mode 100644 index f1518424..00000000 --- a/registry/storage/driver/oss/oss_test.go +++ /dev/null @@ -1,149 +0,0 @@ -//go:build include_oss -// +build include_oss - -package oss - -import ( - "os" - "strconv" - "testing" - - alioss "github.com/denverdino/aliyungo/oss" - "github.com/distribution/distribution/v3/context" - storagedriver "github.com/distribution/distribution/v3/registry/storage/driver" - "github.com/distribution/distribution/v3/registry/storage/driver/testsuites" - "gopkg.in/check.v1" -) - -// Hook up gocheck into the "go test" runner. -func Test(t *testing.T) { check.TestingT(t) } - -var ossDriverConstructor func(rootDirectory string) (*Driver, error) - -var skipCheck func() string - -func init() { - var ( - accessKey = os.Getenv("ALIYUN_ACCESS_KEY_ID") - secretKey = os.Getenv("ALIYUN_ACCESS_KEY_SECRET") - bucket = os.Getenv("OSS_BUCKET") - region = os.Getenv("OSS_REGION") - internal = os.Getenv("OSS_INTERNAL") - encrypt = os.Getenv("OSS_ENCRYPT") - secure = os.Getenv("OSS_SECURE") - endpoint = os.Getenv("OSS_ENDPOINT") - encryptionKeyID = os.Getenv("OSS_ENCRYPTIONKEYID") - ) - - root, err := os.MkdirTemp("", "driver-") - if err != nil { - panic(err) - } - defer os.Remove(root) - - ossDriverConstructor = func(rootDirectory string) (*Driver, error) { - encryptBool := false - if encrypt != "" { - encryptBool, err = strconv.ParseBool(encrypt) - if err != nil { - return nil, err - } - } - - secureBool := false - if secure != "" { - secureBool, err = strconv.ParseBool(secure) - if err != nil { - return nil, err - } - } - - internalBool := false - if internal != "" { - internalBool, err = strconv.ParseBool(internal) - if err != nil { - return nil, err - } - } - - parameters := DriverParameters{ - AccessKeyID: accessKey, - AccessKeySecret: secretKey, - Bucket: bucket, - Region: alioss.Region(region), - Internal: internalBool, - ChunkSize: minChunkSize, - RootDirectory: rootDirectory, - Encrypt: encryptBool, - Secure: secureBool, - Endpoint: endpoint, - EncryptionKeyID: encryptionKeyID, - } - - return New(parameters) - } - - // Skip OSS storage driver tests if environment variable parameters are not provided - skipCheck = func() string { - if accessKey == "" || secretKey == "" || region == "" || bucket == "" || encrypt == "" { - return "Must set ALIYUN_ACCESS_KEY_ID, ALIYUN_ACCESS_KEY_SECRET, OSS_REGION, OSS_BUCKET, and OSS_ENCRYPT to run OSS tests" - } - return "" - } - - testsuites.RegisterSuite(func() (storagedriver.StorageDriver, error) { - return ossDriverConstructor(root) - }, skipCheck) -} - -func TestEmptyRootList(t *testing.T) { - if skipCheck() != "" { - t.Skip(skipCheck()) - } - - validRoot := t.TempDir() - - rootedDriver, err := ossDriverConstructor(validRoot) - if err != nil { - t.Fatalf("unexpected error creating rooted driver: %v", err) - } - - emptyRootDriver, err := ossDriverConstructor("") - if err != nil { - t.Fatalf("unexpected error creating empty root driver: %v", err) - } - - slashRootDriver, err := ossDriverConstructor("/") - if err != nil { - t.Fatalf("unexpected error creating slash root driver: %v", err) - } - - filename := "/test" - contents := []byte("contents") - ctx := context.Background() - err = rootedDriver.PutContent(ctx, filename, contents) - if err != nil { - t.Fatalf("unexpected error creating content: %v", err) - } - defer rootedDriver.Delete(ctx, filename) - - keys, err := emptyRootDriver.List(ctx, "/") - if err != nil { - t.Fatalf("unexpected error listing empty root content: %v", err) - } - for _, path := range keys { - if !storagedriver.PathRegexp.MatchString(path) { - t.Fatalf("unexpected string in path: %q != %q", path, storagedriver.PathRegexp) - } - } - - keys, err = slashRootDriver.List(ctx, "/") - if err != nil { - t.Fatalf("unexpected error listing slash root content: %v", err) - } - for _, path := range keys { - if !storagedriver.PathRegexp.MatchString(path) { - t.Fatalf("unexpected string in path: %q != %q", path, storagedriver.PathRegexp) - } - } -} diff --git a/vendor/github.com/denverdino/aliyungo/LICENSE.txt b/vendor/github.com/denverdino/aliyungo/LICENSE.txt deleted file mode 100644 index 91829713..00000000 --- a/vendor/github.com/denverdino/aliyungo/LICENSE.txt +++ /dev/null @@ -1,191 +0,0 @@ - - Apache License - Version 2.0, January 2004 - https://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - Copyright 2015-2015 Li Yi (denverdino@gmail.com). - - 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 - - https://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. diff --git a/vendor/github.com/denverdino/aliyungo/cdn/auth/random_uuid.go b/vendor/github.com/denverdino/aliyungo/cdn/auth/random_uuid.go deleted file mode 100644 index 169a2b6c..00000000 --- a/vendor/github.com/denverdino/aliyungo/cdn/auth/random_uuid.go +++ /dev/null @@ -1,97 +0,0 @@ -package auth - -import ( - "crypto/rand" - "fmt" - "io" - "os" - "syscall" - "time" -) - -const ( - // Bits is the number of bits in a UUID - Bits = 128 - - // Size is the number of bytes in a UUID - Size = Bits / 8 - - format = "%08x%04x%04x%04x%012x" -) - -var ( - // Loggerf can be used to override the default logging destination. Such - // log messages in this library should be logged at warning or higher. - Loggerf = func(format string, args ...interface{}) {} -) - -// UUID represents a UUID value. UUIDs can be compared and set to other values -// and accessed by byte. -type UUID [Size]byte - -// GenerateUUID creates a new, version 4 uuid. -func GenerateUUID() (u UUID) { - const ( - // ensures we backoff for less than 450ms total. Use the following to - // select new value, in units of 10ms: - // n*(n+1)/2 = d -> n^2 + n - 2d -> n = (sqrt(8d + 1) - 1)/2 - maxretries = 9 - backoff = time.Millisecond * 10 - ) - - var ( - totalBackoff time.Duration - count int - retries int - ) - - for { - // This should never block but the read may fail. Because of this, - // we just try to read the random number generator until we get - // something. This is a very rare condition but may happen. - b := time.Duration(retries) * backoff - time.Sleep(b) - totalBackoff += b - - n, err := io.ReadFull(rand.Reader, u[count:]) - if err != nil { - if retryOnError(err) && retries < maxretries { - count += n - retries++ - Loggerf("error generating version 4 uuid, retrying: %v", err) - continue - } - - // Any other errors represent a system problem. What did someone - // do to /dev/urandom? - panic(fmt.Errorf("error reading random number generator, retried for %v: %v", totalBackoff.String(), err)) - } - - break - } - - u[6] = (u[6] & 0x0f) | 0x40 // set version byte - u[8] = (u[8] & 0x3f) | 0x80 // set high order byte 0b10{8,9,a,b} - - return u -} - -func (u UUID) String() string { - return fmt.Sprintf(format, u[:4], u[4:6], u[6:8], u[8:10], u[10:]) -} - -// retryOnError tries to detect whether or not retrying would be fruitful. -func retryOnError(err error) bool { - switch err := err.(type) { - case *os.PathError: - return retryOnError(err.Err) // unpack the target error - case syscall.Errno: - if err == syscall.EPERM { - // EPERM represents an entropy pool exhaustion, a condition under - // which we backoff and retry. - return true - } - } - - return false -} diff --git a/vendor/github.com/denverdino/aliyungo/cdn/auth/sign_url.go b/vendor/github.com/denverdino/aliyungo/cdn/auth/sign_url.go deleted file mode 100644 index 211bd04f..00000000 --- a/vendor/github.com/denverdino/aliyungo/cdn/auth/sign_url.go +++ /dev/null @@ -1,80 +0,0 @@ -package auth - -import ( - "crypto/md5" - "fmt" - "net/url" - "time" -) - -// An URLSigner provides URL signing utilities to sign URLs for Aliyun CDN -// resources. -// authentication document: https://help.aliyun.com/document_detail/85117.html -type URLSigner struct { - authType string - privKey string -} - -// NewURLSigner returns a new signer object. -func NewURLSigner(authType string, privKey string) *URLSigner { - return &URLSigner{ - authType: authType, - privKey: privKey, - } -} - -// Sign returns a signed aliyuncdn url based on authentication type -func (s URLSigner) Sign(uri string, expires time.Time) (string, error) { - r, err := url.Parse(uri) - if err != nil { - return "", fmt.Errorf("unable to parse url: %s", uri) - } - - switch s.authType { - case "a": - return aTypeSign(r, s.privKey, expires), nil - case "b": - return bTypeSign(r, s.privKey, expires), nil - case "c": - return cTypeSign(r, s.privKey, expires), nil - default: - return "", fmt.Errorf("invalid authentication type") - } -} - -// sign by A type authentication method. -// authentication document: https://help.aliyun.com/document_detail/85113.html -func aTypeSign(r *url.URL, privateKey string, expires time.Time) string { - //rand is a random uuid without "-" - rand := GenerateUUID().String() - // not use, "0" by default - uid := "0" - secret := fmt.Sprintf("%s-%d-%s-%s-%s", r.Path, expires.Unix(), rand, uid, privateKey) - hashValue := md5.Sum([]byte(secret)) - authKey := fmt.Sprintf("%d-%s-%s-%x", expires.Unix(), rand, uid, hashValue) - if r.RawQuery == "" { - return fmt.Sprintf("%s?auth_key=%s", r.String(), authKey) - } - return fmt.Sprintf("%s&auth_key=%s", r.String(), authKey) - -} - -// sign by B type authentication method. -// authentication document: https://help.aliyun.com/document_detail/85114.html -func bTypeSign(r *url.URL, privateKey string, expires time.Time) string { - formatExp := expires.Format("200601021504") - secret := privateKey + formatExp + r.Path - hashValue := md5.Sum([]byte(secret)) - signURL := fmt.Sprintf("%s://%s/%s/%x%s?%s", r.Scheme, r.Host, formatExp, hashValue, r.Path, r.RawQuery) - return signURL -} - -// sign by C type authentication method. -// authentication document: https://help.aliyun.com/document_detail/85115.html -func cTypeSign(r *url.URL, privateKey string, expires time.Time) string { - hexExp := fmt.Sprintf("%x", expires.Unix()) - secret := privateKey + r.Path + hexExp - hashValue := md5.Sum([]byte(secret)) - signURL := fmt.Sprintf("%s://%s/%x/%s%s?%s", r.Scheme, r.Host, hashValue, hexExp, r.Path, r.RawQuery) - return signURL -} diff --git a/vendor/github.com/denverdino/aliyungo/common/client.go b/vendor/github.com/denverdino/aliyungo/common/client.go deleted file mode 100644 index 6c00d1c1..00000000 --- a/vendor/github.com/denverdino/aliyungo/common/client.go +++ /dev/null @@ -1,550 +0,0 @@ -package common - -import ( - "bytes" - "encoding/json" - "errors" - "fmt" - "io/ioutil" - "log" - "net/http" - "net/url" - "os" - "strconv" - "strings" - "time" - - "github.com/denverdino/aliyungo/util" -) - -// RemovalPolicy.N add index to array item -// RemovalPolicy=["a", "b"] => RemovalPolicy.1="a" RemovalPolicy.2="b" -type FlattenArray []string - -// string contains underline which will be replaced with dot -// SystemDisk_Category => SystemDisk.Category -type UnderlineString string - -// A Client represents a client of ECS services -type Client struct { - AccessKeyId string //Access Key Id - AccessKeySecret string //Access Key Secret - securityToken string - debug bool - httpClient *http.Client - endpoint string - version string - serviceCode string - regionID Region - businessInfo string - userAgent string -} - -// Initialize properties of a client instance -func (client *Client) Init(endpoint, version, accessKeyId, accessKeySecret string) { - client.AccessKeyId = accessKeyId - ak := accessKeySecret - if !strings.HasSuffix(ak, "&") { - ak += "&" - } - client.AccessKeySecret = ak - client.debug = false - handshakeTimeout, err := strconv.Atoi(os.Getenv("TLSHandshakeTimeout")) - if err != nil { - handshakeTimeout = 0 - } - if handshakeTimeout == 0 { - client.httpClient = &http.Client{} - } else { - t := &http.Transport{ - TLSHandshakeTimeout: time.Duration(handshakeTimeout) * time.Second} - client.httpClient = &http.Client{Transport: t} - } - client.endpoint = endpoint - client.version = version -} - -// Initialize properties of a client instance including regionID -func (client *Client) NewInit(endpoint, version, accessKeyId, accessKeySecret, serviceCode string, regionID Region) { - client.Init(endpoint, version, accessKeyId, accessKeySecret) - client.serviceCode = serviceCode - client.regionID = regionID -} - -// Intialize client object when all properties are ready -func (client *Client) InitClient() *Client { - client.debug = false - handshakeTimeout, err := strconv.Atoi(os.Getenv("TLSHandshakeTimeout")) - if err != nil { - handshakeTimeout = 0 - } - if handshakeTimeout == 0 { - client.httpClient = &http.Client{} - } else { - t := &http.Transport{ - TLSHandshakeTimeout: time.Duration(handshakeTimeout) * time.Second} - client.httpClient = &http.Client{Transport: t} - } - return client -} - -func (client *Client) NewInitForAssumeRole(endpoint, version, accessKeyId, accessKeySecret, serviceCode string, regionID Region, securityToken string) { - client.NewInit(endpoint, version, accessKeyId, accessKeySecret, serviceCode, regionID) - client.securityToken = securityToken -} - -//getLocationEndpoint -func (client *Client) getEndpointByLocation() string { - locationClient := NewLocationClient(client.AccessKeyId, client.AccessKeySecret, client.securityToken) - locationClient.SetDebug(true) - return locationClient.DescribeOpenAPIEndpoint(client.regionID, client.serviceCode) -} - -//NewClient using location service -func (client *Client) setEndpointByLocation(region Region, serviceCode, accessKeyId, accessKeySecret, securityToken string) { - locationClient := NewLocationClient(accessKeyId, accessKeySecret, securityToken) - locationClient.SetDebug(true) - ep := locationClient.DescribeOpenAPIEndpoint(region, serviceCode) - if ep == "" { - ep = loadEndpointFromFile(region, serviceCode) - } - - if ep != "" { - client.endpoint = ep - } -} - -// Ensure all necessary properties are valid -func (client *Client) ensureProperties() error { - var msg string - - if client.endpoint == "" { - msg = fmt.Sprintf("endpoint cannot be empty!") - } else if client.version == "" { - msg = fmt.Sprintf("version cannot be empty!") - } else if client.AccessKeyId == "" { - msg = fmt.Sprintf("AccessKeyId cannot be empty!") - } else if client.AccessKeySecret == "" { - msg = fmt.Sprintf("AccessKeySecret cannot be empty!") - } - - if msg != "" { - return errors.New(msg) - } - - return nil -} - -// ---------------------------------------------------- -// WithXXX methods -// ---------------------------------------------------- - -// WithEndpoint sets custom endpoint -func (client *Client) WithEndpoint(endpoint string) *Client { - client.SetEndpoint(endpoint) - return client -} - -// WithVersion sets custom version -func (client *Client) WithVersion(version string) *Client { - client.SetVersion(version) - return client -} - -// WithRegionID sets Region ID -func (client *Client) WithRegionID(regionID Region) *Client { - client.SetRegionID(regionID) - return client -} - -//WithServiceCode sets serviceCode -func (client *Client) WithServiceCode(serviceCode string) *Client { - client.SetServiceCode(serviceCode) - return client -} - -// WithAccessKeyId sets new AccessKeyId -func (client *Client) WithAccessKeyId(id string) *Client { - client.SetAccessKeyId(id) - return client -} - -// WithAccessKeySecret sets new AccessKeySecret -func (client *Client) WithAccessKeySecret(secret string) *Client { - client.SetAccessKeySecret(secret) - return client -} - -// WithSecurityToken sets securityToken -func (client *Client) WithSecurityToken(securityToken string) *Client { - client.SetSecurityToken(securityToken) - return client -} - -// WithDebug sets debug mode to log the request/response message -func (client *Client) WithDebug(debug bool) *Client { - client.SetDebug(debug) - return client -} - -// WithBusinessInfo sets business info to log the request/response message -func (client *Client) WithBusinessInfo(businessInfo string) *Client { - client.SetBusinessInfo(businessInfo) - return client -} - -// WithUserAgent sets user agent to the request/response message -func (client *Client) WithUserAgent(userAgent string) *Client { - client.SetUserAgent(userAgent) - return client -} - -// ---------------------------------------------------- -// SetXXX methods -// ---------------------------------------------------- - -// SetEndpoint sets custom endpoint -func (client *Client) SetEndpoint(endpoint string) { - client.endpoint = endpoint -} - -// SetEndpoint sets custom version -func (client *Client) SetVersion(version string) { - client.version = version -} - -// SetEndpoint sets Region ID -func (client *Client) SetRegionID(regionID Region) { - client.regionID = regionID -} - -//SetServiceCode sets serviceCode -func (client *Client) SetServiceCode(serviceCode string) { - client.serviceCode = serviceCode -} - -// SetAccessKeyId sets new AccessKeyId -func (client *Client) SetAccessKeyId(id string) { - client.AccessKeyId = id -} - -// SetAccessKeySecret sets new AccessKeySecret -func (client *Client) SetAccessKeySecret(secret string) { - client.AccessKeySecret = secret + "&" -} - -// SetDebug sets debug mode to log the request/response message -func (client *Client) SetDebug(debug bool) { - client.debug = debug -} - -// SetBusinessInfo sets business info to log the request/response message -func (client *Client) SetBusinessInfo(businessInfo string) { - if strings.HasPrefix(businessInfo, "/") { - client.businessInfo = businessInfo - } else if businessInfo != "" { - client.businessInfo = "/" + businessInfo - } -} - -// SetUserAgent sets user agent to the request/response message -func (client *Client) SetUserAgent(userAgent string) { - client.userAgent = userAgent -} - -//set SecurityToken -func (client *Client) SetSecurityToken(securityToken string) { - client.securityToken = securityToken -} - -func (client *Client) initEndpoint() error { - // if set any value to "CUSTOMIZED_ENDPOINT" could skip location service. - // example: export CUSTOMIZED_ENDPOINT=true - if os.Getenv("CUSTOMIZED_ENDPOINT") != "" { - return nil - } - - if client.serviceCode != "" && client.regionID != "" { - endpoint := client.getEndpointByLocation() - if endpoint == "" { - return GetCustomError("InvalidEndpoint", "endpoint is empty,pls check") - } - client.endpoint = endpoint - } - return nil -} - -// Invoke sends the raw HTTP request for ECS services -func (client *Client) Invoke(action string, args interface{}, response interface{}) error { - if err := client.ensureProperties(); err != nil { - return err - } - - //init endpoint - if err := client.initEndpoint(); err != nil { - return err - } - - request := Request{} - request.init(client.version, action, client.AccessKeyId, client.securityToken, client.regionID) - - query := util.ConvertToQueryValues(request) - util.SetQueryValues(args, &query) - - // Sign request - signature := util.CreateSignatureForRequest(ECSRequestMethod, &query, client.AccessKeySecret) - - // Generate the request URL - requestURL := client.endpoint + "?" + query.Encode() + "&Signature=" + url.QueryEscape(signature) - - httpReq, err := http.NewRequest(ECSRequestMethod, requestURL, nil) - - if err != nil { - return GetClientError(err) - } - - // TODO move to util and add build val flag - httpReq.Header.Set("X-SDK-Client", `AliyunGO/`+Version+client.businessInfo) - - httpReq.Header.Set("User-Agent", httpReq.UserAgent()+" "+client.userAgent) - - t0 := time.Now() - httpResp, err := client.httpClient.Do(httpReq) - t1 := time.Now() - if err != nil { - return GetClientError(err) - } - statusCode := httpResp.StatusCode - - if client.debug { - log.Printf("Invoke %s %s %d (%v)", ECSRequestMethod, requestURL, statusCode, t1.Sub(t0)) - } - - defer httpResp.Body.Close() - body, err := ioutil.ReadAll(httpResp.Body) - - if err != nil { - return GetClientError(err) - } - - if client.debug { - var prettyJSON bytes.Buffer - err = json.Indent(&prettyJSON, body, "", " ") - log.Println(string(prettyJSON.Bytes())) - } - - if statusCode >= 400 && statusCode <= 599 { - errorResponse := ErrorResponse{} - err = json.Unmarshal(body, &errorResponse) - ecsError := &Error{ - ErrorResponse: errorResponse, - StatusCode: statusCode, - } - return ecsError - } - - err = json.Unmarshal(body, response) - //log.Printf("%++v", response) - if err != nil { - return GetClientError(err) - } - - return nil -} - -// Invoke sends the raw HTTP request for ECS services -func (client *Client) InvokeByFlattenMethod(action string, args interface{}, response interface{}) error { - if err := client.ensureProperties(); err != nil { - return err - } - - //init endpoint - if err := client.initEndpoint(); err != nil { - return err - } - - request := Request{} - request.init(client.version, action, client.AccessKeyId, client.securityToken, client.regionID) - - query := util.ConvertToQueryValues(request) - - util.SetQueryValueByFlattenMethod(args, &query) - - // Sign request - signature := util.CreateSignatureForRequest(ECSRequestMethod, &query, client.AccessKeySecret) - - // Generate the request URL - requestURL := client.endpoint + "?" + query.Encode() + "&Signature=" + url.QueryEscape(signature) - - httpReq, err := http.NewRequest(ECSRequestMethod, requestURL, nil) - - if err != nil { - return GetClientError(err) - } - - // TODO move to util and add build val flag - httpReq.Header.Set("X-SDK-Client", `AliyunGO/`+Version+client.businessInfo) - - httpReq.Header.Set("User-Agent", httpReq.UserAgent()+" "+client.userAgent) - - t0 := time.Now() - httpResp, err := client.httpClient.Do(httpReq) - t1 := time.Now() - if err != nil { - return GetClientError(err) - } - statusCode := httpResp.StatusCode - - if client.debug { - log.Printf("Invoke %s %s %d (%v)", ECSRequestMethod, requestURL, statusCode, t1.Sub(t0)) - } - - defer httpResp.Body.Close() - body, err := ioutil.ReadAll(httpResp.Body) - - if err != nil { - return GetClientError(err) - } - - if client.debug { - var prettyJSON bytes.Buffer - err = json.Indent(&prettyJSON, body, "", " ") - log.Println(string(prettyJSON.Bytes())) - } - - if statusCode >= 400 && statusCode <= 599 { - errorResponse := ErrorResponse{} - err = json.Unmarshal(body, &errorResponse) - ecsError := &Error{ - ErrorResponse: errorResponse, - StatusCode: statusCode, - } - return ecsError - } - - err = json.Unmarshal(body, response) - //log.Printf("%++v", response) - if err != nil { - return GetClientError(err) - } - - return nil -} - -// Invoke sends the raw HTTP request for ECS services -//改进了一下上面那个方法,可以使用各种Http方法 -//2017.1.30 增加了一个path参数,用来拓展访问的地址 -func (client *Client) InvokeByAnyMethod(method, action, path string, args interface{}, response interface{}) error { - if err := client.ensureProperties(); err != nil { - return err - } - - //init endpoint - if err := client.initEndpoint(); err != nil { - return err - } - - request := Request{} - request.init(client.version, action, client.AccessKeyId, client.securityToken, client.regionID) - data := util.ConvertToQueryValues(request) - util.SetQueryValues(args, &data) - - // Sign request - signature := util.CreateSignatureForRequest(method, &data, client.AccessKeySecret) - - data.Add("Signature", signature) - // Generate the request URL - var ( - httpReq *http.Request - err error - ) - if method == http.MethodGet { - requestURL := client.endpoint + path + "?" + data.Encode() - //fmt.Println(requestURL) - httpReq, err = http.NewRequest(method, requestURL, nil) - } else { - //fmt.Println(client.endpoint + path) - httpReq, err = http.NewRequest(method, client.endpoint+path, strings.NewReader(data.Encode())) - httpReq.Header.Set("Content-Type", "application/x-www-form-urlencoded") - } - - if err != nil { - return GetClientError(err) - } - - // TODO move to util and add build val flag - httpReq.Header.Set("X-SDK-Client", `AliyunGO/`+Version+client.businessInfo) - httpReq.Header.Set("User-Agent", httpReq.Header.Get("User-Agent")+" "+client.userAgent) - - t0 := time.Now() - httpResp, err := client.httpClient.Do(httpReq) - t1 := time.Now() - if err != nil { - return GetClientError(err) - } - statusCode := httpResp.StatusCode - - if client.debug { - log.Printf("Invoke %s %s %d (%v) %v", ECSRequestMethod, client.endpoint, statusCode, t1.Sub(t0), data.Encode()) - } - - defer httpResp.Body.Close() - body, err := ioutil.ReadAll(httpResp.Body) - - if err != nil { - return GetClientError(err) - } - - if client.debug { - var prettyJSON bytes.Buffer - err = json.Indent(&prettyJSON, body, "", " ") - log.Println(string(prettyJSON.Bytes())) - } - - if statusCode >= 400 && statusCode <= 599 { - errorResponse := ErrorResponse{} - err = json.Unmarshal(body, &errorResponse) - ecsError := &Error{ - ErrorResponse: errorResponse, - StatusCode: statusCode, - } - return ecsError - } - - err = json.Unmarshal(body, response) - //log.Printf("%++v", response) - if err != nil { - return GetClientError(err) - } - - return nil -} - -// GenerateClientToken generates the Client Token with random string -func (client *Client) GenerateClientToken() string { - return util.CreateRandomString() -} - -func GetClientErrorFromString(str string) error { - return &Error{ - ErrorResponse: ErrorResponse{ - Code: "AliyunGoClientFailure", - Message: str, - }, - StatusCode: -1, - } -} - -func GetClientError(err error) error { - return GetClientErrorFromString(err.Error()) -} - -func GetCustomError(code, message string) error { - return &Error{ - ErrorResponse: ErrorResponse{ - Code: code, - Message: message, - }, - StatusCode: 400, - } -} diff --git a/vendor/github.com/denverdino/aliyungo/common/endpoint.go b/vendor/github.com/denverdino/aliyungo/common/endpoint.go deleted file mode 100644 index 757f7a78..00000000 --- a/vendor/github.com/denverdino/aliyungo/common/endpoint.go +++ /dev/null @@ -1,208 +0,0 @@ -package common - -import ( - "encoding/xml" - "fmt" - "io/ioutil" - "log" - "os" - "strings" - "time" -) - -const ( - // LocationDefaultEndpoint is the default API endpoint of Location services - locationDefaultEndpoint = "https://location.aliyuncs.com" - locationAPIVersion = "2015-06-12" - HTTP_PROTOCOL = "http" - HTTPS_PROTOCOL = "https" -) - -var ( - endpoints = make(map[Region]map[string]string) - - SpecailEnpoints = map[Region]map[string]string{ - APNorthEast1: { - "ecs": "https://ecs.ap-northeast-1.aliyuncs.com", - "slb": "https://slb.ap-northeast-1.aliyuncs.com", - "rds": "https://rds.ap-northeast-1.aliyuncs.com", - "vpc": "https://vpc.ap-northeast-1.aliyuncs.com", - }, - APSouthEast2: { - "ecs": "https://ecs.ap-southeast-2.aliyuncs.com", - "slb": "https://slb.ap-southeast-2.aliyuncs.com", - "rds": "https://rds.ap-southeast-2.aliyuncs.com", - "vpc": "https://vpc.ap-southeast-2.aliyuncs.com", - }, - APSouthEast3: { - "ecs": "https://ecs.ap-southeast-3.aliyuncs.com", - "slb": "https://slb.ap-southeast-3.aliyuncs.com", - "rds": "https://rds.ap-southeast-3.aliyuncs.com", - "vpc": "https://vpc.ap-southeast-3.aliyuncs.com", - }, - MEEast1: { - "ecs": "https://ecs.me-east-1.aliyuncs.com", - "slb": "https://slb.me-east-1.aliyuncs.com", - "rds": "https://rds.me-east-1.aliyuncs.com", - "vpc": "https://vpc.me-east-1.aliyuncs.com", - }, - EUCentral1: { - "ecs": "https://ecs.eu-central-1.aliyuncs.com", - "slb": "https://slb.eu-central-1.aliyuncs.com", - "rds": "https://rds.eu-central-1.aliyuncs.com", - "vpc": "https://vpc.eu-central-1.aliyuncs.com", - }, - EUWest1: { - "ecs": "https://ecs.eu-west-1.aliyuncs.com", - "slb": "https://slb.eu-west-1.aliyuncs.com", - "rds": "https://rds.eu-west-1.aliyuncs.com", - "vpc": "https://vpc.eu-west-1.aliyuncs.com", - }, - Zhangjiakou: { - "ecs": "https://ecs.cn-zhangjiakou.aliyuncs.com", - "slb": "https://slb.cn-zhangjiakou.aliyuncs.com", - "rds": "https://rds.cn-zhangjiakou.aliyuncs.com", - "vpc": "https://vpc.cn-zhangjiakou.aliyuncs.com", - }, - Huhehaote: { - "ecs": "https://ecs.cn-huhehaote.aliyuncs.com", - "slb": "https://slb.cn-huhehaote.aliyuncs.com", - "rds": "https://rds.cn-huhehaote.aliyuncs.com", - "vpc": "https://vpc.cn-huhehaote.aliyuncs.com", - }, - } -) - -//init endpoints from file -func init() { - -} - -type LocationClient struct { - Client -} - -func NewLocationClient(accessKeyId, accessKeySecret, securityToken string) *LocationClient { - endpoint := os.Getenv("LOCATION_ENDPOINT") - if endpoint == "" { - endpoint = locationDefaultEndpoint - } - - client := &LocationClient{} - client.Init(endpoint, locationAPIVersion, accessKeyId, accessKeySecret) - client.securityToken = securityToken - return client -} - -func NewLocationClientWithSecurityToken(accessKeyId, accessKeySecret, securityToken string) *LocationClient { - endpoint := os.Getenv("LOCATION_ENDPOINT") - if endpoint == "" { - endpoint = locationDefaultEndpoint - } - - client := &LocationClient{} - client.WithEndpoint(endpoint). - WithVersion(locationAPIVersion). - WithAccessKeyId(accessKeyId). - WithAccessKeySecret(accessKeySecret). - WithSecurityToken(securityToken). - InitClient() - return client -} - -func (client *LocationClient) DescribeEndpoint(args *DescribeEndpointArgs) (*DescribeEndpointResponse, error) { - response := &DescribeEndpointResponse{} - err := client.Invoke("DescribeEndpoint", args, response) - if err != nil { - return nil, err - } - return response, err -} - -func (client *LocationClient) DescribeEndpoints(args *DescribeEndpointsArgs) (*DescribeEndpointsResponse, error) { - response := &DescribeEndpointsResponse{} - err := client.Invoke("DescribeEndpoints", args, response) - if err != nil { - return nil, err - } - return response, err -} - -func getProductRegionEndpoint(region Region, serviceCode string) string { - if sp, ok := endpoints[region]; ok { - if endpoint, ok := sp[serviceCode]; ok { - return endpoint - } - } - - return "" -} - -func setProductRegionEndpoint(region Region, serviceCode string, endpoint string) { - endpoints[region] = map[string]string{ - serviceCode: endpoint, - } -} - -func (client *LocationClient) DescribeOpenAPIEndpoint(region Region, serviceCode string) string { - if endpoint := getProductRegionEndpoint(region, serviceCode); endpoint != "" { - return endpoint - } - defaultProtocols := HTTP_PROTOCOL - - args := &DescribeEndpointsArgs{ - Id: region, - ServiceCode: serviceCode, - Type: "openAPI", - } - - var endpoint *DescribeEndpointsResponse - var err error - for index := 0; index < 5; index++ { - endpoint, err = client.DescribeEndpoints(args) - if err == nil && endpoint != nil && len(endpoint.Endpoints.Endpoint) > 0 { - break - } - time.Sleep(500 * time.Millisecond) - } - - if err != nil || endpoint == nil || len(endpoint.Endpoints.Endpoint) <= 0 { - log.Printf("aliyungo: can not get endpoint from service, use default. endpoint=[%v], error=[%v]\n", endpoint, err) - return "" - } - - for _, protocol := range endpoint.Endpoints.Endpoint[0].Protocols.Protocols { - if strings.ToLower(protocol) == HTTPS_PROTOCOL { - defaultProtocols = HTTPS_PROTOCOL - break - } - } - - ep := fmt.Sprintf("%s://%s", defaultProtocols, endpoint.Endpoints.Endpoint[0].Endpoint) - - setProductRegionEndpoint(region, serviceCode, ep) - return ep -} - -func loadEndpointFromFile(region Region, serviceCode string) string { - data, err := ioutil.ReadFile("./endpoints.xml") - if err != nil { - return "" - } - var endpoints Endpoints - err = xml.Unmarshal(data, &endpoints) - if err != nil { - return "" - } - for _, endpoint := range endpoints.Endpoint { - if endpoint.RegionIds.RegionId == string(region) { - for _, product := range endpoint.Products.Product { - if strings.ToLower(product.ProductName) == serviceCode { - return fmt.Sprintf("%s://%s", HTTPS_PROTOCOL, product.DomainName) - } - } - } - } - - return "" -} diff --git a/vendor/github.com/denverdino/aliyungo/common/endpoints.xml b/vendor/github.com/denverdino/aliyungo/common/endpoints.xml deleted file mode 100644 index 26ea765b..00000000 --- a/vendor/github.com/denverdino/aliyungo/common/endpoints.xml +++ /dev/null @@ -1,1370 +0,0 @@ - - - - jp-fudao-1 - - Ecsecs-cn-hangzhou.aliyuncs.com - - - - me-east-1 - - Rdsrds.me-east-1.aliyuncs.com - Ecsecs.me-east-1.aliyuncs.com - Vpcvpc.me-east-1.aliyuncs.com - Kmskms.me-east-1.aliyuncs.com - Cmsmetrics.cn-hangzhou.aliyuncs.com - Slbslb.me-east-1.aliyuncs.com - - - - us-east-1 - - CScs.aliyuncs.com - Pushcloudpush.aliyuncs.com - COScos.aliyuncs.com - Essess.aliyuncs.com - Ace-opsace-ops.cn-hangzhou.aliyuncs.com - Billingbilling.aliyuncs.com - Dqsdqs.aliyuncs.com - Ddsmongodb.aliyuncs.com - Emremr.aliyuncs.com - Smssms.aliyuncs.com - Jaqjaq.aliyuncs.com - HPChpc.aliyuncs.com - Locationlocation.aliyuncs.com - ChargingServicechargingservice.aliyuncs.com - Msgmsg-inner.aliyuncs.com - Commondrivercommon.driver.aliyuncs.com - R-kvstorer-kvstore-cn-hangzhou.aliyuncs.com - Bssbss.aliyuncs.com - Workorderworkorder.aliyuncs.com - Ocsm-kvstore.aliyuncs.com - Yundunyundun-cn-hangzhou.aliyuncs.com - Ubsms-innerubsms-inner.aliyuncs.com - Dmdm.aliyuncs.com - Greengreen.aliyuncs.com - Riskrisk-cn-hangzhou.aliyuncs.com - oceanbaseoceanbase.aliyuncs.com - Mscmsc-inner.aliyuncs.com - Yundunhsmyundunhsm.aliyuncs.com - Iotiot.aliyuncs.com - jaqjaq.aliyuncs.com - Omsoms.aliyuncs.com - livelive.aliyuncs.com - Ecsecs-cn-hangzhou.aliyuncs.com - Ubsmsubsms.aliyuncs.com - Vpcvpc.aliyuncs.com - Alertalert.aliyuncs.com - Aceace.cn-hangzhou.aliyuncs.com - AMSams.aliyuncs.com - ROSros.aliyuncs.com - PTSpts.aliyuncs.com - Qualitycheckqualitycheck.aliyuncs.com - M-kvstorem-kvstore.aliyuncs.com - HighDDosyd-highddos-cn-hangzhou.aliyuncs.com - CmsSiteMonitorsitemonitor.aliyuncs.com - Rdsrds.aliyuncs.com - BatchComputebatchCompute.aliyuncs.com - CFcf.aliyuncs.com - Drdsdrds.aliyuncs.com - Acsacs.aliyun-inc.com - Httpdnshttpdns-api.aliyuncs.com - Location-innerlocation-inner.aliyuncs.com - Aasaas.aliyuncs.com - Stssts.aliyuncs.com - Dtsdts.aliyuncs.com - Drcdrc.aliyuncs.com - Vpc-innervpc-inner.aliyuncs.com - Cmsmetrics.cn-hangzhou.aliyuncs.com - Slbslb.aliyuncs.com - Crmcrm-cn-hangzhou.aliyuncs.com - Domaindomain.aliyuncs.com - Otsots-pop.aliyuncs.com - Ossoss-cn-hangzhou.aliyuncs.com - Ramram.aliyuncs.com - Salessales.cn-hangzhou.aliyuncs.com - OssAdminoss-admin.aliyuncs.com - Alidnsalidns.aliyuncs.com - Onsons.aliyuncs.com - Cdncdn.aliyuncs.com - YundunDdosinner-yundun-ddos.cn-hangzhou.aliyuncs.com - - - - ap-northeast-1 - - Rdsrds.ap-northeast-1.aliyuncs.com - Kmskms.ap-northeast-1.aliyuncs.com - Vpcvpc.ap-northeast-1.aliyuncs.com - Ecsecs.ap-northeast-1.aliyuncs.com - Cmsmetrics.ap-northeast-1.aliyuncs.com - Kvstorer-kvstore.ap-northeast-1.aliyuncs.com - Slbslb.ap-northeast-1.aliyuncs.com - - - - cn-hangzhou-bj-b01 - - Ecsecs-cn-hangzhou.aliyuncs.com - - - - cn-hongkong - - Pushcloudpush.aliyuncs.com - COScos.aliyuncs.com - Onsons.aliyuncs.com - Essess.aliyuncs.com - Ace-opsace-ops.cn-hangzhou.aliyuncs.com - Billingbilling.aliyuncs.com - Dqsdqs.aliyuncs.com - Ddsmongodb.aliyuncs.com - Emremr.aliyuncs.com - Smssms.aliyuncs.com - Jaqjaq.aliyuncs.com - CScs.aliyuncs.com - Kmskms.cn-hongkong.aliyuncs.com - Locationlocation.aliyuncs.com - Msgmsg-inner.aliyuncs.com - ChargingServicechargingservice.aliyuncs.com - R-kvstorer-kvstore-cn-hangzhou.aliyuncs.com - Alertalert.aliyuncs.com - Mscmsc-inner.aliyuncs.com - Drcdrc.aliyuncs.com - Yundunyundun-cn-hangzhou.aliyuncs.com - Ubsms-innerubsms-inner.aliyuncs.com - Ocsm-kvstore.aliyuncs.com - Dmdm.aliyuncs.com - Riskrisk-cn-hangzhou.aliyuncs.com - oceanbaseoceanbase.aliyuncs.com - Workorderworkorder.aliyuncs.com - Yundunhsmyundunhsm.aliyuncs.com - Iotiot.aliyuncs.com - HPChpc.aliyuncs.com - jaqjaq.aliyuncs.com - Omsoms.aliyuncs.com - livelive.aliyuncs.com - Ecsecs-cn-hangzhou.aliyuncs.com - M-kvstorem-kvstore.aliyuncs.com - Vpcvpc.aliyuncs.com - BatchComputebatchCompute.aliyuncs.com - AMSams.aliyuncs.com - ROSros.aliyuncs.com - PTSpts.aliyuncs.com - Qualitycheckqualitycheck.aliyuncs.com - Bssbss.aliyuncs.com - Ubsmsubsms.aliyuncs.com - CloudAPIapigateway.cn-hongkong.aliyuncs.com - Stssts.aliyuncs.com - CmsSiteMonitorsitemonitor.aliyuncs.com - Aceace.cn-hangzhou.aliyuncs.com - Mtsmts.cn-hongkong.aliyuncs.com - Location-innerlocation-inner.aliyuncs.com - CFcf.aliyuncs.com - Acsacs.aliyun-inc.com - Httpdnshttpdns-api.aliyuncs.com - Greengreen.aliyuncs.com - Aasaas.aliyuncs.com - Alidnsalidns.aliyuncs.com - Dtsdts.aliyuncs.com - HighDDosyd-highddos-cn-hangzhou.aliyuncs.com - Vpc-innervpc-inner.aliyuncs.com - Cmsmetrics.cn-hangzhou.aliyuncs.com - Slbslb.aliyuncs.com - Commondrivercommon.driver.aliyuncs.com - Domaindomain.aliyuncs.com - Otsots-pop.aliyuncs.com - Cdncdn.aliyuncs.com - Ramram.aliyuncs.com - Drdsdrds.aliyuncs.com - Rdsrds.aliyuncs.com - Crmcrm-cn-hangzhou.aliyuncs.com - OssAdminoss-admin.aliyuncs.com - Salessales.cn-hangzhou.aliyuncs.com - YundunDdosinner-yundun-ddos.cn-hangzhou.aliyuncs.com - Ossoss-cn-hongkong.aliyuncs.com - - - - cn-beijing-nu16-b01 - - Ecsecs-cn-hangzhou.aliyuncs.com - - - - cn-beijing-am13-c01 - - Ecsecs-cn-hangzhou.aliyuncs.com - Vpcvpc.aliyuncs.com - - - - in-west-antgroup-1 - - Ecsecs-cn-hangzhou.aliyuncs.com - - - - cn-guizhou-gov - - Ecsecs-cn-hangzhou.aliyuncs.com - Vpcvpc.aliyuncs.com - - - - in-west-antgroup-2 - - Ecsecs-cn-hangzhou.aliyuncs.com - - - - cn-qingdao-cm9 - - CScs.aliyuncs.com - Riskrisk-cn-hangzhou.aliyuncs.com - COScos.aliyuncs.com - Essess.aliyuncs.com - Billingbilling.aliyuncs.com - Dqsdqs.aliyuncs.com - Ddsmongodb.aliyuncs.com - Alidnsalidns.aliyuncs.com - Smssms.aliyuncs.com - Drdsdrds.aliyuncs.com - HPChpc.aliyuncs.com - Locationlocation.aliyuncs.com - Msgmsg-inner.aliyuncs.com - ChargingServicechargingservice.aliyuncs.com - Ocsm-kvstore.aliyuncs.com - Alertalert.aliyuncs.com - Mscmsc-inner.aliyuncs.com - HighDDosyd-highddos-cn-hangzhou.aliyuncs.com - R-kvstorer-kvstore-cn-hangzhou.aliyuncs.com - Yundunyundun-cn-hangzhou.aliyuncs.com - Ubsms-innerubsms-inner.aliyuncs.com - Dmdm.aliyuncs.com - Greengreen.aliyuncs.com - YundunDdosinner-yundun-ddos.cn-hangzhou.aliyuncs.com - oceanbaseoceanbase.aliyuncs.com - Workorderworkorder.aliyuncs.com - Yundunhsmyundunhsm.aliyuncs.com - Iotiot.aliyuncs.com - jaqjaq.aliyuncs.com - Omsoms.aliyuncs.com - livelive.aliyuncs.com - Ecsecs-cn-hangzhou.aliyuncs.com - Ubsmsubsms.aliyuncs.com - CmsSiteMonitorsitemonitor.aliyuncs.com - AMSams.aliyuncs.com - Crmcrm-cn-hangzhou.aliyuncs.com - PTSpts.aliyuncs.com - Qualitycheckqualitycheck.aliyuncs.com - Bssbss.aliyuncs.com - M-kvstorem-kvstore.aliyuncs.com - Aceace.cn-hangzhou.aliyuncs.com - Mtsmts.cn-qingdao.aliyuncs.com - CFcf.aliyuncs.com - Httpdnshttpdns-api.aliyuncs.com - Location-innerlocation-inner.aliyuncs.com - Aasaas.aliyuncs.com - Stssts.aliyuncs.com - Dtsdts.aliyuncs.com - Emremr.aliyuncs.com - Drcdrc.aliyuncs.com - Pushcloudpush.aliyuncs.com - Cmsmetrics.aliyuncs.com - Slbslb.aliyuncs.com - Commondrivercommon.driver.aliyuncs.com - Domaindomain.aliyuncs.com - Otsots-pop.aliyuncs.com - ROSros.aliyuncs.com - Ossoss-cn-hangzhou.aliyuncs.com - Ramram.aliyuncs.com - Salessales.cn-hangzhou.aliyuncs.com - Rdsrds.aliyuncs.com - OssAdminoss-admin.aliyuncs.com - Onsons.aliyuncs.com - Cdncdn.aliyuncs.com - - - - tw-snowcloud-kaohsiung - - Ecsecs-cn-hangzhou.aliyuncs.com - - - - cn-shanghai-finance-1 - - Kmskms.cn-shanghai-finance-1.aliyuncs.com - Ecsecs-cn-hangzhou.aliyuncs.com - Vpcvpc.aliyuncs.com - Rdsrds.aliyuncs.com - - - - cn-guizhou - - Ecsecs-cn-hangzhou.aliyuncs.com - Vpcvpc.aliyuncs.com - - - - cn-qingdao-finance - - Ossoss-cn-qdjbp-a.aliyuncs.com - - - - cn-beijing-gov-1 - - Ossoss-cn-haidian-a.aliyuncs.com - Rdsrds.aliyuncs.com - - - - cn-shanghai - - ARMSarms.cn-shanghai.aliyuncs.com - Riskrisk-cn-hangzhou.aliyuncs.com - COScos.aliyuncs.com - HPChpc.aliyuncs.com - Billingbilling.aliyuncs.com - Dqsdqs.aliyuncs.com - Drcdrc.aliyuncs.com - Alidnsalidns.aliyuncs.com - Smssms.aliyuncs.com - Drdsdrds.aliyuncs.com - CScs.aliyuncs.com - Kmskms.cn-shanghai.aliyuncs.com - Locationlocation.aliyuncs.com - Msgmsg-inner.aliyuncs.com - ChargingServicechargingservice.aliyuncs.com - Ocsm-kvstore.aliyuncs.com - Alertalert.aliyuncs.com - Mscmsc-inner.aliyuncs.com - R-kvstorer-kvstore-cn-hangzhou.aliyuncs.com - Yundunyundun-cn-hangzhou.aliyuncs.com - Ubsms-innerubsms-inner.aliyuncs.com - Dmdm.aliyuncs.com - Greengreen.cn-shanghai.aliyuncs.com - Commondrivercommon.driver.aliyuncs.com - oceanbaseoceanbase.aliyuncs.com - Workorderworkorder.aliyuncs.com - Yundunhsmyundunhsm.aliyuncs.com - Iotiot.aliyuncs.com - Bssbss.aliyuncs.com - Omsoms.aliyuncs.com - Ubsmsubsms.aliyuncs.com - livelive.aliyuncs.com - Ecsecs-cn-hangzhou.aliyuncs.com - Ace-opsace-ops.cn-hangzhou.aliyuncs.com - CmsSiteMonitorsitemonitor.aliyuncs.com - BatchComputebatchCompute.aliyuncs.com - AMSams.aliyuncs.com - ROSros.aliyuncs.com - PTSpts.aliyuncs.com - Qualitycheckqualitycheck.aliyuncs.com - M-kvstorem-kvstore.aliyuncs.com - Apigatewayapigateway.cn-shanghai.aliyuncs.com - CloudAPIapigateway.cn-shanghai.aliyuncs.com - Stssts.aliyuncs.com - Vpcvpc.aliyuncs.com - Aceace.cn-hangzhou.aliyuncs.com - Mtsmts.cn-shanghai.aliyuncs.com - Ddsmongodb.aliyuncs.com - CFcf.aliyuncs.com - Acsacs.aliyun-inc.com - Httpdnshttpdns-api.aliyuncs.com - Pushcloudpush.aliyuncs.com - Location-innerlocation-inner.aliyuncs.com - Aasaas.aliyuncs.com - Emremr.aliyuncs.com - Dtsdts.aliyuncs.com - HighDDosyd-highddos-cn-hangzhou.aliyuncs.com - Jaqjaq.aliyuncs.com - Cmsmetrics.cn-hangzhou.aliyuncs.com - Slbslb.aliyuncs.com - Crmcrm-cn-hangzhou.aliyuncs.com - Domaindomain.aliyuncs.com - Otsots-pop.aliyuncs.com - jaqjaq.aliyuncs.com - Cdncdn.aliyuncs.com - Ramram.aliyuncs.com - Salessales.cn-hangzhou.aliyuncs.com - Vpc-innervpc-inner.aliyuncs.com - Rdsrds.aliyuncs.com - OssAdminoss-admin.aliyuncs.com - Onsons.aliyuncs.com - Essess.aliyuncs.com - Ossoss-cn-shanghai.aliyuncs.com - YundunDdosinner-yundun-ddos.cn-hangzhou.aliyuncs.com - vodvod.cn-shanghai.aliyuncs.com - - - - cn-shenzhen-inner - - Riskrisk-cn-hangzhou.aliyuncs.com - COScos.aliyuncs.com - Onsons.aliyuncs.com - Essess.aliyuncs.com - Billingbilling.aliyuncs.com - Dqsdqs.aliyuncs.com - Ddsmongodb.aliyuncs.com - Alidnsalidns.aliyuncs.com - Smssms.aliyuncs.com - Salessales.cn-hangzhou.aliyuncs.com - HPChpc.aliyuncs.com - Locationlocation.aliyuncs.com - Msgmsg-inner.aliyuncs.com - ChargingServicechargingservice.aliyuncs.com - Ocsm-kvstore.aliyuncs.com - jaqjaq.aliyuncs.com - Mscmsc-inner.aliyuncs.com - HighDDosyd-highddos-cn-hangzhou.aliyuncs.com - R-kvstorer-kvstore-cn-hangzhou.aliyuncs.com - Bssbss.aliyuncs.com - Ubsms-innerubsms-inner.aliyuncs.com - Dmdm.aliyuncs.com - Commondrivercommon.driver.aliyuncs.com - oceanbaseoceanbase.aliyuncs.com - Workorderworkorder.aliyuncs.com - Yundunhsmyundunhsm.aliyuncs.com - Iotiot.aliyuncs.com - Alertalert.aliyuncs.com - Omsoms.aliyuncs.com - livelive.aliyuncs.com - Ecsecs-cn-hangzhou.aliyuncs.com - Ubsmsubsms.aliyuncs.com - CmsSiteMonitorsitemonitor.aliyuncs.com - AMSams.aliyuncs.com - Crmcrm-cn-hangzhou.aliyuncs.com - PTSpts.aliyuncs.com - Qualitycheckqualitycheck.aliyuncs.com - M-kvstorem-kvstore.aliyuncs.com - Stssts.aliyuncs.com - Aceace.cn-hangzhou.aliyuncs.com - Mtsmts.cn-shenzhen.aliyuncs.com - CFcf.aliyuncs.com - Httpdnshttpdns-api.aliyuncs.com - Greengreen.aliyuncs.com - Aasaas.aliyuncs.com - Emremr.aliyuncs.com - CScs.aliyuncs.com - Drcdrc.aliyuncs.com - Pushcloudpush.aliyuncs.com - Cmsmetrics.aliyuncs.com - Slbslb.aliyuncs.com - YundunDdosinner-yundun-ddos.cn-hangzhou.aliyuncs.com - Dtsdts.aliyuncs.com - Domaindomain.aliyuncs.com - Otsots-pop.aliyuncs.com - ROSros.aliyuncs.com - Cdncdn.aliyuncs.com - Ramram.aliyuncs.com - Drdsdrds.aliyuncs.com - Rdsrds.aliyuncs.com - OssAdminoss-admin.aliyuncs.com - Location-innerlocation-inner.aliyuncs.com - Yundunyundun-cn-hangzhou.aliyuncs.com - Ossoss-cn-hangzhou.aliyuncs.com - - - - cn-fujian - - Ecsecs-cn-hangzhou.aliyuncs.com - Rdsrds.aliyuncs.com - - - - in-mumbai-alipay - - Ecsecs-cn-hangzhou.aliyuncs.com - - - - us-west-1 - - CScs.aliyuncs.com - COScos.aliyuncs.com - Essess.aliyuncs.com - Ace-opsace-ops.cn-hangzhou.aliyuncs.com - Billingbilling.aliyuncs.com - Dqsdqs.aliyuncs.com - Ddsmongodb.aliyuncs.com - Stssts.aliyuncs.com - Smssms.aliyuncs.com - Jaqjaq.aliyuncs.com - Pushcloudpush.aliyuncs.com - Alidnsalidns.aliyuncs.com - Locationlocation.aliyuncs.com - Msgmsg-inner.aliyuncs.com - ChargingServicechargingservice.aliyuncs.com - Ocsm-kvstore.aliyuncs.com - Bssbss.aliyuncs.com - Mscmsc-inner.aliyuncs.com - R-kvstorer-kvstore-cn-hangzhou.aliyuncs.com - Yundunyundun-cn-hangzhou.aliyuncs.com - Ubsms-innerubsms-inner.aliyuncs.com - Dmdm.aliyuncs.com - Greengreen.aliyuncs.com - Riskrisk-cn-hangzhou.aliyuncs.com - oceanbaseoceanbase.aliyuncs.com - Workorderworkorder.aliyuncs.com - Yundunhsmyundunhsm.aliyuncs.com - Iotiot.aliyuncs.com - Alertalert.aliyuncs.com - Omsoms.aliyuncs.com - livelive.aliyuncs.com - Ecsecs-cn-hangzhou.aliyuncs.com - M-kvstorem-kvstore.aliyuncs.com - Vpcvpc.aliyuncs.com - BatchComputebatchCompute.aliyuncs.com - Aceace.cn-hangzhou.aliyuncs.com - AMSams.aliyuncs.com - ROSros.aliyuncs.com - PTSpts.aliyuncs.com - Qualitycheckqualitycheck.aliyuncs.com - Ubsmsubsms.aliyuncs.com - HighDDosyd-highddos-cn-hangzhou.aliyuncs.com - CmsSiteMonitorsitemonitor.aliyuncs.com - Rdsrds.aliyuncs.com - Mtsmts.us-west-1.aliyuncs.com - CFcf.aliyuncs.com - Acsacs.aliyun-inc.com - Httpdnshttpdns-api.aliyuncs.com - Location-innerlocation-inner.aliyuncs.com - Aasaas.aliyuncs.com - Emremr.aliyuncs.com - HPChpc.aliyuncs.com - Drcdrc.aliyuncs.com - Vpc-innervpc-inner.aliyuncs.com - Cmsmetrics.cn-hangzhou.aliyuncs.com - Slbslb.aliyuncs.com - Crmcrm-cn-hangzhou.aliyuncs.com - Dtsdts.aliyuncs.com - Domaindomain.aliyuncs.com - Otsots-pop.aliyuncs.com - Commondrivercommon.driver.aliyuncs.com - jaqjaq.aliyuncs.com - Cdncdn.aliyuncs.com - Ramram.aliyuncs.com - Drdsdrds.aliyuncs.com - OssAdminoss-admin.aliyuncs.com - Salessales.cn-hangzhou.aliyuncs.com - Onsons.aliyuncs.com - Ossoss-us-west-1.aliyuncs.com - YundunDdosinner-yundun-ddos.cn-hangzhou.aliyuncs.com - - - - cn-shanghai-inner - - CScs.aliyuncs.com - COScos.aliyuncs.com - Essess.aliyuncs.com - Billingbilling.aliyuncs.com - Dqsdqs.aliyuncs.com - Ddsmongodb.aliyuncs.com - Emremr.aliyuncs.com - Smssms.aliyuncs.com - Drdsdrds.aliyuncs.com - HPChpc.aliyuncs.com - Locationlocation.aliyuncs.com - ChargingServicechargingservice.aliyuncs.com - Msgmsg-inner.aliyuncs.com - Commondrivercommon.driver.aliyuncs.com - R-kvstorer-kvstore-cn-hangzhou.aliyuncs.com - jaqjaq.aliyuncs.com - Mscmsc-inner.aliyuncs.com - Ocsm-kvstore.aliyuncs.com - Yundunyundun-cn-hangzhou.aliyuncs.com - Ubsms-innerubsms-inner.aliyuncs.com - Dmdm.aliyuncs.com - Greengreen.aliyuncs.com - Riskrisk-cn-hangzhou.aliyuncs.com - oceanbaseoceanbase.aliyuncs.com - Workorderworkorder.aliyuncs.com - Yundunhsmyundunhsm.aliyuncs.com - Iotiot.aliyuncs.com - Bssbss.aliyuncs.com - Omsoms.aliyuncs.com - livelive.aliyuncs.com - Ecsecs-cn-hangzhou.aliyuncs.com - M-kvstorem-kvstore.aliyuncs.com - CmsSiteMonitorsitemonitor.aliyuncs.com - Alertalert.aliyuncs.com - Aceace.cn-hangzhou.aliyuncs.com - AMSams.aliyuncs.com - ROSros.aliyuncs.com - PTSpts.aliyuncs.com - Qualitycheckqualitycheck.aliyuncs.com - Ubsmsubsms.aliyuncs.com - HighDDosyd-highddos-cn-hangzhou.aliyuncs.com - Rdsrds.aliyuncs.com - Mtsmts.cn-shanghai.aliyuncs.com - CFcf.aliyuncs.com - Httpdnshttpdns-api.aliyuncs.com - Location-innerlocation-inner.aliyuncs.com - Aasaas.aliyuncs.com - Stssts.aliyuncs.com - Dtsdts.aliyuncs.com - Drcdrc.aliyuncs.com - Pushcloudpush.aliyuncs.com - Cmsmetrics.aliyuncs.com - Slbslb.aliyuncs.com - YundunDdosinner-yundun-ddos.cn-hangzhou.aliyuncs.com - Domaindomain.aliyuncs.com - Otsots-pop.aliyuncs.com - Ossoss-cn-hangzhou.aliyuncs.com - Ramram.aliyuncs.com - Salessales.cn-hangzhou.aliyuncs.com - Crmcrm-cn-hangzhou.aliyuncs.com - OssAdminoss-admin.aliyuncs.com - Alidnsalidns.aliyuncs.com - Onsons.aliyuncs.com - Cdncdn.aliyuncs.com - - - - cn-anhui-gov-1 - - Ecsecs-cn-hangzhou.aliyuncs.com - - - - cn-hangzhou-finance - - Ossoss-cn-hzjbp-b-console.aliyuncs.com - - - - cn-hangzhou - - ARMSarms.cn-hangzhou.aliyuncs.com - CScs.aliyuncs.com - COScos.aliyuncs.com - Essess.aliyuncs.com - Ace-opsace-ops.cn-hangzhou.aliyuncs.com - Billingbilling.aliyuncs.com - Dqsdqs.aliyuncs.com - Ddsmongodb.aliyuncs.com - Stssts.aliyuncs.com - Smssms.aliyuncs.com - Msgmsg-inner.aliyuncs.com - Jaqjaq.aliyuncs.com - Pushcloudpush.aliyuncs.com - Livelive.aliyuncs.com - Kmskms.cn-hangzhou.aliyuncs.com - Locationlocation.aliyuncs.com - Hpchpc.aliyuncs.com - ChargingServicechargingservice.aliyuncs.com - R-kvstorer-kvstore-cn-hangzhou.aliyuncs.com - Alertalert.aliyuncs.com - Mscmsc-inner.aliyuncs.com - Drcdrc.aliyuncs.com - Yundunyundun-cn-hangzhou.aliyuncs.com - Ubsms-innerubsms-inner.aliyuncs.com - Ocsm-kvstore.aliyuncs.com - Dmdm.aliyuncs.com - Greengreen.cn-hangzhou.aliyuncs.com - Commondrivercommon.driver.aliyuncs.com - oceanbaseoceanbase.aliyuncs.com - Workorderworkorder.aliyuncs.com - Yundunhsmyundunhsm.aliyuncs.com - Iotiot.aliyuncs.com - jaqjaq.aliyuncs.com - Omsoms.aliyuncs.com - livelive.aliyuncs.com - Ecsecs-cn-hangzhou.aliyuncs.com - M-kvstorem-kvstore.aliyuncs.com - Vpcvpc.aliyuncs.com - BatchComputebatchCompute.aliyuncs.com - Domaindomain.aliyuncs.com - AMSams.aliyuncs.com - ROSros.aliyuncs.com - PTSpts.aliyuncs.com - Qualitycheckqualitycheck.aliyuncs.com - Ubsmsubsms.aliyuncs.com - Apigatewayapigateway.cn-hangzhou.aliyuncs.com - CloudAPIapigateway.cn-hangzhou.aliyuncs.com - CmsSiteMonitorsitemonitor.aliyuncs.com - Aceace.cn-hangzhou.aliyuncs.com - Mtsmts.cn-hangzhou.aliyuncs.com - Oascn-hangzhou.oas.aliyuncs.com - CFcf.aliyuncs.com - Acsacs.aliyun-inc.com - Httpdnshttpdns-api.aliyuncs.com - Location-innerlocation-inner.aliyuncs.com - Aasaas.aliyuncs.com - Alidnsalidns.aliyuncs.com - HPChpc.aliyuncs.com - Emremr.aliyuncs.com - HighDDosyd-highddos-cn-hangzhou.aliyuncs.com - Vpc-innervpc-inner.aliyuncs.com - Cmsmetrics.cn-hangzhou.aliyuncs.com - Slbslb.aliyuncs.com - Riskrisk-cn-hangzhou.aliyuncs.com - Dtsdts.aliyuncs.com - Bssbss.aliyuncs.com - Otsots-pop.aliyuncs.com - Cdncdn.aliyuncs.com - Ramram.aliyuncs.com - Drdsdrds.aliyuncs.com - Rdsrds.aliyuncs.com - Crmcrm-cn-hangzhou.aliyuncs.com - OssAdminoss-admin.aliyuncs.com - Salessales.cn-hangzhou.aliyuncs.com - Onsons.aliyuncs.com - Ossoss-cn-hangzhou.aliyuncs.com - YundunDdosinner-yundun-ddos.cn-hangzhou.aliyuncs.com - - - - cn-beijing-inner - - Riskrisk-cn-hangzhou.aliyuncs.com - COScos.aliyuncs.com - HPChpc.aliyuncs.com - Billingbilling.aliyuncs.com - Dqsdqs.aliyuncs.com - Ddsmongodb.aliyuncs.com - Emremr.aliyuncs.com - Smssms.aliyuncs.com - Drdsdrds.aliyuncs.com - CScs.aliyuncs.com - Locationlocation.aliyuncs.com - ChargingServicechargingservice.aliyuncs.com - Msgmsg-inner.aliyuncs.com - Essess.aliyuncs.com - R-kvstorer-kvstore-cn-hangzhou.aliyuncs.com - Bssbss.aliyuncs.com - Workorderworkorder.aliyuncs.com - Drcdrc.aliyuncs.com - Yundunyundun-cn-hangzhou.aliyuncs.com - Ubsms-innerubsms-inner.aliyuncs.com - Ocsm-kvstore.aliyuncs.com - Dmdm.aliyuncs.com - YundunDdosinner-yundun-ddos.cn-hangzhou.aliyuncs.com - oceanbaseoceanbase.aliyuncs.com - Mscmsc-inner.aliyuncs.com - Yundunhsmyundunhsm.aliyuncs.com - Iotiot.aliyuncs.com - jaqjaq.aliyuncs.com - Omsoms.aliyuncs.com - M-kvstorem-kvstore.aliyuncs.com - livelive.aliyuncs.com - Ecsecs-cn-hangzhou.aliyuncs.com - Alertalert.aliyuncs.com - CmsSiteMonitorsitemonitor.aliyuncs.com - Aceace.cn-hangzhou.aliyuncs.com - AMSams.aliyuncs.com - Otsots-pop.aliyuncs.com - PTSpts.aliyuncs.com - Qualitycheckqualitycheck.aliyuncs.com - Ubsmsubsms.aliyuncs.com - Stssts.aliyuncs.com - Rdsrds.aliyuncs.com - Mtsmts.cn-beijing.aliyuncs.com - Location-innerlocation-inner.aliyuncs.com - CFcf.aliyuncs.com - Httpdnshttpdns-api.aliyuncs.com - Greengreen.aliyuncs.com - Aasaas.aliyuncs.com - Alidnsalidns.aliyuncs.com - Pushcloudpush.aliyuncs.com - HighDDosyd-highddos-cn-hangzhou.aliyuncs.com - Cmsmetrics.aliyuncs.com - Slbslb.aliyuncs.com - Commondrivercommon.driver.aliyuncs.com - Dtsdts.aliyuncs.com - Domaindomain.aliyuncs.com - ROSros.aliyuncs.com - Ossoss-cn-hangzhou.aliyuncs.com - Ramram.aliyuncs.com - Salessales.cn-hangzhou.aliyuncs.com - Crmcrm-cn-hangzhou.aliyuncs.com - OssAdminoss-admin.aliyuncs.com - Onsons.aliyuncs.com - Cdncdn.aliyuncs.com - - - - cn-haidian-cm12-c01 - - Ecsecs-cn-hangzhou.aliyuncs.com - Vpcvpc.aliyuncs.com - Rdsrds.aliyuncs.com - - - - cn-anhui-gov - - Ecsecs-cn-hangzhou.aliyuncs.com - Vpcvpc.aliyuncs.com - - - - cn-shenzhen - - ARMSarms.cn-shenzhen.aliyuncs.com - CScs.aliyuncs.com - COScos.aliyuncs.com - Onsons.aliyuncs.com - Essess.aliyuncs.com - Dqsdqs.aliyuncs.com - Ddsmongodb.aliyuncs.com - Alidnsalidns.aliyuncs.com - Smssms.aliyuncs.com - Jaqjaq.aliyuncs.com - Pushcloudpush.aliyuncs.com - Kmskms.cn-shenzhen.aliyuncs.com - Locationlocation.aliyuncs.com - Ocsm-kvstore.aliyuncs.com - Alertalert.aliyuncs.com - Drcdrc.aliyuncs.com - R-kvstorer-kvstore-cn-hangzhou.aliyuncs.com - Yundunyundun-cn-hangzhou.aliyuncs.com - Ubsms-innerubsms-inner.aliyuncs.com - Dmdm.aliyuncs.com - Commondrivercommon.driver.aliyuncs.com - oceanbaseoceanbase.aliyuncs.com - Iotiot.aliyuncs.com - HPChpc.aliyuncs.com - Bssbss.aliyuncs.com - Omsoms.aliyuncs.com - Ubsmsubsms.aliyuncs.com - livelive.aliyuncs.com - Ecsecs-cn-hangzhou.aliyuncs.com - M-kvstorem-kvstore.aliyuncs.com - CmsSiteMonitorsitemonitor.aliyuncs.com - BatchComputebatchcompute.cn-shenzhen.aliyuncs.com - Aceace.cn-hangzhou.aliyuncs.com - ROSros.aliyuncs.com - PTSpts.aliyuncs.com - Ace-opsace-ops.cn-hangzhou.aliyuncs.com - Apigatewayapigateway.cn-shenzhen.aliyuncs.com - CloudAPIapigateway.cn-shenzhen.aliyuncs.com - Stssts.aliyuncs.com - Vpcvpc.aliyuncs.com - Rdsrds.aliyuncs.com - Mtsmts.cn-shenzhen.aliyuncs.com - Oascn-shenzhen.oas.aliyuncs.com - CFcf.aliyuncs.com - Acsacs.aliyun-inc.com - Crmcrm-cn-hangzhou.aliyuncs.com - Location-innerlocation-inner.aliyuncs.com - Aasaas.aliyuncs.com - Emremr.aliyuncs.com - Dtsdts.aliyuncs.com - HighDDosyd-highddos-cn-hangzhou.aliyuncs.com - Vpc-innervpc-inner.aliyuncs.com - Cmsmetrics.cn-hangzhou.aliyuncs.com - Slbslb.aliyuncs.com - Riskrisk-cn-hangzhou.aliyuncs.com - Domaindomain.aliyuncs.com - Otsots-pop.aliyuncs.com - jaqjaq.aliyuncs.com - Cdncdn.aliyuncs.com - Ramram.aliyuncs.com - Drdsdrds.aliyuncs.com - OssAdminoss-admin.aliyuncs.com - Greengreen.aliyuncs.com - Httpdnshttpdns-api.aliyuncs.com - Ossoss-cn-shenzhen.aliyuncs.com - - - - ap-southeast-2 - - Rdsrds.ap-southeast-2.aliyuncs.com - Kmskms.ap-southeast-2.aliyuncs.com - Vpcvpc.ap-southeast-2.aliyuncs.com - Ecsecs.ap-southeast-2.aliyuncs.com - Cmsmetrics.cn-hangzhou.aliyuncs.com - Slbslb.ap-southeast-2.aliyuncs.com - - - - cn-qingdao - - CScs.aliyuncs.com - COScos.aliyuncs.com - HPChpc.aliyuncs.com - Dqsdqs.aliyuncs.com - Ddsmongodb.aliyuncs.com - Emremr.cn-qingdao.aliyuncs.com - Smssms.aliyuncs.com - Jaqjaq.aliyuncs.com - Dtsdts.aliyuncs.com - Locationlocation.aliyuncs.com - Essess.aliyuncs.com - R-kvstorer-kvstore-cn-hangzhou.aliyuncs.com - Alertalert.aliyuncs.com - Drcdrc.aliyuncs.com - Yundunyundun-cn-hangzhou.aliyuncs.com - Ubsms-innerubsms-inner.cn-qingdao.aliyuncs.com - Ocsm-kvstore.aliyuncs.com - Dmdm.aliyuncs.com - Riskrisk-cn-hangzhou.aliyuncs.com - oceanbaseoceanbase.aliyuncs.com - Iotiot.aliyuncs.com - Bssbss.aliyuncs.com - Omsoms.aliyuncs.com - Ubsmsubsms.cn-qingdao.aliyuncs.com - livelive.aliyuncs.com - Ecsecs-cn-hangzhou.aliyuncs.com - M-kvstorem-kvstore.aliyuncs.com - CmsSiteMonitorsitemonitor.aliyuncs.com - BatchComputebatchcompute.cn-qingdao.aliyuncs.com - Aceace.cn-hangzhou.aliyuncs.com - Otsots-pop.aliyuncs.com - PTSpts.aliyuncs.com - Ace-opsace-ops.cn-hangzhou.aliyuncs.com - Apigatewayapigateway.cn-qingdao.aliyuncs.com - CloudAPIapigateway.cn-qingdao.aliyuncs.com - Stssts.aliyuncs.com - Rdsrds.aliyuncs.com - Mtsmts.cn-qingdao.aliyuncs.com - Location-innerlocation-inner.aliyuncs.com - CFcf.aliyuncs.com - Acsacs.aliyun-inc.com - Httpdnshttpdns-api.aliyuncs.com - Greengreen.aliyuncs.com - Aasaas.aliyuncs.com - Alidnsalidns.aliyuncs.com - Pushcloudpush.aliyuncs.com - HighDDosyd-highddos-cn-hangzhou.aliyuncs.com - Vpc-innervpc-inner.aliyuncs.com - Cmsmetrics.cn-hangzhou.aliyuncs.com - Slbslb.aliyuncs.com - Commondrivercommon.driver.aliyuncs.com - Domaindomain.aliyuncs.com - ROSros.aliyuncs.com - jaqjaq.aliyuncs.com - Cdncdn.aliyuncs.com - Ramram.aliyuncs.com - Drdsdrds.aliyuncs.com - Crmcrm-cn-hangzhou.aliyuncs.com - OssAdminoss-admin.aliyuncs.com - Onsons.aliyuncs.com - Ossoss-cn-qingdao.aliyuncs.com - - - - cn-shenzhen-su18-b02 - - Ecsecs-cn-hangzhou.aliyuncs.com - - - - cn-shenzhen-su18-b03 - - Ecsecs-cn-hangzhou.aliyuncs.com - - - - cn-shenzhen-su18-b01 - - Ecsecs-cn-hangzhou.aliyuncs.com - - - - ap-southeast-antgroup-1 - - Ecsecs-cn-hangzhou.aliyuncs.com - - - - oss-cn-bjzwy - - Ossoss-cn-bjzwy.aliyuncs.com - - - - cn-henan-am12001 - - Ecsecs-cn-hangzhou.aliyuncs.com - Vpcvpc.aliyuncs.com - - - - cn-beijing - - ARMSarms.cn-beijing.aliyuncs.com - CScs.aliyuncs.com - COScos.aliyuncs.com - Jaqjaq.aliyuncs.com - Essess.aliyuncs.com - Billingbilling.aliyuncs.com - Dqsdqs.aliyuncs.com - Ddsmongodb.aliyuncs.com - Stssts.aliyuncs.com - Smssms.aliyuncs.com - Msgmsg-inner.aliyuncs.com - Salessales.cn-hangzhou.aliyuncs.com - HPChpc.aliyuncs.com - Oascn-beijing.oas.aliyuncs.com - Locationlocation.aliyuncs.com - Onsons.aliyuncs.com - ChargingServicechargingservice.aliyuncs.com - Hpchpc.aliyuncs.com - Commondrivercommon.driver.aliyuncs.com - Ocsm-kvstore.aliyuncs.com - jaqjaq.aliyuncs.com - Workorderworkorder.aliyuncs.com - R-kvstorer-kvstore-cn-hangzhou.aliyuncs.com - Bssbss.aliyuncs.com - Ubsms-innerubsms-inner.aliyuncs.com - Dmdm.aliyuncs.com - Riskrisk-cn-hangzhou.aliyuncs.com - oceanbaseoceanbase.aliyuncs.com - Mscmsc-inner.aliyuncs.com - Yundunhsmyundunhsm.aliyuncs.com - Iotiot.aliyuncs.com - Alertalert.aliyuncs.com - Omsoms.aliyuncs.com - Ubsmsubsms.aliyuncs.com - livelive.aliyuncs.com - Ecsecs-cn-hangzhou.aliyuncs.com - Ace-opsace-ops.cn-hangzhou.aliyuncs.com - Vpcvpc.aliyuncs.com - BatchComputebatchCompute.aliyuncs.com - AMSams.aliyuncs.com - ROSros.aliyuncs.com - PTSpts.aliyuncs.com - M-kvstorem-kvstore.aliyuncs.com - Apigatewayapigateway.cn-beijing.aliyuncs.com - CloudAPIapigateway.cn-beijing.aliyuncs.com - Kmskms.cn-beijing.aliyuncs.com - HighDDosyd-highddos-cn-hangzhou.aliyuncs.com - CmsSiteMonitorsitemonitor.aliyuncs.com - Aceace.cn-hangzhou.aliyuncs.com - Mtsmts.cn-beijing.aliyuncs.com - CFcf.aliyuncs.com - Acsacs.aliyun-inc.com - Httpdnshttpdns-api.aliyuncs.com - Location-innerlocation-inner.aliyuncs.com - Aasaas.aliyuncs.com - Emremr.aliyuncs.com - Dtsdts.aliyuncs.com - Drcdrc.aliyuncs.com - Pushcloudpush.aliyuncs.com - Cmsmetrics.cn-hangzhou.aliyuncs.com - Slbslb.aliyuncs.com - Crmcrm-cn-hangzhou.aliyuncs.com - Domaindomain.aliyuncs.com - Otsots-pop.aliyuncs.com - Ossoss-cn-beijing.aliyuncs.com - Ramram.aliyuncs.com - Drdsdrds.aliyuncs.com - Vpc-innervpc-inner.aliyuncs.com - Rdsrds.aliyuncs.com - OssAdminoss-admin.aliyuncs.com - Alidnsalidns.aliyuncs.com - Greengreen.aliyuncs.com - Yundunyundun-cn-hangzhou.aliyuncs.com - Cdncdn.aliyuncs.com - YundunDdosinner-yundun-ddos.cn-hangzhou.aliyuncs.com - vodvod.cn-beijing.aliyuncs.com - - - - cn-hangzhou-d - - CScs.aliyuncs.com - COScos.aliyuncs.com - Essess.aliyuncs.com - Billingbilling.aliyuncs.com - Dqsdqs.aliyuncs.com - Ddsmongodb.aliyuncs.com - Emremr.aliyuncs.com - Smssms.aliyuncs.com - Salessales.cn-hangzhou.aliyuncs.com - Dtsdts.aliyuncs.com - Locationlocation.aliyuncs.com - Msgmsg-inner.aliyuncs.com - ChargingServicechargingservice.aliyuncs.com - R-kvstorer-kvstore-cn-hangzhou.aliyuncs.com - Bssbss.aliyuncs.com - Mscmsc-inner.aliyuncs.com - Ocsm-kvstore.aliyuncs.com - Yundunyundun-cn-hangzhou.aliyuncs.com - Ubsms-innerubsms-inner.aliyuncs.com - Dmdm.aliyuncs.com - Riskrisk-cn-hangzhou.aliyuncs.com - oceanbaseoceanbase.aliyuncs.com - Workorderworkorder.aliyuncs.com - Alidnsalidns.aliyuncs.com - Iotiot.aliyuncs.com - HPChpc.aliyuncs.com - jaqjaq.aliyuncs.com - Omsoms.aliyuncs.com - livelive.aliyuncs.com - Ecsecs-cn-hangzhou.aliyuncs.com - M-kvstorem-kvstore.aliyuncs.com - CmsSiteMonitorsitemonitor.aliyuncs.com - Alertalert.aliyuncs.com - Aceace.cn-hangzhou.aliyuncs.com - AMSams.aliyuncs.com - Otsots-pop.aliyuncs.com - PTSpts.aliyuncs.com - Qualitycheckqualitycheck.aliyuncs.com - Ubsmsubsms.aliyuncs.com - Rdsrds.aliyuncs.com - Mtsmts.cn-hangzhou.aliyuncs.com - Location-innerlocation-inner.aliyuncs.com - CFcf.aliyuncs.com - Httpdnshttpdns-api.aliyuncs.com - Greengreen.aliyuncs.com - Aasaas.aliyuncs.com - Stssts.aliyuncs.com - Pushcloudpush.aliyuncs.com - HighDDosyd-highddos-cn-hangzhou.aliyuncs.com - Cmsmetrics.aliyuncs.com - Slbslb.aliyuncs.com - YundunDdosinner-yundun-ddos.cn-hangzhou.aliyuncs.com - Domaindomain.aliyuncs.com - Commondrivercommon.driver.aliyuncs.com - ROSros.aliyuncs.com - Cdncdn.aliyuncs.com - Ramram.aliyuncs.com - Drdsdrds.aliyuncs.com - Crmcrm-cn-hangzhou.aliyuncs.com - OssAdminoss-admin.aliyuncs.com - Onsons.aliyuncs.com - Yundunhsmyundunhsm.aliyuncs.com - Drcdrc.aliyuncs.com - Ossoss-cn-hangzhou.aliyuncs.com - - - - cn-gansu-am6 - - Ecsecs-cn-hangzhou.aliyuncs.com - Vpcvpc.aliyuncs.com - Rdsrds.aliyuncs.com - - - - cn-ningxiazhongwei - - Ecsecs-cn-hangzhou.aliyuncs.com - Vpcvpc.aliyuncs.com - - - - cn-shanghai-et2-b01 - - CScs.aliyuncs.com - Riskrisk-cn-hangzhou.aliyuncs.com - COScos.aliyuncs.com - Onsons.aliyuncs.com - Essess.aliyuncs.com - Billingbilling.aliyuncs.com - Dqsdqs.aliyuncs.com - Ddsmongodb.aliyuncs.com - Alidnsalidns.aliyuncs.com - Smssms.aliyuncs.com - Jaqjaq.aliyuncs.com - Dtsdts.aliyuncs.com - Locationlocation.aliyuncs.com - Msgmsg-inner.aliyuncs.com - ChargingServicechargingservice.aliyuncs.com - Ocsm-kvstore.aliyuncs.com - Bssbss.aliyuncs.com - Mscmsc-inner.aliyuncs.com - R-kvstorer-kvstore-cn-hangzhou.aliyuncs.com - Yundunyundun-cn-hangzhou.aliyuncs.com - Ubsms-innerubsms-inner.aliyuncs.com - Dmdm.aliyuncs.com - Commondrivercommon.driver.aliyuncs.com - oceanbaseoceanbase.aliyuncs.com - Workorderworkorder.aliyuncs.com - Yundunhsmyundunhsm.aliyuncs.com - Iotiot.aliyuncs.com - jaqjaq.aliyuncs.com - Omsoms.aliyuncs.com - Ubsmsubsms.aliyuncs.com - livelive.aliyuncs.com - Ecsecs-cn-hangzhou.aliyuncs.com - Ace-opsace-ops.cn-hangzhou.aliyuncs.com - CmsSiteMonitorsitemonitor.aliyuncs.com - BatchComputebatchCompute.aliyuncs.com - Aceace.cn-hangzhou.aliyuncs.com - AMSams.aliyuncs.com - Otsots-pop.aliyuncs.com - PTSpts.aliyuncs.com - Qualitycheckqualitycheck.aliyuncs.com - M-kvstorem-kvstore.aliyuncs.com - Rdsrds.aliyuncs.com - Mtsmts.cn-hangzhou.aliyuncs.com - CFcf.aliyuncs.com - Acsacs.aliyun-inc.com - Httpdnshttpdns-api.aliyuncs.com - Location-innerlocation-inner.aliyuncs.com - Aasaas.aliyuncs.com - Stssts.aliyuncs.com - HPChpc.aliyuncs.com - Emremr.aliyuncs.com - HighDDosyd-highddos-cn-hangzhou.aliyuncs.com - Pushcloudpush.aliyuncs.com - Cmsmetrics.aliyuncs.com - Slbslb.aliyuncs.com - Crmcrm-cn-hangzhou.aliyuncs.com - Alertalert.aliyuncs.com - Domaindomain.aliyuncs.com - ROSros.aliyuncs.com - Cdncdn.aliyuncs.com - Ramram.aliyuncs.com - Drdsdrds.aliyuncs.com - Vpc-innervpc-inner.aliyuncs.com - OssAdminoss-admin.aliyuncs.com - Salessales.cn-hangzhou.aliyuncs.com - Greengreen.aliyuncs.com - Drcdrc.aliyuncs.com - Ossoss-cn-hangzhou.aliyuncs.com - YundunDdosinner-yundun-ddos.cn-hangzhou.aliyuncs.com - - - - cn-ningxia-am7-c01 - - Ecsecs-cn-hangzhou.aliyuncs.com - Vpcvpc.aliyuncs.com - - - - cn-shenzhen-finance-1 - - Kmskms.cn-shenzhen-finance-1.aliyuncs.com - Ecsecs-cn-hangzhou.aliyuncs.com - Rdsrds.aliyuncs.com - Vpcvpc.aliyuncs.com - - - - ap-southeast-1 - - CScs.aliyuncs.com - Riskrisk-cn-hangzhou.aliyuncs.com - COScos.aliyuncs.com - Essess.aliyuncs.com - Billingbilling.aliyuncs.com - Dqsdqs.aliyuncs.com - Ddsmongodb.aliyuncs.com - Alidnsalidns.aliyuncs.com - Smssms.aliyuncs.com - Drdsdrds.aliyuncs.com - Dtsdts.aliyuncs.com - Kmskms.ap-southeast-1.aliyuncs.com - Locationlocation.aliyuncs.com - Msgmsg-inner.aliyuncs.com - ChargingServicechargingservice.aliyuncs.com - R-kvstorer-kvstore-cn-hangzhou.aliyuncs.com - Alertalert.aliyuncs.com - Mscmsc-inner.aliyuncs.com - HighDDosyd-highddos-cn-hangzhou.aliyuncs.com - Yundunyundun-cn-hangzhou.aliyuncs.com - Ubsms-innerubsms-inner.aliyuncs.com - Ocsm-kvstore.aliyuncs.com - Dmdm.aliyuncs.com - Greengreen.aliyuncs.com - Commondrivercommon.driver.aliyuncs.com - oceanbaseoceanbase.aliyuncs.com - Workorderworkorder.aliyuncs.com - Yundunhsmyundunhsm.aliyuncs.com - Iotiot.aliyuncs.com - HPChpc.aliyuncs.com - jaqjaq.aliyuncs.com - Omsoms.aliyuncs.com - livelive.aliyuncs.com - Ecsecs-cn-hangzhou.aliyuncs.com - M-kvstorem-kvstore.aliyuncs.com - Vpcvpc.aliyuncs.com - BatchComputebatchCompute.aliyuncs.com - AMSams.aliyuncs.com - ROSros.aliyuncs.com - PTSpts.aliyuncs.com - Qualitycheckqualitycheck.aliyuncs.com - Bssbss.aliyuncs.com - Ubsmsubsms.aliyuncs.com - Apigatewayapigateway.ap-southeast-1.aliyuncs.com - CloudAPIapigateway.ap-southeast-1.aliyuncs.com - Stssts.aliyuncs.com - CmsSiteMonitorsitemonitor.aliyuncs.com - Aceace.cn-hangzhou.aliyuncs.com - Mtsmts.ap-southeast-1.aliyuncs.com - CFcf.aliyuncs.com - Crmcrm-cn-hangzhou.aliyuncs.com - Location-innerlocation-inner.aliyuncs.com - Aasaas.aliyuncs.com - Emremr.ap-southeast-1.aliyuncs.com - Httpdnshttpdns-api.aliyuncs.com - Drcdrc.aliyuncs.com - Pushcloudpush.aliyuncs.com - Cmsmetrics.cn-hangzhou.aliyuncs.com - Slbslb.aliyuncs.com - YundunDdosinner-yundun-ddos.cn-hangzhou.aliyuncs.com - Domaindomain.aliyuncs.com - Otsots-pop.aliyuncs.com - Cdncdn.aliyuncs.com - Ramram.aliyuncs.com - Salessales.cn-hangzhou.aliyuncs.com - Rdsrds.aliyuncs.com - OssAdminoss-admin.aliyuncs.com - Onsons.aliyuncs.com - Ossoss-ap-southeast-1.aliyuncs.com - - - - cn-shenzhen-st4-d01 - - Ecsecs-cn-hangzhou.aliyuncs.com - - - - eu-central-1 - - Rdsrds.eu-central-1.aliyuncs.com - Ecsecs.eu-central-1.aliyuncs.com - Vpcvpc.eu-central-1.aliyuncs.com - Kmskms.eu-central-1.aliyuncs.com - Cmsmetrics.cn-hangzhou.aliyuncs.com - Slbslb.eu-central-1.aliyuncs.com - - - - eu-west-1 - - Rdsrds.eu-west-1.aliyuncs.com - Ecsecs.eu-west-1.aliyuncs.com - Vpcvpc.eu-west-1.aliyuncs.com - Kmskms.eu-west-1.aliyuncs.com - Cmsmetrics.cn-hangzhou.aliyuncs.com - Slbslb.eu-west-1.aliyuncs.com - - - - cn-zhangjiakou - - Rdsrds.cn-zhangjiakou.aliyuncs.com - Ecsecs.cn-zhangjiakou.aliyuncs.com - Vpcvpc.cn-zhangjiakou.aliyuncs.com - Cmsmetrics.cn-hangzhou.aliyuncs.com - Slbslb.cn-zhangjiakou.aliyuncs.com - - - - cn-huhehaote - - Rdsrds.cn-huhehaote.aliyuncs.com - Ecsecs.cn-huhehaote.aliyuncs.com - Vpcvpc.cn-huhehaote.aliyuncs.com - Cmsmetrics.cn-hangzhou.aliyuncs.com - Slbslb.cn-huhehaote.aliyuncs.com - - - diff --git a/vendor/github.com/denverdino/aliyungo/common/regions.go b/vendor/github.com/denverdino/aliyungo/common/regions.go deleted file mode 100644 index e6bc728f..00000000 --- a/vendor/github.com/denverdino/aliyungo/common/regions.go +++ /dev/null @@ -1,55 +0,0 @@ -package common - -// Region represents ECS region -type Region string - -// Constants of region definition -const ( - Hangzhou = Region("cn-hangzhou") - Qingdao = Region("cn-qingdao") - Beijing = Region("cn-beijing") - Hongkong = Region("cn-hongkong") - Shenzhen = Region("cn-shenzhen") - Shanghai = Region("cn-shanghai") - Zhangjiakou = Region("cn-zhangjiakou") - Huhehaote = Region("cn-huhehaote") - - APSouthEast1 = Region("ap-southeast-1") - APNorthEast1 = Region("ap-northeast-1") - APSouthEast2 = Region("ap-southeast-2") - APSouthEast3 = Region("ap-southeast-3") - APSouthEast5 = Region("ap-southeast-5") - - APSouth1 = Region("ap-south-1") - - USWest1 = Region("us-west-1") - USEast1 = Region("us-east-1") - - MEEast1 = Region("me-east-1") - - EUCentral1 = Region("eu-central-1") - EUWest1 = Region("eu-west-1") - - ShenZhenFinance = Region("cn-shenzhen-finance-1") - ShanghaiFinance = Region("cn-shanghai-finance-1") -) - -var ValidRegions = []Region{ - Hangzhou, Qingdao, Beijing, Shenzhen, Hongkong, Shanghai, Zhangjiakou, Huhehaote, - USWest1, USEast1, - APNorthEast1, APSouthEast1, APSouthEast2, APSouthEast3, APSouthEast5, - APSouth1, - MEEast1, - EUCentral1, EUWest1, - ShenZhenFinance, ShanghaiFinance, -} - -// IsValidRegion checks if r is an Ali supported region. -func IsValidRegion(r string) bool { - for _, v := range ValidRegions { - if r == string(v) { - return true - } - } - return false -} diff --git a/vendor/github.com/denverdino/aliyungo/common/request.go b/vendor/github.com/denverdino/aliyungo/common/request.go deleted file mode 100644 index f35c2990..00000000 --- a/vendor/github.com/denverdino/aliyungo/common/request.go +++ /dev/null @@ -1,105 +0,0 @@ -package common - -import ( - "fmt" - "log" - "time" - - "github.com/denverdino/aliyungo/util" -) - -// Constants for Aliyun API requests -const ( - SignatureVersion = "1.0" - SignatureMethod = "HMAC-SHA1" - JSONResponseFormat = "JSON" - XMLResponseFormat = "XML" - ECSRequestMethod = "GET" -) - -type Request struct { - Format string - Version string - RegionId Region - AccessKeyId string - SecurityToken string - Signature string - SignatureMethod string - Timestamp util.ISO6801Time - SignatureVersion string - SignatureNonce string - ResourceOwnerAccount string - Action string -} - -func (request *Request) init(version string, action string, AccessKeyId string, securityToken string, regionId Region) { - request.Format = JSONResponseFormat - request.Timestamp = util.NewISO6801Time(time.Now().UTC()) - request.Version = version - request.SignatureVersion = SignatureVersion - request.SignatureMethod = SignatureMethod - request.SignatureNonce = util.CreateRandomString() - request.Action = action - request.AccessKeyId = AccessKeyId - request.SecurityToken = securityToken - request.RegionId = regionId -} - -type Response struct { - RequestId string -} - -type ErrorResponse struct { - Response - HostId string - Code string - Message string -} - -// An Error represents a custom error for Aliyun API failure response -type Error struct { - ErrorResponse - StatusCode int //Status Code of HTTP Response -} - -func (e *Error) Error() string { - return fmt.Sprintf("Aliyun API Error: RequestId: %s Status Code: %d Code: %s Message: %s", e.RequestId, e.StatusCode, e.Code, e.Message) -} - -type Pagination struct { - PageNumber int - PageSize int -} - -func (p *Pagination) SetPageSize(size int) { - p.PageSize = size -} - -func (p *Pagination) Validate() { - if p.PageNumber < 0 { - log.Printf("Invalid PageNumber: %d", p.PageNumber) - p.PageNumber = 1 - } - if p.PageSize < 0 { - log.Printf("Invalid PageSize: %d", p.PageSize) - p.PageSize = 10 - } else if p.PageSize > 50 { - log.Printf("Invalid PageSize: %d", p.PageSize) - p.PageSize = 50 - } -} - -// A PaginationResponse represents a response with pagination information -type PaginationResult struct { - TotalCount int - PageNumber int - PageSize int -} - -// NextPage gets the next page of the result set -func (r *PaginationResult) NextPage() *Pagination { - if r.PageNumber*r.PageSize >= r.TotalCount { - return nil - } - return &Pagination{PageNumber: r.PageNumber + 1, PageSize: r.PageSize} -} diff --git a/vendor/github.com/denverdino/aliyungo/common/types.go b/vendor/github.com/denverdino/aliyungo/common/types.go deleted file mode 100644 index cf161f11..00000000 --- a/vendor/github.com/denverdino/aliyungo/common/types.go +++ /dev/null @@ -1,107 +0,0 @@ -package common - -type InternetChargeType string - -const ( - PayByBandwidth = InternetChargeType("PayByBandwidth") - PayByTraffic = InternetChargeType("PayByTraffic") -) - -type InstanceChargeType string - -const ( - PrePaid = InstanceChargeType("PrePaid") - PostPaid = InstanceChargeType("PostPaid") -) - -type DescribeEndpointArgs struct { - Id Region - ServiceCode string - Type string -} - -type EndpointItem struct { - Protocols struct { - Protocols []string - } - Type string - Namespace string - Id Region - SerivceCode string - Endpoint string -} - -type DescribeEndpointResponse struct { - Response - EndpointItem -} - -type DescribeEndpointsArgs struct { - Id Region - ServiceCode string - Type string -} - -type DescribeEndpointsResponse struct { - Response - Endpoints APIEndpoints - RequestId string - Success bool -} - -type APIEndpoints struct { - Endpoint []EndpointItem -} - -type NetType string - -const ( - Internet = NetType("Internet") - Intranet = NetType("Intranet") -) - -type TimeType string - -const ( - Hour = TimeType("Hour") - Day = TimeType("Day") - Week = TimeType("Week") - Month = TimeType("Month") - Year = TimeType("Year") -) - -type NetworkType string - -const ( - Classic = NetworkType("Classic") - VPC = NetworkType("VPC") -) - -type BusinessInfo struct { - Pack string `json:"pack,omitempty"` - ActivityId string `json:"activityId,omitempty"` -} - -//xml -type Endpoints struct { - Endpoint []Endpoint `xml:"Endpoint"` -} - -type Endpoint struct { - Name string `xml:"name,attr"` - RegionIds RegionIds `xml:"RegionIds"` - Products Products `xml:"Products"` -} - -type RegionIds struct { - RegionId string `xml:"RegionId"` -} - -type Products struct { - Product []Product `xml:"Product"` -} - -type Product struct { - ProductName string `xml:"ProductName"` - DomainName string `xml:"DomainName"` -} diff --git a/vendor/github.com/denverdino/aliyungo/common/version.go b/vendor/github.com/denverdino/aliyungo/common/version.go deleted file mode 100644 index 7cb3d3af..00000000 --- a/vendor/github.com/denverdino/aliyungo/common/version.go +++ /dev/null @@ -1,3 +0,0 @@ -package common - -const Version = "0.1" diff --git a/vendor/github.com/denverdino/aliyungo/oss/authenticate_callback.go b/vendor/github.com/denverdino/aliyungo/oss/authenticate_callback.go deleted file mode 100644 index 74b58fb0..00000000 --- a/vendor/github.com/denverdino/aliyungo/oss/authenticate_callback.go +++ /dev/null @@ -1,88 +0,0 @@ -package oss - -import ( - "crypto" - "crypto/md5" - "crypto/rsa" - "crypto/x509" - "encoding/base64" - "encoding/pem" - "errors" - "io/ioutil" - "net/http" - "regexp" - "strings" - "sync" -) - -type authenticationType struct { - lock *sync.RWMutex - certificate map[string]*rsa.PublicKey -} - -var ( - authentication = authenticationType{lock: &sync.RWMutex{}, certificate: map[string]*rsa.PublicKey{}} - urlReg = regexp.MustCompile(`^http(|s)://gosspublic.alicdn.com/[0-9a-zA-Z]`) -) - -//验证OSS向业务服务器发来的回调函数。 -//该方法是并发安全的 -//pubKeyUrl 回调请求头中[x-oss-pub-key-url]一项,以Base64编码 -//reqUrl oss所发来请求的url,由path+query组成 -//reqBody oss所发来请求的body -//authorization authorization为回调头中的签名 -func AuthenticateCallBack(pubKeyUrl, reqUrl, reqBody, authorization string) error { - //获取证书url - keyURL, err := base64.URLEncoding.DecodeString(pubKeyUrl) - if err != nil { - return err - } - url := string(keyURL) - //判断证书是否来自于阿里云 - if !urlReg.Match(keyURL) { - return errors.New("certificate address error") - } - //获取文件名 - rs := []rune(url) - filename := string(rs[strings.LastIndex(url, "/") : len(rs)-1]) - authentication.lock.RLock() - certificate := authentication.certificate[filename] - authentication.lock.RUnlock() - //内存中没有证书,下载 - if certificate == nil { - authentication.lock.Lock() - res, err := http.Get(url) - if err != nil { - return err - } - defer res.Body.Close() - body, err := ioutil.ReadAll(res.Body) - if err != nil { - return err - } - block, _ := pem.Decode(body) - if block == nil { - return errors.New("certificate error") - } - pubKey, err := x509.ParsePKIXPublicKey(block.Bytes) - if err != nil { - return err - } - certificate = pubKey.(*rsa.PublicKey) - authentication.certificate[filename] = certificate - authentication.lock.Unlock() - } - //证书准备完毕,开始验证 - //解析签名 - signature, err := base64.StdEncoding.DecodeString(authorization) - if err != nil { - return err - } - hashed := md5.New() - hashed.Write([]byte(reqUrl + "\n" + reqBody)) - if err := rsa.VerifyPKCS1v15(certificate, crypto.MD5, hashed.Sum(nil), signature); err != nil { - return err - } - //验证通过 - return nil -} diff --git a/vendor/github.com/denverdino/aliyungo/oss/client.go b/vendor/github.com/denverdino/aliyungo/oss/client.go deleted file mode 100644 index c0919194..00000000 --- a/vendor/github.com/denverdino/aliyungo/oss/client.go +++ /dev/null @@ -1,1421 +0,0 @@ -package oss - -import ( - "bytes" - "crypto/hmac" - "crypto/md5" - "crypto/sha1" - "encoding/base64" - "encoding/xml" - "fmt" - "io" - "io/ioutil" - "log" - "mime" - "net" - "net/http" - "net/http/httputil" - "net/url" - "os" - "path" - "strconv" - "strings" - "time" - - "github.com/denverdino/aliyungo/common" - "github.com/denverdino/aliyungo/util" -) - -const DefaultContentType = "application/octet-stream" - -// The Client type encapsulates operations with an OSS region. -type Client struct { - AccessKeyId string - AccessKeySecret string - SecurityToken string - Region Region - Internal bool - Secure bool - ConnectTimeout time.Duration - - endpoint string - debug bool -} - -// The Bucket type encapsulates operations with an bucket. -type Bucket struct { - *Client - Name string -} - -// The Owner type represents the owner of the object in an bucket. -type Owner struct { - ID string - DisplayName string -} - -// Options struct -// -type Options struct { - ServerSideEncryption bool - ServerSideEncryptionKeyID string - - Meta map[string][]string - ContentEncoding string - CacheControl string - ContentMD5 string - ContentDisposition string - //Range string - //Expires int -} - -type CopyOptions struct { - Headers http.Header - CopySourceOptions string - MetadataDirective string - //ContentType string - - ServerSideEncryption bool - ServerSideEncryptionKeyID string -} - -// CopyObjectResult is the output from a Copy request -type CopyObjectResult struct { - ETag string - LastModified string -} - -var attempts = util.AttemptStrategy{ - Min: 5, - Total: 5 * time.Second, - Delay: 200 * time.Millisecond, -} - -// NewOSSClient creates a new OSS. - -func NewOSSClientForAssumeRole(region Region, internal bool, accessKeyId string, accessKeySecret string, securityToken string, secure bool) *Client { - return &Client{ - AccessKeyId: accessKeyId, - AccessKeySecret: accessKeySecret, - SecurityToken: securityToken, - Region: region, - Internal: internal, - debug: false, - Secure: secure, - } -} - -func NewOSSClient(region Region, internal bool, accessKeyId string, accessKeySecret string, secure bool) *Client { - return &Client{ - AccessKeyId: accessKeyId, - AccessKeySecret: accessKeySecret, - Region: region, - Internal: internal, - debug: false, - Secure: secure, - } -} - -// SetDebug sets debug mode to log the request/response message -func (client *Client) SetDebug(debug bool) { - client.debug = debug -} - -// Bucket returns a Bucket with the given name. -func (client *Client) Bucket(name string) *Bucket { - name = strings.ToLower(name) - return &Bucket{ - Client: client, - Name: name, - } -} - -type BucketInfo struct { - Name string - CreationDate string - ExtranetEndpoint string - IntranetEndpoint string - Location string - Grant string `xml:"AccessControlList>Grant"` -} - -type GetServiceResp struct { - Owner Owner - Buckets []BucketInfo `xml:">Bucket"` -} - -type GetBucketInfoResp struct { - Bucket BucketInfo -} - -// GetService gets a list of all buckets owned by an account. -func (client *Client) GetService() (*GetServiceResp, error) { - bucket := client.Bucket("") - - r, err := bucket.Get("") - if err != nil { - return nil, err - } - - // Parse the XML response. - var resp GetServiceResp - if err = xml.Unmarshal(r, &resp); err != nil { - return nil, err - } - - return &resp, nil -} - -type ACL string - -const ( - Private = ACL("private") - PublicRead = ACL("public-read") - PublicReadWrite = ACL("public-read-write") - AuthenticatedRead = ACL("authenticated-read") - BucketOwnerRead = ACL("bucket-owner-read") - BucketOwnerFull = ACL("bucket-owner-full-control") -) - -var createBucketConfiguration = ` - %s -` - -// locationConstraint returns an io.Reader specifying a LocationConstraint if -// required for the region. -func (client *Client) locationConstraint() io.Reader { - constraint := fmt.Sprintf(createBucketConfiguration, client.Region) - return strings.NewReader(constraint) -} - -// override default endpoint -func (client *Client) SetEndpoint(endpoint string) { - // TODO check endpoint - client.endpoint = endpoint -} - -// Info query basic information about the bucket -// -// You can read doc at https://help.aliyun.com/document_detail/31968.html -func (b *Bucket) Info() (BucketInfo, error) { - params := make(url.Values) - params.Set("bucketInfo", "") - r, err := b.GetWithParams("/", params) - - if err != nil { - return BucketInfo{}, err - } - - // Parse the XML response. - var resp GetBucketInfoResp - if err = xml.Unmarshal(r, &resp); err != nil { - return BucketInfo{}, err - } - - return resp.Bucket, nil -} - -// PutBucket creates a new bucket. -// -// You can read doc at http://docs.aliyun.com/#/pub/oss/api-reference/bucket&PutBucket -func (b *Bucket) PutBucket(perm ACL) error { - headers := make(http.Header) - if perm != "" { - headers.Set("x-oss-acl", string(perm)) - } - req := &request{ - method: "PUT", - bucket: b.Name, - path: "/", - headers: headers, - payload: b.Client.locationConstraint(), - } - return b.Client.query(req, nil) -} - -// DelBucket removes an existing bucket. All objects in the bucket must -// be removed before the bucket itself can be removed. -// -// You can read doc at http://docs.aliyun.com/#/pub/oss/api-reference/bucket&DeleteBucket -func (b *Bucket) DelBucket() (err error) { - for attempt := attempts.Start(); attempt.Next(); { - req := &request{ - method: "DELETE", - bucket: b.Name, - path: "/", - } - - err = b.Client.query(req, nil) - if !shouldRetry(err) { - break - } - } - return err -} - -// Get retrieves an object from an bucket. -// -// You can read doc at http://docs.aliyun.com/#/pub/oss/api-reference/object&GetObject -func (b *Bucket) Get(path string) (data []byte, err error) { - body, err := b.GetReader(path) - if err != nil { - return nil, err - } - data, err = ioutil.ReadAll(body) - body.Close() - return data, err -} - -// GetReader retrieves an object from an bucket, -// returning the body of the HTTP response. -// It is the caller's responsibility to call Close on rc when -// finished reading. -func (b *Bucket) GetReader(path string) (rc io.ReadCloser, err error) { - resp, err := b.GetResponse(path) - if resp != nil { - return resp.Body, err - } - return nil, err -} - -// GetResponse retrieves an object from an bucket, -// returning the HTTP response. -// It is the caller's responsibility to call Close on rc when -// finished reading -func (b *Bucket) GetResponse(path string) (resp *http.Response, err error) { - return b.GetResponseWithHeaders(path, make(http.Header)) -} - -// GetResponseWithHeaders retrieves an object from an bucket -// Accepts custom headers to be sent as the second parameter -// returning the body of the HTTP response. -// It is the caller's responsibility to call Close on rc when -// finished reading -func (b *Bucket) GetResponseWithHeaders(path string, headers http.Header) (resp *http.Response, err error) { - for attempt := attempts.Start(); attempt.Next(); { - req := &request{ - bucket: b.Name, - path: path, - headers: headers, - } - err = b.Client.prepare(req) - if err != nil { - return nil, err - } - - resp, err := b.Client.run(req, nil) - if shouldRetry(err) && attempt.HasNext() { - continue - } - if err != nil { - return nil, err - } - return resp, nil - } - panic("unreachable") -} - -// Get retrieves an object from an bucket. -func (b *Bucket) GetWithParams(path string, params url.Values) (data []byte, err error) { - resp, err := b.GetResponseWithParamsAndHeaders(path, params, nil) - if err != nil { - return nil, err - } - data, err = ioutil.ReadAll(resp.Body) - resp.Body.Close() - return data, err -} - -func (b *Bucket) GetResponseWithParamsAndHeaders(path string, params url.Values, headers http.Header) (resp *http.Response, err error) { - for attempt := attempts.Start(); attempt.Next(); { - req := &request{ - bucket: b.Name, - path: path, - params: params, - headers: headers, - } - err = b.Client.prepare(req) - if err != nil { - return nil, err - } - - resp, err := b.Client.run(req, nil) - if shouldRetry(err) && attempt.HasNext() { - continue - } - if err != nil { - return nil, err - } - return resp, nil - } - panic("unreachable") -} - -// Exists checks whether or not an object exists on an bucket using a HEAD request. -func (b *Bucket) Exists(path string) (exists bool, err error) { - for attempt := attempts.Start(); attempt.Next(); { - req := &request{ - method: "HEAD", - bucket: b.Name, - path: path, - } - err = b.Client.prepare(req) - if err != nil { - return - } - - resp, err := b.Client.run(req, nil) - - if shouldRetry(err) && attempt.HasNext() { - continue - } - - if err != nil { - // We can treat a 403 or 404 as non existence - if e, ok := err.(*Error); ok && (e.StatusCode == 403 || e.StatusCode == 404) { - return false, nil - } - return false, err - } - - if resp.StatusCode/100 == 2 { - exists = true - } - if resp.Body != nil { - resp.Body.Close() - } - return exists, err - } - return false, fmt.Errorf("OSS Currently Unreachable") -} - -// Head HEADs an object in the bucket, returns the response with -// -// You can read doc at http://docs.aliyun.com/#/pub/oss/api-reference/object&HeadObject -func (b *Bucket) Head(path string, headers http.Header) (*http.Response, error) { - - for attempt := attempts.Start(); attempt.Next(); { - req := &request{ - method: "HEAD", - bucket: b.Name, - path: path, - headers: headers, - } - err := b.Client.prepare(req) - if err != nil { - return nil, err - } - - resp, err := b.Client.run(req, nil) - if shouldRetry(err) && attempt.HasNext() { - continue - } - if err != nil { - return nil, err - } - if resp != nil && resp.Body != nil { - resp.Body.Close() - } - return resp, err - } - return nil, fmt.Errorf("OSS Currently Unreachable") -} - -// Put inserts an object into the bucket. -// -// You can read doc at http://docs.aliyun.com/#/pub/oss/api-reference/object&PutObject -func (b *Bucket) Put(path string, data []byte, contType string, perm ACL, options Options) error { - body := bytes.NewBuffer(data) - return b.PutReader(path, body, int64(len(data)), contType, perm, options) -} - -// PutCopy puts a copy of an object given by the key path into bucket b using b.Path as the target key -// -// You can read doc at http://docs.aliyun.com/#/pub/oss/api-reference/object&CopyObject -func (b *Bucket) PutCopy(path string, perm ACL, options CopyOptions, source string) (*CopyObjectResult, error) { - headers := make(http.Header) - - headers.Set("x-oss-object-acl", string(perm)) - headers.Set("x-oss-copy-source", source) - - options.addHeaders(headers) - req := &request{ - method: "PUT", - bucket: b.Name, - path: path, - headers: headers, - timeout: 5 * time.Minute, - } - resp := &CopyObjectResult{} - err := b.Client.query(req, resp) - if err != nil { - return resp, err - } - return resp, nil -} - -// PutReader inserts an object into the bucket by consuming data -// from r until EOF. -func (b *Bucket) PutReader(path string, r io.Reader, length int64, contType string, perm ACL, options Options) error { - headers := make(http.Header) - headers.Set("Content-Length", strconv.FormatInt(length, 10)) - headers.Set("Content-Type", contType) - headers.Set("x-oss-object-acl", string(perm)) - - options.addHeaders(headers) - req := &request{ - method: "PUT", - bucket: b.Name, - path: path, - headers: headers, - payload: r, - } - return b.Client.query(req, nil) -} - -// PutFile creates/updates object with file -func (b *Bucket) PutFile(path string, file *os.File, perm ACL, options Options) error { - var contentType string - if dotPos := strings.LastIndex(file.Name(), "."); dotPos == -1 { - contentType = DefaultContentType - } else { - if mimeType := mime.TypeByExtension(file.Name()[dotPos:]); mimeType == "" { - contentType = DefaultContentType - } else { - contentType = mimeType - } - } - stats, err := file.Stat() - if err != nil { - log.Printf("Unable to read file %s stats.\n", file.Name()) - return err - } - - return b.PutReader(path, file, stats.Size(), contentType, perm, options) -} - -// addHeaders adds o's specified fields to headers -func (o Options) addHeaders(headers http.Header) { - if len(o.ServerSideEncryptionKeyID) != 0 { - headers.Set("x-oss-server-side-encryption", "KMS") - headers.Set("x-oss-server-side-encryption-key-id", o.ServerSideEncryptionKeyID) - } else if o.ServerSideEncryption { - headers.Set("x-oss-server-side-encryption", "AES256") - } - if len(o.ContentEncoding) != 0 { - headers.Set("Content-Encoding", o.ContentEncoding) - } - if len(o.CacheControl) != 0 { - headers.Set("Cache-Control", o.CacheControl) - } - if len(o.ContentMD5) != 0 { - headers.Set("Content-MD5", o.ContentMD5) - } - if len(o.ContentDisposition) != 0 { - headers.Set("Content-Disposition", o.ContentDisposition) - } - - for k, v := range o.Meta { - for _, mv := range v { - headers.Add("x-oss-meta-"+k, mv) - } - } -} - -// addHeaders adds o's specified fields to headers -func (o CopyOptions) addHeaders(headers http.Header) { - if len(o.ServerSideEncryptionKeyID) != 0 { - headers.Set("x-oss-server-side-encryption", "KMS") - headers.Set("x-oss-server-side-encryption-key-id", o.ServerSideEncryptionKeyID) - } else if o.ServerSideEncryption { - headers.Set("x-oss-server-side-encryption", "AES256") - } - - if len(o.MetadataDirective) != 0 { - headers.Set("x-oss-metadata-directive", o.MetadataDirective) - } - if len(o.CopySourceOptions) != 0 { - headers.Set("x-oss-copy-source-range", o.CopySourceOptions) - } - if o.Headers != nil { - for k, v := range o.Headers { - newSlice := make([]string, len(v)) - copy(newSlice, v) - headers[k] = newSlice - } - } -} - -func makeXMLBuffer(doc []byte) *bytes.Buffer { - buf := new(bytes.Buffer) - buf.WriteString(xml.Header) - buf.Write(doc) - return buf -} - -type IndexDocument struct { - Suffix string `xml:"Suffix"` -} - -type ErrorDocument struct { - Key string `xml:"Key"` -} - -type RoutingRule struct { - ConditionKeyPrefixEquals string `xml:"Condition>KeyPrefixEquals"` - RedirectReplaceKeyPrefixWith string `xml:"Redirect>ReplaceKeyPrefixWith,omitempty"` - RedirectReplaceKeyWith string `xml:"Redirect>ReplaceKeyWith,omitempty"` -} - -type RedirectAllRequestsTo struct { - HostName string `xml:"HostName"` - Protocol string `xml:"Protocol,omitempty"` -} - -type WebsiteConfiguration struct { - XMLName xml.Name `xml:"http://doc.oss-cn-hangzhou.aliyuncs.com WebsiteConfiguration"` - IndexDocument *IndexDocument `xml:"IndexDocument,omitempty"` - ErrorDocument *ErrorDocument `xml:"ErrorDocument,omitempty"` - RoutingRules *[]RoutingRule `xml:"RoutingRules>RoutingRule,omitempty"` - RedirectAllRequestsTo *RedirectAllRequestsTo `xml:"RedirectAllRequestsTo,omitempty"` -} - -// PutBucketWebsite configures a bucket as a website. -// -// You can read doc at http://docs.aliyun.com/#/pub/oss/api-reference/bucket&PutBucketWebsite -func (b *Bucket) PutBucketWebsite(configuration WebsiteConfiguration) error { - doc, err := xml.Marshal(configuration) - if err != nil { - return err - } - - buf := makeXMLBuffer(doc) - - return b.PutBucketSubresource("website", buf, int64(buf.Len())) -} - -func (b *Bucket) PutBucketSubresource(subresource string, r io.Reader, length int64) error { - headers := make(http.Header) - headers.Set("Content-Length", strconv.FormatInt(length, 10)) - - req := &request{ - path: "/", - method: "PUT", - bucket: b.Name, - headers: headers, - payload: r, - params: url.Values{subresource: {""}}, - } - - return b.Client.query(req, nil) -} - -// Del removes an object from the bucket. -// -// You can read doc at http://docs.aliyun.com/#/pub/oss/api-reference/object&DeleteObject -func (b *Bucket) Del(path string) error { - req := &request{ - method: "DELETE", - bucket: b.Name, - path: path, - } - return b.Client.query(req, nil) -} - -type Delete struct { - Quiet bool `xml:"Quiet,omitempty"` - Objects []Object `xml:"Object"` -} - -type Object struct { - Key string `xml:"Key"` - VersionId string `xml:"VersionId,omitempty"` -} - -// DelMulti removes up to 1000 objects from the bucket. -// -// You can read doc at http://docs.aliyun.com/#/pub/oss/api-reference/object&DeleteMultipleObjects -func (b *Bucket) DelMulti(objects Delete) error { - doc, err := xml.Marshal(objects) - if err != nil { - return err - } - - buf := makeXMLBuffer(doc) - digest := md5.New() - size, err := digest.Write(buf.Bytes()) - if err != nil { - return err - } - - headers := make(http.Header) - headers.Set("Content-Length", strconv.FormatInt(int64(size), 10)) - headers.Set("Content-MD5", base64.StdEncoding.EncodeToString(digest.Sum(nil))) - headers.Set("Content-Type", "text/xml") - - req := &request{ - path: "/", - method: "POST", - params: url.Values{"delete": {""}}, - bucket: b.Name, - headers: headers, - payload: buf, - } - - return b.Client.query(req, nil) -} - -// The ListResp type holds the results of a List bucket operation. -type ListResp struct { - Name string - Prefix string - Delimiter string - Marker string - MaxKeys int - // IsTruncated is true if the results have been truncated because - // there are more keys and prefixes than can fit in MaxKeys. - // N.B. this is the opposite sense to that documented (incorrectly) in - // http://goo.gl/YjQTc - IsTruncated bool - Contents []Key - CommonPrefixes []string `xml:">Prefix"` - // if IsTruncated is true, pass NextMarker as marker argument to List() - // to get the next set of keys - NextMarker string -} - -// The Key type represents an item stored in an bucket. -type Key struct { - Key string - LastModified string - Type string - Size int64 - // ETag gives the hex-encoded MD5 sum of the contents, - // surrounded with double-quotes. - ETag string - StorageClass string - Owner Owner -} - -// List returns information about objects in an bucket. -// -// The prefix parameter limits the response to keys that begin with the -// specified prefix. -// -// The delim parameter causes the response to group all of the keys that -// share a common prefix up to the next delimiter in a single entry within -// the CommonPrefixes field. You can use delimiters to separate a bucket -// into different groupings of keys, similar to how folders would work. -// -// The marker parameter specifies the key to start with when listing objects -// in a bucket. OSS lists objects in alphabetical order and -// will return keys alphabetically greater than the marker. -// -// The max parameter specifies how many keys + common prefixes to return in -// the response, at most 1000. The default is 100. -// -// For example, given these keys in a bucket: -// -// index.html -// index2.html -// photos/2006/January/sample.jpg -// photos/2006/February/sample2.jpg -// photos/2006/February/sample3.jpg -// photos/2006/February/sample4.jpg -// -// Listing this bucket with delimiter set to "/" would yield the -// following result: -// -// &ListResp{ -// Name: "sample-bucket", -// MaxKeys: 1000, -// Delimiter: "/", -// Contents: []Key{ -// {Key: "index.html", "index2.html"}, -// }, -// CommonPrefixes: []string{ -// "photos/", -// }, -// } -// -// Listing the same bucket with delimiter set to "/" and prefix set to -// "photos/2006/" would yield the following result: -// -// &ListResp{ -// Name: "sample-bucket", -// MaxKeys: 1000, -// Delimiter: "/", -// Prefix: "photos/2006/", -// CommonPrefixes: []string{ -// "photos/2006/February/", -// "photos/2006/January/", -// }, -// } -// -// -// You can read doc at http://docs.aliyun.com/#/pub/oss/api-reference/bucket&GetBucket -func (b *Bucket) List(prefix, delim, marker string, max int) (result *ListResp, err error) { - params := make(url.Values) - params.Set("prefix", prefix) - params.Set("delimiter", delim) - params.Set("marker", marker) - if max != 0 { - params.Set("max-keys", strconv.FormatInt(int64(max), 10)) - } - result = &ListResp{} - for attempt := attempts.Start(); attempt.Next(); { - req := &request{ - bucket: b.Name, - params: params, - } - err = b.Client.query(req, result) - if !shouldRetry(err) { - break - } - } - if err != nil { - return nil, err - } - // if NextMarker is not returned, it should be set to the name of last key, - // so let's do it so that each caller doesn't have to - if result.IsTruncated && result.NextMarker == "" { - n := len(result.Contents) - if n > 0 { - result.NextMarker = result.Contents[n-1].Key - } - } - return result, nil -} - -type GetLocationResp struct { - Location string `xml:",innerxml"` -} - -func (b *Bucket) Location() (string, error) { - params := make(url.Values) - params.Set("location", "") - r, err := b.GetWithParams("/", params) - - if err != nil { - return "", err - } - - // Parse the XML response. - var resp GetLocationResp - if err = xml.Unmarshal(r, &resp); err != nil { - return "", err - } - - if resp.Location == "" { - return string(Hangzhou), nil - } - return resp.Location, nil -} - -func (b *Bucket) Path(path string) string { - if !strings.HasPrefix(path, "/") { - path = "/" + path - } - return "/" + b.Name + path -} - -// URL returns a non-signed URL that allows retriving the -// object at path. It only works if the object is publicly -// readable (see SignedURL). -func (b *Bucket) URL(path string) string { - req := &request{ - bucket: b.Name, - path: path, - } - err := b.Client.prepare(req) - if err != nil { - panic(err) - } - u, err := req.url() - if err != nil { - panic(err) - } - u.RawQuery = "" - return u.String() -} - -// SignedURL returns a signed URL that allows anyone holding the URL -// to retrieve the object at path. The signature is valid until expires. -func (b *Bucket) SignedURL(path string, expires time.Time) string { - return b.SignedURLWithArgs(path, expires, nil, nil) -} - -// SignedURLWithArgs returns a signed URL that allows anyone holding the URL -// to retrieve the object at path. The signature is valid until expires. -func (b *Bucket) SignedURLWithArgs(path string, expires time.Time, params url.Values, headers http.Header) string { - return b.SignedURLWithMethod("GET", path, expires, params, headers) -} - -func (b *Bucket) SignedURLWithMethodForAssumeRole(method, path string, expires time.Time, params url.Values, headers http.Header) string { - var uv = url.Values{} - if params != nil { - uv = params - } - if len(b.Client.SecurityToken) != 0 { - uv.Set("security-token", b.Client.SecurityToken) - } - return b.SignedURLWithMethod(method, path, expires, params, headers) -} - -// SignedURLWithMethod returns a signed URL that allows anyone holding the URL -// to either retrieve the object at path or make a HEAD request against it. The signature is valid until expires. -func (b *Bucket) SignedURLWithMethod(method, path string, expires time.Time, params url.Values, headers http.Header) string { - var uv = url.Values{} - - if params != nil { - uv = params - } - - uv.Set("Expires", strconv.FormatInt(expires.Unix(), 10)) - uv.Set("OSSAccessKeyId", b.AccessKeyId) - - req := &request{ - method: method, - bucket: b.Name, - path: path, - params: uv, - headers: headers, - } - err := b.Client.prepare(req) - if err != nil { - panic(err) - } - u, err := req.url() - if err != nil { - panic(err) - } - - return u.String() -} - -// UploadSignedURL returns a signed URL that allows anyone holding the URL -// to upload the object at path. The signature is valid until expires. -// contenttype is a string like image/png -// name is the resource name in OSS terminology like images/ali.png [obviously excluding the bucket name itself] -func (b *Bucket) UploadSignedURL(name, method, contentType string, expires time.Time) string { - //TODO TESTING - expireDate := expires.Unix() - if method != "POST" { - method = "PUT" - } - - tokenData := "" - - stringToSign := method + "\n\n" + contentType + "\n" + strconv.FormatInt(expireDate, 10) + "\n" + tokenData + "/" + path.Join(b.Name, name) - secretKey := b.AccessKeySecret - accessId := b.AccessKeyId - mac := hmac.New(sha1.New, []byte(secretKey)) - mac.Write([]byte(stringToSign)) - macsum := mac.Sum(nil) - signature := base64.StdEncoding.EncodeToString(macsum) - signature = strings.TrimSpace(signature) - - signedurl, err := url.Parse(b.Region.GetEndpoint(b.Internal, b.Name, b.Secure)) - if err != nil { - log.Println("ERROR sining url for OSS upload", err) - return "" - } - signedurl.Path = name - params := url.Values{} - params.Add("OSSAccessKeyId", accessId) - params.Add("Expires", strconv.FormatInt(expireDate, 10)) - params.Add("Signature", signature) - - signedurl.RawQuery = params.Encode() - return signedurl.String() -} - -// PostFormArgsEx returns the action and input fields needed to allow anonymous -// uploads to a bucket within the expiration limit -// Additional conditions can be specified with conds -func (b *Bucket) PostFormArgsEx(path string, expires time.Time, redirect string, conds []string) (action string, fields map[string]string) { - conditions := []string{} - fields = map[string]string{ - "AWSAccessKeyId": b.AccessKeyId, - "key": path, - } - - if conds != nil { - conditions = append(conditions, conds...) - } - - conditions = append(conditions, fmt.Sprintf("{\"key\": \"%s\"}", path)) - conditions = append(conditions, fmt.Sprintf("{\"bucket\": \"%s\"}", b.Name)) - if redirect != "" { - conditions = append(conditions, fmt.Sprintf("{\"success_action_redirect\": \"%s\"}", redirect)) - fields["success_action_redirect"] = redirect - } - - vExpiration := expires.Format("2006-01-02T15:04:05Z") - vConditions := strings.Join(conditions, ",") - policy := fmt.Sprintf("{\"expiration\": \"%s\", \"conditions\": [%s]}", vExpiration, vConditions) - policy64 := base64.StdEncoding.EncodeToString([]byte(policy)) - fields["policy"] = policy64 - - signer := hmac.New(sha1.New, []byte(b.AccessKeySecret)) - signer.Write([]byte(policy64)) - fields["signature"] = base64.StdEncoding.EncodeToString(signer.Sum(nil)) - - action = fmt.Sprintf("%s/%s/", b.Client.Region, b.Name) - return -} - -// PostFormArgs returns the action and input fields needed to allow anonymous -// uploads to a bucket within the expiration limit -func (b *Bucket) PostFormArgs(path string, expires time.Time, redirect string) (action string, fields map[string]string) { - return b.PostFormArgsEx(path, expires, redirect, nil) -} - -type request struct { - method string - bucket string - path string - params url.Values - headers http.Header - baseurl string - payload io.Reader - prepared bool - timeout time.Duration -} - -func (req *request) url() (*url.URL, error) { - u, err := url.Parse(req.baseurl) - if err != nil { - return nil, fmt.Errorf("bad OSS endpoint URL %q: %v", req.baseurl, err) - } - u.RawQuery = req.params.Encode() - u.Path = req.path - return u, nil -} - -// query prepares and runs the req request. -// If resp is not nil, the XML data contained in the response -// body will be unmarshalled on it. -func (client *Client) query(req *request, resp interface{}) error { - err := client.prepare(req) - if err != nil { - return err - } - r, err := client.run(req, resp) - if r != nil && r.Body != nil { - r.Body.Close() - } - return err -} - -// Sets baseurl on req from bucket name and the region endpoint -func (client *Client) setBaseURL(req *request) error { - - if client.endpoint == "" { - req.baseurl = client.Region.GetEndpoint(client.Internal, req.bucket, client.Secure) - } else { - req.baseurl = fmt.Sprintf("%s://%s", getProtocol(client.Secure), client.endpoint) - } - - return nil -} - -// partiallyEscapedPath partially escapes the OSS path allowing for all OSS REST API calls. -// -// Some commands including: -// GET Bucket acl http://goo.gl/aoXflF -// GET Bucket cors http://goo.gl/UlmBdx -// GET Bucket lifecycle http://goo.gl/8Fme7M -// GET Bucket policy http://goo.gl/ClXIo3 -// GET Bucket location http://goo.gl/5lh8RD -// GET Bucket Logging http://goo.gl/sZ5ckF -// GET Bucket notification http://goo.gl/qSSZKD -// GET Bucket tagging http://goo.gl/QRvxnM -// require the first character after the bucket name in the path to be a literal '?' and -// not the escaped hex representation '%3F'. -func partiallyEscapedPath(path string) string { - pathEscapedAndSplit := strings.Split((&url.URL{Path: path}).String(), "/") - if len(pathEscapedAndSplit) >= 3 { - if len(pathEscapedAndSplit[2]) >= 3 { - // Check for the one "?" that should not be escaped. - if pathEscapedAndSplit[2][0:3] == "%3F" { - pathEscapedAndSplit[2] = "?" + pathEscapedAndSplit[2][3:] - } - } - } - return strings.Replace(strings.Join(pathEscapedAndSplit, "/"), "+", "%2B", -1) -} - -// prepare sets up req to be delivered to OSS. -func (client *Client) prepare(req *request) error { - // Copy so they can be mutated without affecting on retries. - headers := copyHeader(req.headers) - // security-token should be in either Params or Header, cannot be in both - if len(req.params.Get("security-token")) == 0 && len(client.SecurityToken) != 0 { - headers.Set("x-oss-security-token", client.SecurityToken) - } - - params := make(url.Values) - - for k, v := range req.params { - params[k] = v - } - - req.params = params - req.headers = headers - - if !req.prepared { - req.prepared = true - if req.method == "" { - req.method = "GET" - } - - if !strings.HasPrefix(req.path, "/") { - req.path = "/" + req.path - } - - err := client.setBaseURL(req) - if err != nil { - return err - } - } - - req.headers.Set("Date", util.GetGMTime()) - client.signRequest(req) - - return nil -} - -// Prepares an *http.Request for doHttpRequest -func (client *Client) setupHttpRequest(req *request) (*http.Request, error) { - // Copy so that signing the http request will not mutate it - - u, err := req.url() - if err != nil { - return nil, err - } - u.Opaque = fmt.Sprintf("//%s%s", u.Host, partiallyEscapedPath(u.Path)) - - hreq := http.Request{ - URL: u, - Method: req.method, - ProtoMajor: 1, - ProtoMinor: 1, - Close: true, - Header: req.headers, - Form: req.params, - } - - hreq.Header.Set("X-SDK-Client", `AliyunGO/`+common.Version) - - contentLength := req.headers.Get("Content-Length") - - if contentLength != "" { - hreq.ContentLength, _ = strconv.ParseInt(contentLength, 10, 64) - req.headers.Del("Content-Length") - } - - if req.payload != nil { - hreq.Body = ioutil.NopCloser(req.payload) - } - - return &hreq, nil -} - -// doHttpRequest sends hreq and returns the http response from the server. -// If resp is not nil, the XML data contained in the response -// body will be unmarshalled on it. -func (client *Client) doHttpRequest(c *http.Client, hreq *http.Request, resp interface{}) (*http.Response, error) { - - if client.debug { - log.Printf("%s %s ...\n", hreq.Method, hreq.URL.String()) - } - hresp, err := c.Do(hreq) - if err != nil { - return nil, err - } - if client.debug { - log.Printf("%s %s %d\n", hreq.Method, hreq.URL.String(), hresp.StatusCode) - contentType := hresp.Header.Get("Content-Type") - if contentType == "application/xml" || contentType == "text/xml" { - dump, _ := httputil.DumpResponse(hresp, true) - log.Printf("%s\n", dump) - } else { - log.Printf("Response Content-Type: %s\n", contentType) - } - } - if hresp.StatusCode != 200 && hresp.StatusCode != 204 && hresp.StatusCode != 206 { - return nil, client.buildError(hresp) - } - if resp != nil { - err = xml.NewDecoder(hresp.Body).Decode(resp) - hresp.Body.Close() - - if client.debug { - log.Printf("aliyungo.oss> decoded xml into %#v", resp) - } - - } - return hresp, err -} - -// run sends req and returns the http response from the server. -// If resp is not nil, the XML data contained in the response -// body will be unmarshalled on it. -func (client *Client) run(req *request, resp interface{}) (*http.Response, error) { - if client.debug { - log.Printf("Running OSS request: %#v", req) - } - - hreq, err := client.setupHttpRequest(req) - if err != nil { - return nil, err - } - - c := &http.Client{ - Transport: &http.Transport{ - Dial: func(netw, addr string) (c net.Conn, err error) { - if client.ConnectTimeout > 0 { - c, err = net.DialTimeout(netw, addr, client.ConnectTimeout) - } else { - c, err = net.Dial(netw, addr) - } - if err != nil { - return - } - return - }, - Proxy: http.ProxyFromEnvironment, - }, - Timeout: req.timeout, - } - - return client.doHttpRequest(c, hreq, resp) -} - -// Error represents an error in an operation with OSS. -type Error struct { - StatusCode int // HTTP status code (200, 403, ...) - Code string // OSS error code ("UnsupportedOperation", ...) - Message string // The human-oriented error message - BucketName string - RequestId string - HostId string -} - -func (e *Error) Error() string { - return fmt.Sprintf("Aliyun API Error: RequestId: %s Status Code: %d Code: %s Message: %s", e.RequestId, e.StatusCode, e.Code, e.Message) -} - -func (client *Client) buildError(r *http.Response) error { - if client.debug { - log.Printf("got error (status code %v)", r.StatusCode) - data, err := ioutil.ReadAll(r.Body) - if err != nil { - log.Printf("\tread error: %v", err) - } else { - log.Printf("\tdata:\n%s\n\n", data) - } - r.Body = ioutil.NopCloser(bytes.NewBuffer(data)) - } - - err := Error{} - // TODO return error if Unmarshal fails? - xml.NewDecoder(r.Body).Decode(&err) - r.Body.Close() - err.StatusCode = r.StatusCode - if err.Message == "" { - err.Message = r.Status - } - if client.debug { - log.Printf("err: %#v\n", err) - } - return &err -} - -type TimeoutError interface { - error - Timeout() bool // Is the error a timeout? -} - -func shouldRetry(err error) bool { - if err == nil { - return false - } - - _, ok := err.(TimeoutError) - if ok { - return true - } - - switch err { - case io.ErrUnexpectedEOF, io.EOF: - return true - } - switch e := err.(type) { - case *net.DNSError: - return true - case *net.OpError: - switch e.Op { - case "read", "write": - return true - } - case *url.Error: - // url.Error can be returned either by net/url if a URL cannot be - // parsed, or by net/http if the response is closed before the headers - // are received or parsed correctly. In that later case, e.Op is set to - // the HTTP method name with the first letter uppercased. We don't want - // to retry on POST operations, since those are not idempotent, all the - // other ones should be safe to retry. - switch e.Op { - case "Get", "Put", "Delete", "Head": - return shouldRetry(e.Err) - default: - return false - } - case *Error: - switch e.Code { - case "InternalError", "NoSuchUpload", "NoSuchBucket": - return true - } - } - return false -} - -func hasCode(err error, code string) bool { - e, ok := err.(*Error) - return ok && e.Code == code -} - -func copyHeader(header http.Header) (newHeader http.Header) { - newHeader = make(http.Header) - for k, v := range header { - newSlice := make([]string, len(v)) - copy(newSlice, v) - newHeader[k] = newSlice - } - return -} - -type AccessControlPolicy struct { - Owner Owner - Grants []string `xml:"AccessControlList>Grant"` -} - -// ACL returns ACL of bucket -// -// You can read doc at http://docs.aliyun.com/#/pub/oss/api-reference/bucket&GetBucketAcl -func (b *Bucket) ACL() (result *AccessControlPolicy, err error) { - - params := make(url.Values) - params.Set("acl", "") - - r, err := b.GetWithParams("/", params) - if err != nil { - return nil, err - } - - // Parse the XML response. - var resp AccessControlPolicy - if err = xml.Unmarshal(r, &resp); err != nil { - return nil, err - } - - return &resp, nil -} - -func (b *Bucket) GetContentLength(sourcePath string) (int64, error) { - resp, err := b.Head(sourcePath, nil) - if err != nil { - return 0, err - } - - currentLength := resp.ContentLength - - return currentLength, err -} - -func (b *Bucket) CopyLargeFile(sourcePath string, destPath string, contentType string, perm ACL, options Options) error { - return b.CopyLargeFileInParallel(sourcePath, destPath, contentType, perm, options, 1) -} - -const defaultChunkSize = int64(128 * 1024 * 1024) //128MB -const maxCopytSize = int64(128 * 1024 * 1024) //128MB - -// Copy large file in the same bucket -func (b *Bucket) CopyLargeFileInParallel(sourcePath string, destPath string, contentType string, perm ACL, options Options, maxConcurrency int) error { - - if maxConcurrency < 1 { - maxConcurrency = 1 - } - - currentLength, err := b.GetContentLength(sourcePath) - - log.Printf("Parallel Copy large file[size: %d] from %s to %s\n", currentLength, sourcePath, destPath) - - if err != nil { - return err - } - - if currentLength < maxCopytSize { - _, err := b.PutCopy(destPath, perm, - CopyOptions{}, - b.Path(sourcePath)) - return err - } - - multi, err := b.InitMulti(destPath, contentType, perm, options) - if err != nil { - return err - } - - numParts := (currentLength + defaultChunkSize - 1) / defaultChunkSize - completedParts := make([]Part, numParts) - - errChan := make(chan error, numParts) - limiter := make(chan struct{}, maxConcurrency) - - var start int64 = 0 - var to int64 = 0 - var partNumber = 0 - sourcePathForCopy := b.Path(sourcePath) - - for start = 0; start < currentLength; start = to { - to = start + defaultChunkSize - if to > currentLength { - to = currentLength - } - partNumber++ - - rangeStr := fmt.Sprintf("bytes=%d-%d", start, to-1) - limiter <- struct{}{} - go func(partNumber int, rangeStr string) { - _, part, err := multi.PutPartCopyWithContentLength(partNumber, - CopyOptions{CopySourceOptions: rangeStr}, - sourcePathForCopy, currentLength) - if err == nil { - completedParts[partNumber-1] = part - } else { - log.Printf("Unable in PutPartCopy of part %d for %s: %v\n", partNumber, sourcePathForCopy, err) - } - errChan <- err - <-limiter - }(partNumber, rangeStr) - } - - fullyCompleted := true - for range completedParts { - err := <-errChan - if err != nil { - fullyCompleted = false - } - } - - if fullyCompleted { - err = multi.Complete(completedParts) - } else { - err = multi.Abort() - } - - return err -} diff --git a/vendor/github.com/denverdino/aliyungo/oss/export.go b/vendor/github.com/denverdino/aliyungo/oss/export.go deleted file mode 100644 index ebdb0477..00000000 --- a/vendor/github.com/denverdino/aliyungo/oss/export.go +++ /dev/null @@ -1,23 +0,0 @@ -package oss - -import ( - "github.com/denverdino/aliyungo/util" -) - -var originalStrategy = attempts - -func SetAttemptStrategy(s *util.AttemptStrategy) { - if s == nil { - attempts = originalStrategy - } else { - attempts = *s - } -} - -func SetListPartsMax(n int) { - listPartsMax = n -} - -func SetListMultiMax(n int) { - listMultiMax = n -} diff --git a/vendor/github.com/denverdino/aliyungo/oss/multi.go b/vendor/github.com/denverdino/aliyungo/oss/multi.go deleted file mode 100644 index d720e188..00000000 --- a/vendor/github.com/denverdino/aliyungo/oss/multi.go +++ /dev/null @@ -1,489 +0,0 @@ -package oss - -import ( - "bytes" - "crypto/md5" - "encoding/base64" - "encoding/hex" - "encoding/xml" - "errors" - "io" - "time" - //"log" - "net/http" - "net/url" - "sort" - "strconv" - "strings" -) - -// Multi represents an unfinished multipart upload. -// -// Multipart uploads allow sending big objects in smaller chunks. -// After all parts have been sent, the upload must be explicitly -// completed by calling Complete with the list of parts. - -type Multi struct { - Bucket *Bucket - Key string - UploadId string -} - -// That's the default. Here just for testing. -var listMultiMax = 1000 - -type listMultiResp struct { - NextKeyMarker string - NextUploadIdMarker string - IsTruncated bool - Upload []Multi - CommonPrefixes []string `xml:"CommonPrefixes>Prefix"` -} - -// ListMulti returns the list of unfinished multipart uploads in b. -// -// The prefix parameter limits the response to keys that begin with the -// specified prefix. You can use prefixes to separate a bucket into different -// groupings of keys (to get the feeling of folders, for example). -// -// The delim parameter causes the response to group all of the keys that -// share a common prefix up to the next delimiter in a single entry within -// the CommonPrefixes field. You can use delimiters to separate a bucket -// into different groupings of keys, similar to how folders would work. -// -func (b *Bucket) ListMulti(prefix, delim string) (multis []*Multi, prefixes []string, err error) { - params := make(url.Values) - params.Set("uploads", "") - params.Set("max-uploads", strconv.FormatInt(int64(listMultiMax), 10)) - params.Set("prefix", prefix) - params.Set("delimiter", delim) - - for attempt := attempts.Start(); attempt.Next(); { - req := &request{ - method: "GET", - bucket: b.Name, - params: params, - } - var resp listMultiResp - err := b.Client.query(req, &resp) - if shouldRetry(err) && attempt.HasNext() { - continue - } - if err != nil { - return nil, nil, err - } - for i := range resp.Upload { - multi := &resp.Upload[i] - multi.Bucket = b - multis = append(multis, multi) - } - prefixes = append(prefixes, resp.CommonPrefixes...) - if !resp.IsTruncated { - return multis, prefixes, nil - } - params.Set("key-marker", resp.NextKeyMarker) - params.Set("upload-id-marker", resp.NextUploadIdMarker) - attempt = attempts.Start() // Last request worked. - } - panic("unreachable") -} - -// Multi returns a multipart upload handler for the provided key -// inside b. If a multipart upload exists for key, it is returned, -// otherwise a new multipart upload is initiated with contType and perm. -func (b *Bucket) Multi(key, contType string, perm ACL, options Options) (*Multi, error) { - multis, _, err := b.ListMulti(key, "") - if err != nil && !hasCode(err, "NoSuchUpload") { - return nil, err - } - for _, m := range multis { - if m.Key == key { - return m, nil - } - } - return b.InitMulti(key, contType, perm, options) -} - -// InitMulti initializes a new multipart upload at the provided -// key inside b and returns a value for manipulating it. -// -// -// You can read doc at http://docs.aliyun.com/#/pub/oss/api-reference/multipart-upload&InitiateMultipartUpload -func (b *Bucket) InitMulti(key string, contType string, perm ACL, options Options) (*Multi, error) { - headers := make(http.Header) - headers.Set("Content-Length", "0") - headers.Set("Content-Type", contType) - headers.Set("x-oss-acl", string(perm)) - - options.addHeaders(headers) - params := make(url.Values) - params.Set("uploads", "") - req := &request{ - method: "POST", - bucket: b.Name, - path: key, - headers: headers, - params: params, - } - var err error - var resp struct { - UploadId string `xml:"UploadId"` - } - for attempt := attempts.Start(); attempt.Next(); { - err = b.Client.query(req, &resp) - if !shouldRetry(err) { - break - } - } - if err != nil { - return nil, err - } - return &Multi{Bucket: b, Key: key, UploadId: resp.UploadId}, nil -} - -func (m *Multi) PutPartCopy(n int, options CopyOptions, source string) (*CopyObjectResult, Part, error) { - return m.PutPartCopyWithContentLength(n, options, source, -1) -} - -// -// You can read doc at http://docs.aliyun.com/#/pub/oss/api-reference/multipart-upload&UploadPartCopy -func (m *Multi) PutPartCopyWithContentLength(n int, options CopyOptions, source string, contentLength int64) (*CopyObjectResult, Part, error) { - // TODO source format a /BUCKET/PATH/TO/OBJECT - // TODO not a good design. API could be changed to PutPartCopyWithinBucket(..., path) and PutPartCopyFromBucket(bucket, path) - - headers := make(http.Header) - headers.Set("x-oss-copy-source", source) - - options.addHeaders(headers) - params := make(url.Values) - params.Set("uploadId", m.UploadId) - params.Set("partNumber", strconv.FormatInt(int64(n), 10)) - - if contentLength < 0 { - sourceBucket := m.Bucket.Client.Bucket(strings.TrimRight(strings.Split(source, "/")[1], "/")) - //log.Println("source: ", source) - //log.Println("sourceBucket: ", sourceBucket.Name) - //log.Println("HEAD: ", strings.strings.SplitAfterN(source, "/", 3)[2]) - // TODO SplitAfterN can be use in bucket name - sourceMeta, err := sourceBucket.Head(strings.SplitAfterN(source, "/", 3)[2], nil) - if err != nil { - return nil, Part{}, err - } - contentLength = sourceMeta.ContentLength - } - - for attempt := attempts.Start(); attempt.Next(); { - req := &request{ - method: "PUT", - bucket: m.Bucket.Name, - path: m.Key, - headers: headers, - params: params, - } - resp := &CopyObjectResult{} - err := m.Bucket.Client.query(req, resp) - if shouldRetry(err) && attempt.HasNext() { - continue - } - if err != nil { - return nil, Part{}, err - } - if resp.ETag == "" { - return nil, Part{}, errors.New("part upload succeeded with no ETag") - } - return resp, Part{n, resp.ETag, contentLength}, nil - } - panic("unreachable") -} - -// PutPart sends part n of the multipart upload, reading all the content from r. -// Each part, except for the last one, must be at least 5MB in size. -// -// -// You can read doc at http://docs.aliyun.com/#/pub/oss/api-reference/multipart-upload&UploadPart -func (m *Multi) PutPart(n int, r io.ReadSeeker) (Part, error) { - partSize, _, md5b64, err := seekerInfo(r) - if err != nil { - return Part{}, err - } - return m.putPart(n, r, partSize, md5b64, 0) -} - -func (m *Multi) PutPartWithTimeout(n int, r io.ReadSeeker, timeout time.Duration) (Part, error) { - partSize, _, md5b64, err := seekerInfo(r) - if err != nil { - return Part{}, err - } - return m.putPart(n, r, partSize, md5b64, timeout) -} - -func (m *Multi) putPart(n int, r io.ReadSeeker, partSize int64, md5b64 string, timeout time.Duration) (Part, error) { - headers := make(http.Header) - headers.Set("Content-Length", strconv.FormatInt(partSize, 10)) - headers.Set("Content-MD5", md5b64) - - params := make(url.Values) - params.Set("uploadId", m.UploadId) - params.Set("partNumber", strconv.FormatInt(int64(n), 10)) - - for attempt := attempts.Start(); attempt.Next(); { - _, err := r.Seek(0, 0) - if err != nil { - return Part{}, err - } - req := &request{ - method: "PUT", - bucket: m.Bucket.Name, - path: m.Key, - headers: headers, - params: params, - payload: r, - timeout: timeout, - } - err = m.Bucket.Client.prepare(req) - if err != nil { - return Part{}, err - } - resp, err := m.Bucket.Client.run(req, nil) - if shouldRetry(err) && attempt.HasNext() { - continue - } - if err != nil { - return Part{}, err - } - etag := resp.Header.Get("ETag") - if etag == "" { - return Part{}, errors.New("part upload succeeded with no ETag") - } - return Part{n, etag, partSize}, nil - } - panic("unreachable") -} - -func seekerInfo(r io.ReadSeeker) (size int64, md5hex string, md5b64 string, err error) { - _, err = r.Seek(0, 0) - if err != nil { - return 0, "", "", err - } - digest := md5.New() - size, err = io.Copy(digest, r) - if err != nil { - return 0, "", "", err - } - sum := digest.Sum(nil) - md5hex = hex.EncodeToString(sum) - md5b64 = base64.StdEncoding.EncodeToString(sum) - return size, md5hex, md5b64, nil -} - -type Part struct { - N int `xml:"PartNumber"` - ETag string - Size int64 -} - -type partSlice []Part - -func (s partSlice) Len() int { return len(s) } -func (s partSlice) Less(i, j int) bool { return s[i].N < s[j].N } -func (s partSlice) Swap(i, j int) { s[i], s[j] = s[j], s[i] } - -type listPartsResp struct { - NextPartNumberMarker string - IsTruncated bool - Part []Part -} - -// That's the default. Here just for testing. -var listPartsMax = 1000 - -// ListParts for backcompatability. See the documentation for ListPartsFull -func (m *Multi) ListParts() ([]Part, error) { - return m.ListPartsFull(0, listPartsMax) -} - -// ListPartsFull returns the list of previously uploaded parts in m, -// ordered by part number (Only parts with higher part numbers than -// partNumberMarker will be listed). Only up to maxParts parts will be -// returned. -// -func (m *Multi) ListPartsFull(partNumberMarker int, maxParts int) ([]Part, error) { - if maxParts > listPartsMax { - maxParts = listPartsMax - } - - params := make(url.Values) - params.Set("uploadId", m.UploadId) - params.Set("max-parts", strconv.FormatInt(int64(maxParts), 10)) - params.Set("part-number-marker", strconv.FormatInt(int64(partNumberMarker), 10)) - - var parts partSlice - for attempt := attempts.Start(); attempt.Next(); { - req := &request{ - method: "GET", - bucket: m.Bucket.Name, - path: m.Key, - params: params, - } - var resp listPartsResp - err := m.Bucket.Client.query(req, &resp) - if shouldRetry(err) && attempt.HasNext() { - continue - } - if err != nil { - return nil, err - } - parts = append(parts, resp.Part...) - if !resp.IsTruncated { - sort.Sort(parts) - return parts, nil - } - params.Set("part-number-marker", resp.NextPartNumberMarker) - attempt = attempts.Start() // Last request worked. - } - panic("unreachable") -} - -type ReaderAtSeeker interface { - io.ReaderAt - io.ReadSeeker -} - -// PutAll sends all of r via a multipart upload with parts no larger -// than partSize bytes, which must be set to at least 5MB. -// Parts previously uploaded are either reused if their checksum -// and size match the new part, or otherwise overwritten with the -// new content. -// PutAll returns all the parts of m (reused or not). -func (m *Multi) PutAll(r ReaderAtSeeker, partSize int64) ([]Part, error) { - old, err := m.ListParts() - if err != nil && !hasCode(err, "NoSuchUpload") { - return nil, err - } - reuse := 0 // Index of next old part to consider reusing. - current := 1 // Part number of latest good part handled. - totalSize, err := r.Seek(0, 2) - if err != nil { - return nil, err - } - first := true // Must send at least one empty part if the file is empty. - var result []Part -NextSection: - for offset := int64(0); offset < totalSize || first; offset += partSize { - first = false - if offset+partSize > totalSize { - partSize = totalSize - offset - } - section := io.NewSectionReader(r, offset, partSize) - _, md5hex, md5b64, err := seekerInfo(section) - if err != nil { - return nil, err - } - for reuse < len(old) && old[reuse].N <= current { - // Looks like this part was already sent. - part := &old[reuse] - etag := `"` + md5hex + `"` - if part.N == current && part.Size == partSize && part.ETag == etag { - // Checksum matches. Reuse the old part. - result = append(result, *part) - current++ - continue NextSection - } - reuse++ - } - - // Part wasn't found or doesn't match. Send it. - part, err := m.putPart(current, section, partSize, md5b64, 0) - if err != nil { - return nil, err - } - result = append(result, part) - current++ - } - return result, nil -} - -type completeUpload struct { - XMLName xml.Name `xml:"CompleteMultipartUpload"` - Parts completeParts `xml:"Part"` -} - -type completePart struct { - PartNumber int - ETag string -} - -type completeParts []completePart - -func (p completeParts) Len() int { return len(p) } -func (p completeParts) Less(i, j int) bool { return p[i].PartNumber < p[j].PartNumber } -func (p completeParts) Swap(i, j int) { p[i], p[j] = p[j], p[i] } - -// Complete assembles the given previously uploaded parts into the -// final object. This operation may take several minutes. -// -func (m *Multi) Complete(parts []Part) error { - params := make(url.Values) - params.Set("uploadId", m.UploadId) - - c := completeUpload{} - for _, p := range parts { - c.Parts = append(c.Parts, completePart{p.N, p.ETag}) - } - sort.Sort(c.Parts) - data, err := xml.Marshal(&c) - if err != nil { - return err - } - for attempt := attempts.Start(); attempt.Next(); { - req := &request{ - method: "POST", - bucket: m.Bucket.Name, - path: m.Key, - params: params, - payload: bytes.NewReader(data), - } - err := m.Bucket.Client.query(req, nil) - if shouldRetry(err) && attempt.HasNext() { - continue - } - return err - } - panic("unreachable") -} - -// Abort deletes an unifinished multipart upload and any previously -// uploaded parts for it. -// -// After a multipart upload is aborted, no additional parts can be -// uploaded using it. However, if any part uploads are currently in -// progress, those part uploads might or might not succeed. As a result, -// it might be necessary to abort a given multipart upload multiple -// times in order to completely free all storage consumed by all parts. -// -// NOTE: If the described scenario happens to you, please report back to -// the goamz authors with details. In the future such retrying should be -// handled internally, but it's not clear what happens precisely (Is an -// error returned? Is the issue completely undetectable?). -// -// -// You can read doc at http://docs.aliyun.com/#/pub/oss/api-reference/multipart-upload&AbortMultipartUpload -func (m *Multi) Abort() error { - params := make(url.Values) - params.Set("uploadId", m.UploadId) - - for attempt := attempts.Start(); attempt.Next(); { - req := &request{ - method: "DELETE", - bucket: m.Bucket.Name, - path: m.Key, - params: params, - } - err := m.Bucket.Client.query(req, nil) - if shouldRetry(err) && attempt.HasNext() { - continue - } - return err - } - panic("unreachable") -} diff --git a/vendor/github.com/denverdino/aliyungo/oss/regions.go b/vendor/github.com/denverdino/aliyungo/oss/regions.go deleted file mode 100644 index 89bac838..00000000 --- a/vendor/github.com/denverdino/aliyungo/oss/regions.go +++ /dev/null @@ -1,80 +0,0 @@ -package oss - -import ( - "fmt" -) - -// Region represents OSS region -type Region string - -// Constants of region definition -const ( - Hangzhou = Region("oss-cn-hangzhou") - Qingdao = Region("oss-cn-qingdao") - Beijing = Region("oss-cn-beijing") - Hongkong = Region("oss-cn-hongkong") - Shenzhen = Region("oss-cn-shenzhen") - Shanghai = Region("oss-cn-shanghai") - Zhangjiakou = Region("oss-cn-zhangjiakou") - Huhehaote = Region("oss-cn-huhehaote") - - USWest1 = Region("oss-us-west-1") - USEast1 = Region("oss-us-east-1") - APSouthEast1 = Region("oss-ap-southeast-1") - APNorthEast1 = Region("oss-ap-northeast-1") - APSouthEast2 = Region("oss-ap-southeast-2") - - MEEast1 = Region("oss-me-east-1") - - EUCentral1 = Region("oss-eu-central-1") - EUWest1 = Region("oss-eu-west-1") - - DefaultRegion = Hangzhou -) - -// GetEndpoint returns endpoint of region -func (r Region) GetEndpoint(internal bool, bucket string, secure bool) string { - if internal { - return r.GetInternalEndpoint(bucket, secure) - } - return r.GetInternetEndpoint(bucket, secure) -} - -func getProtocol(secure bool) string { - protocol := "http" - if secure { - protocol = "https" - } - return protocol -} - -// GetInternetEndpoint returns internet endpoint of region -func (r Region) GetInternetEndpoint(bucket string, secure bool) string { - protocol := getProtocol(secure) - if bucket == "" { - return fmt.Sprintf("%s://oss.aliyuncs.com", protocol) - } - return fmt.Sprintf("%s://%s.%s.aliyuncs.com", protocol, bucket, string(r)) -} - -// GetInternalEndpoint returns internal endpoint of region -func (r Region) GetInternalEndpoint(bucket string, secure bool) string { - protocol := getProtocol(secure) - if bucket == "" { - return fmt.Sprintf("%s://oss-internal.aliyuncs.com", protocol) - } - return fmt.Sprintf("%s://%s.%s-internal.aliyuncs.com", protocol, bucket, string(r)) -} - -// GetInternalEndpoint returns internal endpoint of region -func (r Region) GetVPCInternalEndpoint(bucket string, secure bool) string { - protocol := getProtocol(secure) - if bucket == "" { - return fmt.Sprintf("%s://vpc100-oss-cn-hangzhou.aliyuncs.com", protocol) - } - if r == USEast1 { - return r.GetInternalEndpoint(bucket, secure) - } else { - return fmt.Sprintf("%s://%s.vpc100-%s.aliyuncs.com", protocol, bucket, string(r)) - } -} diff --git a/vendor/github.com/denverdino/aliyungo/oss/signature.go b/vendor/github.com/denverdino/aliyungo/oss/signature.go deleted file mode 100644 index 4a0f4d97..00000000 --- a/vendor/github.com/denverdino/aliyungo/oss/signature.go +++ /dev/null @@ -1,125 +0,0 @@ -package oss - -import ( - "github.com/denverdino/aliyungo/util" - //"log" - "net/http" - "net/url" - "sort" - "strings" -) - -const HeaderOSSPrefix = "x-oss-" - -var ossParamsToSign = map[string]bool{ - "acl": true, - "append": true, - "bucketInfo": true, - "cname": true, - "comp": true, - "cors": true, - "delete": true, - "endTime": true, - "img": true, - "lifecycle": true, - "live": true, - "location": true, - "logging": true, - "objectMeta": true, - "partNumber": true, - "position": true, - "qos": true, - "referer": true, - "replication": true, - "replicationLocation": true, - "replicationProgress": true, - "response-cache-control": true, - "response-content-disposition": true, - "response-content-encoding": true, - "response-content-language": true, - "response-content-type": true, - "response-expires": true, - "security-token": true, - "startTime": true, - "status": true, - "style": true, - "styleName": true, - "symlink": true, - "tagging": true, - "uploadId": true, - "uploads": true, - "vod": true, - "website": true, - "x-oss-process": true, -} - -func (client *Client) signRequest(request *request) { - query := request.params - - urlSignature := query.Get("OSSAccessKeyId") != "" - - headers := request.headers - contentMd5 := headers.Get("Content-Md5") - contentType := headers.Get("Content-Type") - date := "" - if urlSignature { - date = query.Get("Expires") - } else { - date = headers.Get("Date") - } - - resource := request.path - if request.bucket != "" { - resource = "/" + request.bucket + request.path - } - params := make(url.Values) - for k, v := range query { - if ossParamsToSign[k] { - params[k] = v - } - } - - if len(params) > 0 { - resource = resource + "?" + util.EncodeWithoutEscape(params) - } - - canonicalizedResource := resource - - _, canonicalizedHeader := canonicalizeHeader(headers) - - stringToSign := request.method + "\n" + contentMd5 + "\n" + contentType + "\n" + date + "\n" + canonicalizedHeader + canonicalizedResource - - //log.Println("stringToSign: ", stringToSign) - signature := util.CreateSignature(stringToSign, client.AccessKeySecret) - - if urlSignature { - query.Set("Signature", signature) - } else { - headers.Set("Authorization", "OSS "+client.AccessKeyId+":"+signature) - } -} - -//Have to break the abstraction to append keys with lower case. -func canonicalizeHeader(headers http.Header) (newHeaders http.Header, result string) { - var canonicalizedHeaders []string - newHeaders = http.Header{} - - for k, v := range headers { - if lower := strings.ToLower(k); strings.HasPrefix(lower, HeaderOSSPrefix) { - newHeaders[lower] = v - canonicalizedHeaders = append(canonicalizedHeaders, lower) - } else { - newHeaders[k] = v - } - } - - sort.Strings(canonicalizedHeaders) - - var canonicalizedHeader string - - for _, k := range canonicalizedHeaders { - canonicalizedHeader += k + ":" + headers.Get(k) + "\n" - } - - return newHeaders, canonicalizedHeader -} diff --git a/vendor/github.com/denverdino/aliyungo/util/attempt.go b/vendor/github.com/denverdino/aliyungo/util/attempt.go deleted file mode 100644 index 2d07f03a..00000000 --- a/vendor/github.com/denverdino/aliyungo/util/attempt.go +++ /dev/null @@ -1,76 +0,0 @@ -package util - -import ( - "time" -) - -// AttemptStrategy is reused from the goamz package - -// AttemptStrategy represents a strategy for waiting for an action -// to complete successfully. This is an internal type used by the -// implementation of other packages. -type AttemptStrategy struct { - Total time.Duration // total duration of attempt. - Delay time.Duration // interval between each try in the burst. - Min int // minimum number of retries; overrides Total -} - -type Attempt struct { - strategy AttemptStrategy - last time.Time - end time.Time - force bool - count int -} - -// Start begins a new sequence of attempts for the given strategy. -func (s AttemptStrategy) Start() *Attempt { - now := time.Now() - return &Attempt{ - strategy: s, - last: now, - end: now.Add(s.Total), - force: true, - } -} - -// Next waits until it is time to perform the next attempt or returns -// false if it is time to stop trying. -func (a *Attempt) Next() bool { - now := time.Now() - sleep := a.nextSleep(now) - if !a.force && !now.Add(sleep).Before(a.end) && a.strategy.Min <= a.count { - return false - } - a.force = false - if sleep > 0 && a.count > 0 { - time.Sleep(sleep) - now = time.Now() - } - a.count++ - a.last = now - return true -} - -func (a *Attempt) nextSleep(now time.Time) time.Duration { - sleep := a.strategy.Delay - now.Sub(a.last) - if sleep < 0 { - return 0 - } - return sleep -} - -// HasNext returns whether another attempt will be made if the current -// one fails. If it returns true, the following call to Next is -// guaranteed to return true. -func (a *Attempt) HasNext() bool { - if a.force || a.strategy.Min > a.count { - return true - } - now := time.Now() - if now.Add(a.nextSleep(now)).Before(a.end) { - a.force = true - return true - } - return false -} diff --git a/vendor/github.com/denverdino/aliyungo/util/encoding.go b/vendor/github.com/denverdino/aliyungo/util/encoding.go deleted file mode 100644 index ec1a5b13..00000000 --- a/vendor/github.com/denverdino/aliyungo/util/encoding.go +++ /dev/null @@ -1,331 +0,0 @@ -package util - -import ( - "encoding/json" - "fmt" - "log" - "net/url" - "reflect" - "strconv" - "strings" - "time" -) - -// change instance=["a", "b"] -// to instance.1="a" instance.2="b" -func FlattenFn(fieldName string, field reflect.Value, values *url.Values) { - l := field.Len() - if l > 0 { - for i := 0; i < l; i++ { - str := field.Index(i).String() - values.Set(fieldName+"."+strconv.Itoa(i+1), str) - } - } -} - -func Underline2Dot(name string) string { - return strings.Replace(name, "_", ".", -1) -} - -//ConvertToQueryValues converts the struct to url.Values -func ConvertToQueryValues(ifc interface{}) url.Values { - values := url.Values{} - SetQueryValues(ifc, &values) - return values -} - -//SetQueryValues sets the struct to existing url.Values following ECS encoding rules -func SetQueryValues(ifc interface{}, values *url.Values) { - setQueryValues(ifc, values, "") -} - -func SetQueryValueByFlattenMethod(ifc interface{}, values *url.Values) { - setQueryValuesByFlattenMethod(ifc, values, "") -} - -func setQueryValues(i interface{}, values *url.Values, prefix string) { - // add to support url.Values - mapValues, ok := i.(url.Values) - if ok { - for k, _ := range mapValues { - values.Set(k, mapValues.Get(k)) - } - return - } - - elem := reflect.ValueOf(i) - if elem.Kind() == reflect.Ptr { - elem = elem.Elem() - } - elemType := elem.Type() - for i := 0; i < elem.NumField(); i++ { - - fieldName := elemType.Field(i).Name - anonymous := elemType.Field(i).Anonymous - tag := elemType.Field(i).Tag.Get("query") - argName := elemType.Field(i).Tag.Get("ArgName") - field := elem.Field(i) - // TODO Use Tag for validation - // tag := typ.Field(i).Tag.Get("tagname") - kind := field.Kind() - isPtr := false - if (kind == reflect.Ptr || kind == reflect.Array || kind == reflect.Slice || kind == reflect.Map || kind == reflect.Chan) && field.IsNil() { - continue - } - if kind == reflect.Ptr { - field = field.Elem() - kind = field.Kind() - isPtr = true - } - var value string - //switch field.Interface().(type) { - switch kind { - case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: - i := field.Int() - if i != 0 || isPtr { - value = strconv.FormatInt(i, 10) - } - case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64: - i := field.Uint() - if i != 0 || isPtr { - value = strconv.FormatUint(i, 10) - } - case reflect.Float32: - value = strconv.FormatFloat(field.Float(), 'f', 4, 32) - case reflect.Float64: - value = strconv.FormatFloat(field.Float(), 'f', 4, 64) - case reflect.Bool: - value = strconv.FormatBool(field.Bool()) - case reflect.String: - value = field.String() - case reflect.Map: - ifc := field.Interface() - m := ifc.(map[string]string) - if m != nil { - j := 0 - for k, v := range m { - j++ - keyName := fmt.Sprintf("%s.%d.Key", fieldName, j) - values.Set(keyName, k) - valueName := fmt.Sprintf("%s.%d.Value", fieldName, j) - values.Set(valueName, v) - } - } - case reflect.Slice: - switch field.Type().Elem().Kind() { - case reflect.Uint8: - value = string(field.Bytes()) - case reflect.String: - l := field.Len() - if l > 0 { - if tag == "list" { - name := argName - if argName == "" { - name = fieldName - } - for i := 0; i < l; i++ { - valueName := fmt.Sprintf("%s.%d", name, (i + 1)) - values.Set(valueName, field.Index(i).String()) - } - } else { - strArray := make([]string, l) - for i := 0; i < l; i++ { - strArray[i] = field.Index(i).String() - } - bytes, err := json.Marshal(strArray) - if err == nil { - value = string(bytes) - } else { - log.Printf("Failed to convert JSON: %v", err) - } - } - } - default: - l := field.Len() - for j := 0; j < l; j++ { - prefixName := fmt.Sprintf("%s.%d.", fieldName, (j + 1)) - ifc := field.Index(j).Interface() - //log.Printf("%s : %v", prefixName, ifc) - if ifc != nil { - setQueryValues(ifc, values, prefixName) - } - } - continue - } - - default: - switch field.Interface().(type) { - case ISO6801Time: - t := field.Interface().(ISO6801Time) - value = t.String() - case time.Time: - t := field.Interface().(time.Time) - value = GetISO8601TimeStamp(t) - default: - ifc := field.Interface() - if ifc != nil { - if anonymous { - SetQueryValues(ifc, values) - } else { - prefixName := fieldName + "." - setQueryValues(ifc, values, prefixName) - } - continue - } - } - } - if value != "" { - name := argName - if argName == "" { - name = fieldName - } - if prefix != "" { - name = prefix + name - } - values.Set(name, value) - } - } -} - -func setQueryValuesByFlattenMethod(i interface{}, values *url.Values, prefix string) { - // add to support url.Values - mapValues, ok := i.(url.Values) - if ok { - for k, _ := range mapValues { - values.Set(k, mapValues.Get(k)) - } - return - } - - elem := reflect.ValueOf(i) - if elem.Kind() == reflect.Ptr { - elem = elem.Elem() - } - elemType := elem.Type() - for i := 0; i < elem.NumField(); i++ { - - fieldName := elemType.Field(i).Name - anonymous := elemType.Field(i).Anonymous - field := elem.Field(i) - - // TODO Use Tag for validation - // tag := typ.Field(i).Tag.Get("tagname") - kind := field.Kind() - - isPtr := false - if (kind == reflect.Ptr || kind == reflect.Array || kind == reflect.Slice || kind == reflect.Map || kind == reflect.Chan) && field.IsNil() { - continue - } - if kind == reflect.Ptr { - field = field.Elem() - kind = field.Kind() - isPtr = true - } - - var value string - //switch field.Interface().(type) { - switch kind { - case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: - i := field.Int() - if i != 0 || isPtr { - value = strconv.FormatInt(i, 10) - } - case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64: - i := field.Uint() - if i != 0 || isPtr { - value = strconv.FormatUint(i, 10) - } - case reflect.Float32: - value = strconv.FormatFloat(field.Float(), 'f', 4, 32) - case reflect.Float64: - value = strconv.FormatFloat(field.Float(), 'f', 4, 64) - case reflect.Bool: - value = strconv.FormatBool(field.Bool()) - case reflect.String: - value = field.String() - case reflect.Map: - ifc := field.Interface() - m := ifc.(map[string]string) - if m != nil { - j := 0 - for k, v := range m { - j++ - keyName := fmt.Sprintf("%s.%d.Key", fieldName, j) - values.Set(keyName, k) - valueName := fmt.Sprintf("%s.%d.Value", fieldName, j) - values.Set(valueName, v) - } - } - case reflect.Slice: - if field.Type().Name() == "FlattenArray" { - FlattenFn(fieldName, field, values) - } else { - switch field.Type().Elem().Kind() { - case reflect.Uint8: - value = string(field.Bytes()) - case reflect.String: - l := field.Len() - if l > 0 { - strArray := make([]string, l) - for i := 0; i < l; i++ { - strArray[i] = field.Index(i).String() - } - bytes, err := json.Marshal(strArray) - if err == nil { - value = string(bytes) - } else { - log.Printf("Failed to convert JSON: %v", err) - } - } - default: - l := field.Len() - for j := 0; j < l; j++ { - prefixName := fmt.Sprintf("%s.%d.", fieldName, (j + 1)) - ifc := field.Index(j).Interface() - //log.Printf("%s : %v", prefixName, ifc) - if ifc != nil { - setQueryValuesByFlattenMethod(ifc, values, prefixName) - } - } - continue - } - } - - default: - switch field.Interface().(type) { - case ISO6801Time: - t := field.Interface().(ISO6801Time) - value = t.String() - case time.Time: - t := field.Interface().(time.Time) - value = GetISO8601TimeStamp(t) - default: - - ifc := field.Interface() - if ifc != nil { - if anonymous { - SetQueryValues(ifc, values) - } else { - prefixName := fieldName + "." - setQueryValuesByFlattenMethod(ifc, values, prefixName) - } - continue - } - } - } - if value != "" { - name := elemType.Field(i).Tag.Get("ArgName") - if name == "" { - name = fieldName - } - if prefix != "" { - name = prefix + name - } - // NOTE: here we will change name to underline style when the type is UnderlineString - if field.Type().Name() == "UnderlineString" { - name = Underline2Dot(name) - } - values.Set(name, value) - } - } -} diff --git a/vendor/github.com/denverdino/aliyungo/util/iso6801.go b/vendor/github.com/denverdino/aliyungo/util/iso6801.go deleted file mode 100644 index 9c25e8f6..00000000 --- a/vendor/github.com/denverdino/aliyungo/util/iso6801.go +++ /dev/null @@ -1,80 +0,0 @@ -package util - -import ( - "fmt" - "strconv" - "time" -) - -// GetISO8601TimeStamp gets timestamp string in ISO8601 format -func GetISO8601TimeStamp(ts time.Time) string { - t := ts.UTC() - return fmt.Sprintf("%04d-%02d-%02dT%02d:%02d:%02dZ", t.Year(), t.Month(), t.Day(), t.Hour(), t.Minute(), t.Second()) -} - -const formatISO8601 = "2006-01-02T15:04:05Z" -const jsonFormatISO8601 = `"` + formatISO8601 + `"` -const formatISO8601withoutSeconds = "2006-01-02T15:04Z" -const jsonFormatISO8601withoutSeconds = `"` + formatISO8601withoutSeconds + `"` - -// A ISO6801Time represents a time in ISO8601 format -type ISO6801Time time.Time - -// New constructs a new iso8601.Time instance from an existing -// time.Time instance. This causes the nanosecond field to be set to -// 0, and its time zone set to a fixed zone with no offset from UTC -// (but it is *not* UTC itself). -func NewISO6801Time(t time.Time) ISO6801Time { - return ISO6801Time(time.Date( - t.Year(), - t.Month(), - t.Day(), - t.Hour(), - t.Minute(), - t.Second(), - 0, - time.UTC, - )) -} - -// IsDefault checks if the time is default -func (it *ISO6801Time) IsDefault() bool { - return *it == ISO6801Time{} -} - -// MarshalJSON serializes the ISO6801Time into JSON string -func (it ISO6801Time) MarshalJSON() ([]byte, error) { - return []byte(time.Time(it).Format(jsonFormatISO8601)), nil -} - -// UnmarshalJSON deserializes the ISO6801Time from JSON string -func (it *ISO6801Time) UnmarshalJSON(data []byte) error { - str := string(data) - - if str == "\"\"" || len(data) == 0 { - return nil - } - var t time.Time - var err error - if str[0] == '"' { - t, err = time.ParseInLocation(jsonFormatISO8601, str, time.UTC) - if err != nil { - t, err = time.ParseInLocation(jsonFormatISO8601withoutSeconds, str, time.UTC) - } - } else { - var i int64 - i, err = strconv.ParseInt(str, 10, 64) - if err == nil { - t = time.Unix(i/1000, i%1000) - } - } - if err == nil { - *it = ISO6801Time(t) - } - return err -} - -// String returns the time in ISO6801Time format -func (it ISO6801Time) String() string { - return time.Time(it).Format(formatISO8601) -} diff --git a/vendor/github.com/denverdino/aliyungo/util/signature.go b/vendor/github.com/denverdino/aliyungo/util/signature.go deleted file mode 100644 index 1be6d39c..00000000 --- a/vendor/github.com/denverdino/aliyungo/util/signature.go +++ /dev/null @@ -1,39 +0,0 @@ -package util - -import ( - "crypto/hmac" - "crypto/sha1" - "encoding/base64" - "net/url" - "strings" -) - -//CreateSignature creates signature for string following Aliyun rules -func CreateSignature(stringToSignature, accessKeySecret string) string { - // Crypto by HMAC-SHA1 - hmacSha1 := hmac.New(sha1.New, []byte(accessKeySecret)) - hmacSha1.Write([]byte(stringToSignature)) - sign := hmacSha1.Sum(nil) - - // Encode to Base64 - base64Sign := base64.StdEncoding.EncodeToString(sign) - - return base64Sign -} - -func percentReplace(str string) string { - str = strings.Replace(str, "+", "%20", -1) - str = strings.Replace(str, "*", "%2A", -1) - str = strings.Replace(str, "%7E", "~", -1) - - return str -} - -// CreateSignatureForRequest creates signature for query string values -func CreateSignatureForRequest(method string, values *url.Values, accessKeySecret string) string { - - canonicalizedQueryString := percentReplace(values.Encode()) - - stringToSign := method + "&%2F&" + url.QueryEscape(canonicalizedQueryString) - return CreateSignature(stringToSign, accessKeySecret) -} diff --git a/vendor/github.com/denverdino/aliyungo/util/util.go b/vendor/github.com/denverdino/aliyungo/util/util.go deleted file mode 100644 index 15a990da..00000000 --- a/vendor/github.com/denverdino/aliyungo/util/util.go +++ /dev/null @@ -1,185 +0,0 @@ -package util - -import ( - "bytes" - srand "crypto/rand" - "encoding/binary" - "encoding/json" - "fmt" - "math/rand" - "net/http" - "net/url" - "sort" - "time" -) - -const dictionary = "_0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" - -//CreateRandomString create random string -func CreateRandomString() string { - b := make([]byte, 32) - l := len(dictionary) - - _, err := srand.Read(b) - - if err != nil { - // fail back to insecure rand - rand.Seed(time.Now().UnixNano()) - for i := range b { - b[i] = dictionary[rand.Int()%l] - } - } else { - for i, v := range b { - b[i] = dictionary[v%byte(l)] - } - } - - return string(b) -} - -// Encode encodes the values into ``URL encoded'' form -// ("acl&bar=baz&foo=quux") sorted by key. -func Encode(v url.Values) string { - if v == nil { - return "" - } - var buf bytes.Buffer - keys := make([]string, 0, len(v)) - for k := range v { - keys = append(keys, k) - } - sort.Strings(keys) - for _, k := range keys { - vs := v[k] - prefix := url.QueryEscape(k) - for _, v := range vs { - if buf.Len() > 0 { - buf.WriteByte('&') - } - buf.WriteString(prefix) - if v != "" { - buf.WriteString("=") - buf.WriteString(url.QueryEscape(v)) - } - } - } - return buf.String() -} - -// Like Encode, but key and value are not escaped -func EncodeWithoutEscape(v url.Values) string { - if v == nil { - return "" - } - var buf bytes.Buffer - keys := make([]string, 0, len(v)) - for k := range v { - keys = append(keys, k) - } - sort.Strings(keys) - for _, k := range keys { - vs := v[k] - prefix := k - for _, v := range vs { - if buf.Len() > 0 { - buf.WriteByte('&') - } - buf.WriteString(prefix) - if v != "" { - buf.WriteString("=") - buf.WriteString(v) - } - } - } - return buf.String() -} - -func GetGMTime() string { - return time.Now().UTC().Format(http.TimeFormat) -} - -// - -func randUint32() uint32 { - return randUint32Slice(1)[0] -} - -func randUint32Slice(c int) []uint32 { - b := make([]byte, c*4) - - _, err := srand.Read(b) - - if err != nil { - // fail back to insecure rand - rand.Seed(time.Now().UnixNano()) - for i := range b { - b[i] = byte(rand.Int()) - } - } - - n := make([]uint32, c) - - for i := range n { - n[i] = binary.BigEndian.Uint32(b[i*4 : i*4+4]) - } - - return n -} - -func toByte(n uint32, st, ed byte) byte { - return byte(n%uint32(ed-st+1) + uint32(st)) -} - -func toDigit(n uint32) byte { - return toByte(n, '0', '9') -} - -func toLowerLetter(n uint32) byte { - return toByte(n, 'a', 'z') -} - -func toUpperLetter(n uint32) byte { - return toByte(n, 'A', 'Z') -} - -type convFunc func(uint32) byte - -var convFuncs = []convFunc{toDigit, toLowerLetter, toUpperLetter} - -// tools for generating a random ECS instance password -// from 8 to 30 char MUST contain digit upper, case letter and upper case letter -// http://docs.aliyun.com/#/pub/ecs/open-api/instance&createinstance -func GenerateRandomECSPassword() string { - - // [8, 30] - l := int(randUint32()%23 + 8) - - n := randUint32Slice(l) - - b := make([]byte, l) - - b[0] = toDigit(n[0]) - b[1] = toLowerLetter(n[1]) - b[2] = toUpperLetter(n[2]) - - for i := 3; i < l; i++ { - b[i] = convFuncs[n[i]%3](n[i]) - } - - s := make([]byte, l) - perm := rand.Perm(l) - for i, v := range perm { - s[v] = b[i] - } - - return string(s) - -} - -func PrettyJson(object interface{}) string { - b, err := json.MarshalIndent(object, "", " ") - if err != nil { - fmt.Printf("ERROR: PrettyJson, %v\n %s\n", err, b) - } - return string(b) -} diff --git a/vendor/modules.txt b/vendor/modules.txt index c577f969..86a9adfd 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -170,12 +170,6 @@ github.com/cespare/xxhash/v2 # github.com/cyphar/filepath-securejoin v0.2.3 ## explicit; go 1.13 github.com/cyphar/filepath-securejoin -# github.com/denverdino/aliyungo v0.0.0-20190125010748-a747050bb1ba -## explicit -github.com/denverdino/aliyungo/cdn/auth -github.com/denverdino/aliyungo/common -github.com/denverdino/aliyungo/oss -github.com/denverdino/aliyungo/util # github.com/docker/go-events v0.0.0-20190806004212-e31b211e4f1c ## explicit github.com/docker/go-events