2017-03-16 15:21:58 -04:00
|
|
|
/*
|
2020-03-22 01:10:13 -04:00
|
|
|
* MinIO Cloud Storage, (C) 2017-2020 MinIO, Inc.
|
2017-03-16 15:21:58 -04:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2017-12-05 20:58:09 -05:00
|
|
|
package azure
|
2017-03-16 15:21:58 -04:00
|
|
|
|
|
|
|
import (
|
2017-09-19 19:08:08 -04:00
|
|
|
"bytes"
|
2018-03-14 15:01:47 -04:00
|
|
|
"context"
|
2018-03-29 12:54:47 -04:00
|
|
|
"crypto/rand"
|
2017-03-16 15:21:58 -04:00
|
|
|
"encoding/base64"
|
2017-09-19 19:08:08 -04:00
|
|
|
"encoding/hex"
|
|
|
|
"encoding/json"
|
2020-06-01 21:23:48 -04:00
|
|
|
"errors"
|
2017-03-16 15:21:58 -04:00
|
|
|
"fmt"
|
|
|
|
"io"
|
2019-12-02 12:32:19 -05:00
|
|
|
"io/ioutil"
|
2017-03-16 15:21:58 -04:00
|
|
|
"net/http"
|
2019-12-02 12:32:19 -05:00
|
|
|
"net/url"
|
2019-02-06 19:58:43 -05:00
|
|
|
"path"
|
2017-11-20 17:03:20 -05:00
|
|
|
"sort"
|
2017-09-19 19:08:08 -04:00
|
|
|
"strconv"
|
2017-03-16 15:21:58 -04:00
|
|
|
"strings"
|
|
|
|
"time"
|
|
|
|
|
2020-05-08 14:30:35 -04:00
|
|
|
"github.com/minio/minio/pkg/env"
|
|
|
|
|
2019-12-02 12:32:19 -05:00
|
|
|
"github.com/Azure/azure-pipeline-go/pipeline"
|
|
|
|
"github.com/Azure/azure-storage-blob-go/azblob"
|
2017-09-05 19:56:23 -04:00
|
|
|
humanize "github.com/dustin/go-humanize"
|
2017-10-27 18:07:46 -04:00
|
|
|
"github.com/minio/cli"
|
2019-05-29 19:35:12 -04:00
|
|
|
miniogopolicy "github.com/minio/minio-go/v6/pkg/policy"
|
2018-04-05 18:04:40 -04:00
|
|
|
"github.com/minio/minio/cmd/logger"
|
2017-12-05 20:58:09 -05:00
|
|
|
"github.com/minio/minio/pkg/auth"
|
2020-01-27 17:12:34 -05:00
|
|
|
"github.com/minio/minio/pkg/bucket/policy"
|
|
|
|
"github.com/minio/minio/pkg/bucket/policy/condition"
|
2018-01-17 13:54:31 -05:00
|
|
|
sha256 "github.com/minio/sha256-simd"
|
2017-12-05 20:58:09 -05:00
|
|
|
|
|
|
|
minio "github.com/minio/minio/cmd"
|
2017-03-16 15:21:58 -04:00
|
|
|
)
|
|
|
|
|
2020-04-23 05:04:13 -04:00
|
|
|
var (
|
|
|
|
azureUploadChunkSize = getUploadChunkSizeFromEnv(azureChunkSizeEnvVar, strconv.Itoa(azureDefaultUploadChunkSize/humanize.MiByte))
|
|
|
|
azureSdkTimeout = time.Duration(azureUploadChunkSize/humanize.MiByte) * azureSdkTimeoutPerMb
|
|
|
|
azureUploadConcurrency = azureUploadMaxMemoryUsage / azureUploadChunkSize
|
|
|
|
)
|
|
|
|
|
2017-10-27 18:07:46 -04:00
|
|
|
const (
|
2019-12-02 12:32:19 -05:00
|
|
|
// The defaultDialTimeout for communicating with the cloud backends is set
|
|
|
|
// to 30 seconds in utils.go; the Azure SDK recommends to set a timeout of 60
|
|
|
|
// seconds per MB of data a client expects to upload so we must transfer less
|
|
|
|
// than 0.5 MB per chunk to stay within the defaultDialTimeout tolerance.
|
|
|
|
// See https://github.com/Azure/azure-storage-blob-go/blob/fc70003/azblob/zc_policy_retry.go#L39-L44 for more details.
|
2020-04-23 05:04:13 -04:00
|
|
|
// To change the upload chunk size, set the environmental variable MINIO_AZURE_CHUNK_SIZE_MB with a (float) value between 0 and 100
|
|
|
|
azureDefaultUploadChunkSize = 25 * humanize.MiByte
|
|
|
|
azureSdkTimeoutPerMb = 60 * time.Second
|
|
|
|
azureUploadMaxMemoryUsage = 100 * humanize.MiByte
|
|
|
|
azureChunkSizeEnvVar = "MINIO_AZURE_CHUNK_SIZE_MB"
|
2019-12-02 12:32:19 -05:00
|
|
|
|
|
|
|
azureDownloadRetryAttempts = 5
|
2017-10-27 18:07:46 -04:00
|
|
|
azureBlockSize = 100 * humanize.MiByte
|
2017-12-05 20:58:09 -05:00
|
|
|
azureS3MinPartSize = 5 * humanize.MiByte
|
|
|
|
metadataObjectNameTemplate = minio.GatewayMinioSysTmp + "multipart/v1/%s.%x/azure.json"
|
2017-10-27 18:07:46 -04:00
|
|
|
azureBackend = "azure"
|
2018-04-27 19:08:46 -04:00
|
|
|
azureMarkerPrefix = "{minio}"
|
2019-02-06 19:58:43 -05:00
|
|
|
metadataPartNamePrefix = minio.GatewayMinioSysTmp + "multipart/v1/%s.%x"
|
|
|
|
maxPartsCount = 10000
|
2017-10-27 18:07:46 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
const azureGatewayTemplate = `NAME:
|
|
|
|
{{.HelpName}} - {{.Usage}}
|
|
|
|
|
|
|
|
USAGE:
|
|
|
|
{{.HelpName}} {{if .VisibleFlags}}[FLAGS]{{end}} [ENDPOINT]
|
|
|
|
{{if .VisibleFlags}}
|
|
|
|
FLAGS:
|
|
|
|
{{range .VisibleFlags}}{{.}}
|
|
|
|
{{end}}{{end}}
|
|
|
|
ENDPOINT:
|
|
|
|
Azure server endpoint. Default ENDPOINT is https://core.windows.net
|
|
|
|
|
|
|
|
EXAMPLES:
|
2019-12-04 18:32:37 -05:00
|
|
|
1. Start minio gateway server for Azure Blob Storage backend on custom endpoint.
|
2019-05-15 04:32:44 -04:00
|
|
|
{{.Prompt}} {{.EnvVarSetCommand}} MINIO_ACCESS_KEY{{.AssignmentOperator}}azureaccountname
|
|
|
|
{{.Prompt}} {{.EnvVarSetCommand}} MINIO_SECRET_KEY{{.AssignmentOperator}}azureaccountkey
|
2020-04-23 05:04:13 -04:00
|
|
|
{{.Prompt}} {{.EnvVarSetCommand}} MINIO_AZURE_CHUNK_SIZE_MB {{.AssignmentOperator}}0.25
|
2019-05-15 04:32:44 -04:00
|
|
|
{{.Prompt}} {{.HelpName}} https://azureaccountname.blob.custom.azure.endpoint
|
2017-10-27 18:07:46 -04:00
|
|
|
|
2019-12-04 18:32:37 -05:00
|
|
|
2. Start minio gateway server for Azure Blob Storage backend with edge caching enabled.
|
2019-05-15 04:32:44 -04:00
|
|
|
{{.Prompt}} {{.EnvVarSetCommand}} MINIO_ACCESS_KEY{{.AssignmentOperator}}azureaccountname
|
|
|
|
{{.Prompt}} {{.EnvVarSetCommand}} MINIO_SECRET_KEY{{.AssignmentOperator}}azureaccountkey
|
2019-11-20 18:10:24 -05:00
|
|
|
{{.Prompt}} {{.EnvVarSetCommand}} MINIO_CACHE_DRIVES{{.AssignmentOperator}}"/mnt/drive1,/mnt/drive2,/mnt/drive3,/mnt/drive4"
|
|
|
|
{{.Prompt}} {{.EnvVarSetCommand}} MINIO_CACHE_EXCLUDE{{.AssignmentOperator}}"bucket1/*,*.png"
|
2020-02-23 08:33:39 -05:00
|
|
|
{{.Prompt}} {{.EnvVarSetCommand}} MINIO_CACHE_QUOTA{{.AssignmentOperator}}90
|
|
|
|
{{.Prompt}} {{.EnvVarSetCommand}} MINIO_CACHE_AFTER{{.AssignmentOperator}}3
|
|
|
|
{{.Prompt}} {{.EnvVarSetCommand}} MINIO_CACHE_WATERMARK_LOW{{.AssignmentOperator}}75
|
|
|
|
{{.Prompt}} {{.EnvVarSetCommand}} MINIO_CACHE_WATERMARK_HIGH{{.AssignmentOperator}}85
|
2020-04-23 05:04:13 -04:00
|
|
|
{{.Prompt}} {{.EnvVarSetCommand}} MINIO_AZURE_CHUNK_SIZE_MB {{.AssignmentOperator}}25
|
2019-05-15 04:32:44 -04:00
|
|
|
{{.Prompt}} {{.HelpName}}
|
2017-10-27 18:07:46 -04:00
|
|
|
`
|
|
|
|
|
2017-12-05 20:58:09 -05:00
|
|
|
minio.RegisterGatewayCommand(cli.Command{
|
2017-10-27 18:07:46 -04:00
|
|
|
Name: azureBackend,
|
2019-07-13 02:32:27 -04:00
|
|
|
Usage: "Microsoft Azure Blob Storage",
|
2017-10-27 18:07:46 -04:00
|
|
|
Action: azureGatewayMain,
|
|
|
|
CustomHelpTemplate: azureGatewayTemplate,
|
|
|
|
HideHelpCommand: true,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2018-04-27 19:08:46 -04:00
|
|
|
// Returns true if marker was returned by Azure, i.e prefixed with
|
|
|
|
// {minio}
|
|
|
|
func isAzureMarker(marker string) bool {
|
|
|
|
return strings.HasPrefix(marker, azureMarkerPrefix)
|
|
|
|
}
|
|
|
|
|
2017-10-27 18:07:46 -04:00
|
|
|
// Handler for 'minio gateway azure' command line.
|
|
|
|
func azureGatewayMain(ctx *cli.Context) {
|
|
|
|
// Validate gateway arguments.
|
|
|
|
host := ctx.Args().First()
|
2020-05-17 11:46:23 -04:00
|
|
|
|
|
|
|
serverAddr := ctx.GlobalString("address")
|
|
|
|
if serverAddr == "" || serverAddr == ":"+minio.GlobalMinioDefaultPort {
|
|
|
|
serverAddr = ctx.String("address")
|
|
|
|
}
|
2017-10-27 18:07:46 -04:00
|
|
|
// Validate gateway arguments.
|
2020-05-17 11:46:23 -04:00
|
|
|
logger.FatalIf(minio.ValidateGatewayArguments(serverAddr, host), "Invalid argument")
|
2017-10-27 18:07:46 -04:00
|
|
|
|
2017-12-05 20:58:09 -05:00
|
|
|
minio.StartGateway(ctx, &Azure{host})
|
2017-10-27 18:07:46 -04:00
|
|
|
}
|
|
|
|
|
2020-04-23 05:04:13 -04:00
|
|
|
// getUploadChunkSizeFromEnv returns the parsed chunk size from the environmental variable 'MINIO_AZURE_CHUNK_SIZE_MB'
|
|
|
|
// The environmental variable should be a floating point number between 0 and 100 representing the MegaBytes
|
|
|
|
// The returned value is an int representing the size in bytes
|
|
|
|
func getUploadChunkSizeFromEnv(envvar string, defaultValue string) int {
|
|
|
|
envChunkSize := env.Get(envvar, defaultValue)
|
|
|
|
|
|
|
|
i, err := strconv.ParseFloat(envChunkSize, 64)
|
|
|
|
if err != nil {
|
|
|
|
logger.LogIf(context.Background(), err)
|
|
|
|
return azureDefaultUploadChunkSize
|
|
|
|
}
|
|
|
|
|
|
|
|
if i <= 0 || i > 100 {
|
|
|
|
logger.LogIf(context.Background(), fmt.Errorf("ENV '%v' should be a floating point value between 0 and 100.\n"+
|
|
|
|
"The upload chunk size is set to its default: %s\n", azureChunkSizeEnvVar, defaultValue))
|
|
|
|
return azureDefaultUploadChunkSize
|
|
|
|
}
|
|
|
|
|
|
|
|
return int(i * humanize.MiByte)
|
|
|
|
}
|
|
|
|
|
2017-12-05 20:58:09 -05:00
|
|
|
// Azure implements Gateway.
|
|
|
|
type Azure struct {
|
2017-10-27 18:07:46 -04:00
|
|
|
host string
|
|
|
|
}
|
|
|
|
|
|
|
|
// Name implements Gateway interface.
|
2017-12-05 20:58:09 -05:00
|
|
|
func (g *Azure) Name() string {
|
2017-10-27 18:07:46 -04:00
|
|
|
return azureBackend
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewGatewayLayer initializes azure blob storage client and returns AzureObjects.
|
2018-02-09 18:19:30 -05:00
|
|
|
func (g *Azure) NewGatewayLayer(creds auth.Credentials) (minio.ObjectLayer, error) {
|
2019-12-02 12:32:19 -05:00
|
|
|
endpointURL, err := parseStorageEndpoint(g.host, creds.AccessKey)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2017-12-05 20:58:09 -05:00
|
|
|
}
|
|
|
|
|
2019-12-02 12:32:19 -05:00
|
|
|
credential, err := azblob.NewSharedKeyCredential(creds.AccessKey, creds.SecretKey)
|
2017-12-05 20:58:09 -05:00
|
|
|
if err != nil {
|
2020-06-01 21:23:48 -04:00
|
|
|
if _, ok := err.(base64.CorruptInputError); ok {
|
|
|
|
return &azureObjects{}, errors.New("invalid Azure credentials")
|
|
|
|
}
|
2017-12-05 20:58:09 -05:00
|
|
|
return &azureObjects{}, err
|
|
|
|
}
|
2018-11-13 18:51:49 -05:00
|
|
|
|
2020-02-11 10:38:01 -05:00
|
|
|
metrics := minio.NewMetrics()
|
|
|
|
|
|
|
|
t := &minio.MetricsTransport{
|
2020-03-22 01:10:13 -04:00
|
|
|
Transport: minio.NewGatewayHTTPTransport(),
|
2020-02-11 10:38:01 -05:00
|
|
|
Metrics: metrics,
|
|
|
|
}
|
|
|
|
|
|
|
|
httpClient := &http.Client{Transport: t}
|
2019-12-02 12:32:19 -05:00
|
|
|
userAgent := fmt.Sprintf("APN/1.0 MinIO/1.0 MinIO/%s", minio.Version)
|
|
|
|
|
|
|
|
pipeline := azblob.NewPipeline(credential, azblob.PipelineOptions{
|
|
|
|
Retry: azblob.RetryOptions{
|
|
|
|
TryTimeout: azureSdkTimeout,
|
|
|
|
},
|
|
|
|
HTTPSender: pipeline.FactoryFunc(func(next pipeline.Policy, po *pipeline.PolicyOptions) pipeline.PolicyFunc {
|
|
|
|
return func(ctx context.Context, request pipeline.Request) (pipeline.Response, error) {
|
|
|
|
request.Header.Set("User-Agent", userAgent)
|
|
|
|
resp, err := httpClient.Do(request.WithContext(ctx))
|
|
|
|
return pipeline.NewHTTPResponse(resp), err
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
})
|
|
|
|
|
|
|
|
client := azblob.NewServiceURL(*endpointURL, pipeline)
|
2017-12-05 20:58:09 -05:00
|
|
|
|
|
|
|
return &azureObjects{
|
2019-12-02 12:32:19 -05:00
|
|
|
endpoint: endpointURL.String(),
|
|
|
|
httpClient: httpClient,
|
|
|
|
client: client,
|
2020-02-11 10:38:01 -05:00
|
|
|
metrics: metrics,
|
2017-12-05 20:58:09 -05:00
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2019-12-02 12:32:19 -05:00
|
|
|
func parseStorageEndpoint(host string, accountName string) (*url.URL, error) {
|
|
|
|
var endpoint string
|
|
|
|
|
|
|
|
// Load the endpoint url if supplied by the user.
|
|
|
|
if host != "" {
|
|
|
|
host, secure, err := minio.ParseGatewayEndpoint(host)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
var protocol string
|
|
|
|
if secure {
|
|
|
|
protocol = "https"
|
|
|
|
} else {
|
|
|
|
protocol = "http"
|
|
|
|
}
|
|
|
|
|
|
|
|
// for containerized storage deployments like Azurite or IoT Edge Storage,
|
|
|
|
// account resolution isn't handled via a hostname prefix like
|
|
|
|
// `http://${account}.host/${path}` but instead via a route prefix like
|
|
|
|
// `http://host/${account}/${path}` so adjusting for that here
|
|
|
|
if !strings.HasPrefix(host, fmt.Sprintf("%s.", accountName)) {
|
|
|
|
host = fmt.Sprintf("%s/%s", host, accountName)
|
|
|
|
}
|
|
|
|
|
|
|
|
endpoint = fmt.Sprintf("%s://%s", protocol, host)
|
|
|
|
} else {
|
|
|
|
endpoint = fmt.Sprintf("https://%s.blob.core.windows.net", accountName)
|
|
|
|
}
|
|
|
|
|
|
|
|
return url.Parse(endpoint)
|
|
|
|
}
|
|
|
|
|
2017-12-05 20:58:09 -05:00
|
|
|
// Production - Azure gateway is production ready.
|
|
|
|
func (g *Azure) Production() bool {
|
|
|
|
return true
|
2017-10-27 18:07:46 -04:00
|
|
|
}
|
2017-03-16 15:21:58 -04:00
|
|
|
|
2017-09-28 18:23:46 -04:00
|
|
|
// s3MetaToAzureProperties converts metadata meant for S3 PUT/COPY
|
|
|
|
// object into Azure data structures - BlobMetadata and
|
|
|
|
// BlobProperties.
|
|
|
|
//
|
|
|
|
// BlobMetadata contains user defined key-value pairs and each key is
|
|
|
|
// automatically prefixed with `X-Ms-Meta-` by the Azure SDK. S3
|
|
|
|
// user-metadata is translated to Azure metadata by removing the
|
|
|
|
// `X-Amz-Meta-` prefix.
|
|
|
|
//
|
|
|
|
// BlobProperties contains commonly set metadata for objects such as
|
|
|
|
// Content-Encoding, etc. Such metadata that is accepted by S3 is
|
|
|
|
// copied into BlobProperties.
|
|
|
|
//
|
|
|
|
// Header names are canonicalized as in http.Header.
|
2019-12-02 12:32:19 -05:00
|
|
|
func s3MetaToAzureProperties(ctx context.Context, s3Metadata map[string]string) (azblob.Metadata, azblob.BlobHTTPHeaders, error) {
|
2017-10-12 15:16:24 -04:00
|
|
|
for k := range s3Metadata {
|
|
|
|
if strings.Contains(k, "--") {
|
2019-12-02 12:32:19 -05:00
|
|
|
return azblob.Metadata{}, azblob.BlobHTTPHeaders{}, minio.UnsupportedMetadata{}
|
2017-10-12 15:16:24 -04:00
|
|
|
}
|
2017-09-12 19:14:41 -04:00
|
|
|
}
|
|
|
|
|
2017-10-12 15:16:24 -04:00
|
|
|
// Encoding technique for each key is used here is as follows
|
|
|
|
// Each '-' is converted to '_'
|
|
|
|
// Each '_' is converted to '__'
|
|
|
|
// With this basic assumption here are some of the expected
|
|
|
|
// translations for these keys.
|
|
|
|
// i: 'x-S3cmd_attrs' -> o: 'x_s3cmd__attrs' (mixed)
|
|
|
|
// i: 'x__test__value' -> o: 'x____test____value' (double '_')
|
|
|
|
encodeKey := func(key string) string {
|
|
|
|
tokens := strings.Split(key, "_")
|
|
|
|
for i := range tokens {
|
|
|
|
tokens[i] = strings.Replace(tokens[i], "-", "_", -1)
|
|
|
|
}
|
|
|
|
return strings.Join(tokens, "__")
|
|
|
|
}
|
2019-12-02 12:32:19 -05:00
|
|
|
var blobMeta azblob.Metadata = make(map[string]string)
|
|
|
|
var err error
|
|
|
|
var props azblob.BlobHTTPHeaders
|
2017-09-28 18:23:46 -04:00
|
|
|
for k, v := range s3Metadata {
|
2017-05-30 23:05:41 -04:00
|
|
|
k = http.CanonicalHeaderKey(k)
|
2017-09-28 18:23:46 -04:00
|
|
|
switch {
|
|
|
|
case strings.HasPrefix(k, "X-Amz-Meta-"):
|
|
|
|
// Strip header prefix, to let Azure SDK
|
|
|
|
// handle it for storage.
|
|
|
|
k = strings.Replace(k, "X-Amz-Meta-", "", 1)
|
2017-10-12 15:16:24 -04:00
|
|
|
blobMeta[encodeKey(k)] = v
|
2017-09-28 18:23:46 -04:00
|
|
|
// All cases below, extract common metadata that is
|
|
|
|
// accepted by S3 into BlobProperties for setting on
|
|
|
|
// Azure - see
|
|
|
|
// https://docs.aws.amazon.com/AmazonS3/latest/API/RESTObjectPUT.html
|
|
|
|
case k == "Cache-Control":
|
|
|
|
props.CacheControl = v
|
|
|
|
case k == "Content-Disposition":
|
|
|
|
props.ContentDisposition = v
|
|
|
|
case k == "Content-Encoding":
|
|
|
|
props.ContentEncoding = v
|
2017-10-25 13:36:37 -04:00
|
|
|
case k == "Content-Md5":
|
2019-12-02 12:32:19 -05:00
|
|
|
props.ContentMD5, err = base64.StdEncoding.DecodeString(v)
|
2017-09-28 18:23:46 -04:00
|
|
|
case k == "Content-Type":
|
|
|
|
props.ContentType = v
|
2018-06-21 12:46:45 -04:00
|
|
|
case k == "Content-Language":
|
|
|
|
props.ContentLanguage = v
|
2017-05-30 23:05:41 -04:00
|
|
|
}
|
|
|
|
}
|
2019-12-02 12:32:19 -05:00
|
|
|
return blobMeta, props, err
|
2017-05-30 23:05:41 -04:00
|
|
|
}
|
|
|
|
|
2019-02-06 19:58:43 -05:00
|
|
|
const (
|
|
|
|
partMetaVersionV1 = "1"
|
|
|
|
)
|
|
|
|
|
|
|
|
// partMetadataV1 struct holds the part specific metadata for
|
|
|
|
// multipart operations.
|
|
|
|
type partMetadataV1 struct {
|
|
|
|
Version string `json:"version"`
|
|
|
|
Size int64 `json:"Size"`
|
|
|
|
BlockIDs []string `json:"blockIDs"`
|
|
|
|
ETag string `json:"etag"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// Returns the initialized part metadata struct
|
|
|
|
func newPartMetaV1(uploadID string, partID int) (partMeta *partMetadataV1) {
|
|
|
|
p := &partMetadataV1{}
|
|
|
|
p.Version = partMetaVersionV1
|
|
|
|
return p
|
|
|
|
}
|
|
|
|
|
2020-04-19 16:42:56 -04:00
|
|
|
func s3StorageClassToAzureTier(sc string) azblob.AccessTierType {
|
|
|
|
switch sc {
|
|
|
|
case "REDUCED_REDUNDANCY":
|
|
|
|
return azblob.AccessTierCool
|
|
|
|
case "STANDARD":
|
|
|
|
return azblob.AccessTierHot
|
|
|
|
}
|
|
|
|
return azblob.AccessTierHot
|
|
|
|
}
|
|
|
|
|
|
|
|
func azureTierToS3StorageClass(tierType string) string {
|
|
|
|
switch azblob.AccessTierType(tierType) {
|
|
|
|
case azblob.AccessTierCool:
|
|
|
|
return "REDUCED_REDUNDANCY"
|
|
|
|
case azblob.AccessTierHot:
|
|
|
|
return "STANDARD"
|
|
|
|
default:
|
|
|
|
return "STANDARD"
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-09-28 18:23:46 -04:00
|
|
|
// azurePropertiesToS3Meta converts Azure metadata/properties to S3
|
|
|
|
// metadata. It is the reverse of s3MetaToAzureProperties. Azure's
|
|
|
|
// `.GetMetadata()` lower-cases all header keys, so this is taken into
|
|
|
|
// account by this function.
|
2019-12-02 12:32:19 -05:00
|
|
|
func azurePropertiesToS3Meta(meta azblob.Metadata, props azblob.BlobHTTPHeaders, contentLength int64) map[string]string {
|
2017-10-12 15:16:24 -04:00
|
|
|
// Decoding technique for each key is used here is as follows
|
|
|
|
// Each '_' is converted to '-'
|
|
|
|
// Each '__' is converted to '_'
|
|
|
|
// With this basic assumption here are some of the expected
|
|
|
|
// translations for these keys.
|
|
|
|
// i: 'x_s3cmd__attrs' -> o: 'x-s3cmd_attrs' (mixed)
|
|
|
|
// i: 'x____test____value' -> o: 'x__test__value' (double '_')
|
|
|
|
decodeKey := func(key string) string {
|
|
|
|
tokens := strings.Split(key, "__")
|
|
|
|
for i := range tokens {
|
|
|
|
tokens[i] = strings.Replace(tokens[i], "_", "-", -1)
|
|
|
|
}
|
|
|
|
return strings.Join(tokens, "_")
|
2017-09-12 19:14:41 -04:00
|
|
|
}
|
|
|
|
|
2017-09-28 18:23:46 -04:00
|
|
|
s3Metadata := make(map[string]string)
|
2017-05-30 23:05:41 -04:00
|
|
|
for k, v := range meta {
|
2017-09-28 18:23:46 -04:00
|
|
|
// k's `x-ms-meta-` prefix is already stripped by
|
|
|
|
// Azure SDK, so we add the AMZ prefix.
|
2017-10-12 15:16:24 -04:00
|
|
|
k = "X-Amz-Meta-" + decodeKey(k)
|
2017-09-28 18:23:46 -04:00
|
|
|
k = http.CanonicalHeaderKey(k)
|
|
|
|
s3Metadata[k] = v
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add each property from BlobProperties that is supported by
|
|
|
|
// S3 PUT/COPY common metadata.
|
|
|
|
if props.CacheControl != "" {
|
|
|
|
s3Metadata["Cache-Control"] = props.CacheControl
|
|
|
|
}
|
|
|
|
if props.ContentDisposition != "" {
|
|
|
|
s3Metadata["Content-Disposition"] = props.ContentDisposition
|
|
|
|
}
|
|
|
|
if props.ContentEncoding != "" {
|
|
|
|
s3Metadata["Content-Encoding"] = props.ContentEncoding
|
|
|
|
}
|
2019-12-02 12:32:19 -05:00
|
|
|
if contentLength != 0 {
|
|
|
|
s3Metadata["Content-Length"] = fmt.Sprintf("%d", contentLength)
|
2017-09-28 18:23:46 -04:00
|
|
|
}
|
2019-12-02 12:32:19 -05:00
|
|
|
if len(props.ContentMD5) != 0 {
|
|
|
|
s3Metadata["Content-MD5"] = base64.StdEncoding.EncodeToString(props.ContentMD5)
|
2017-05-30 23:05:41 -04:00
|
|
|
}
|
2017-09-28 18:23:46 -04:00
|
|
|
if props.ContentType != "" {
|
|
|
|
s3Metadata["Content-Type"] = props.ContentType
|
|
|
|
}
|
2018-06-21 12:46:45 -04:00
|
|
|
if props.ContentLanguage != "" {
|
|
|
|
s3Metadata["Content-Language"] = props.ContentLanguage
|
|
|
|
}
|
2017-09-28 18:23:46 -04:00
|
|
|
return s3Metadata
|
2017-05-30 23:05:41 -04:00
|
|
|
}
|
|
|
|
|
2017-05-15 03:52:33 -04:00
|
|
|
// azureObjects - Implements Object layer for Azure blob storage.
|
|
|
|
type azureObjects struct {
|
2017-12-05 20:58:09 -05:00
|
|
|
minio.GatewayUnsupported
|
2019-11-01 19:58:11 -04:00
|
|
|
endpoint string
|
|
|
|
httpClient *http.Client
|
2020-02-11 10:38:01 -05:00
|
|
|
metrics *minio.Metrics
|
2019-12-02 12:32:19 -05:00
|
|
|
client azblob.ServiceURL // Azure sdk client
|
2017-03-16 15:21:58 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Convert azure errors to minio object layer errors.
|
|
|
|
func azureToObjectError(err error, params ...string) error {
|
|
|
|
if err == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
bucket := ""
|
|
|
|
object := ""
|
|
|
|
if len(params) >= 1 {
|
|
|
|
bucket = params[0]
|
|
|
|
}
|
|
|
|
if len(params) == 2 {
|
|
|
|
object = params[1]
|
|
|
|
}
|
|
|
|
|
2019-12-02 12:32:19 -05:00
|
|
|
azureErr, ok := err.(azblob.StorageError)
|
2017-03-16 15:21:58 -04:00
|
|
|
if !ok {
|
|
|
|
// We don't interpret non Azure errors. As azure errors will
|
|
|
|
// have StatusCode to help to convert to object errors.
|
2018-04-05 18:04:40 -04:00
|
|
|
return err
|
2017-03-16 15:21:58 -04:00
|
|
|
}
|
|
|
|
|
2019-12-02 12:32:19 -05:00
|
|
|
serviceCode := string(azureErr.ServiceCode())
|
|
|
|
statusCode := azureErr.Response().StatusCode
|
|
|
|
|
|
|
|
return azureCodesToObjectError(err, serviceCode, statusCode, bucket, object)
|
|
|
|
}
|
|
|
|
|
|
|
|
func azureCodesToObjectError(err error, serviceCode string, statusCode int, bucket string, object string) error {
|
|
|
|
switch serviceCode {
|
2017-03-16 15:21:58 -04:00
|
|
|
case "ContainerAlreadyExists":
|
2017-12-05 20:58:09 -05:00
|
|
|
err = minio.BucketExists{Bucket: bucket}
|
2017-03-16 15:21:58 -04:00
|
|
|
case "InvalidResourceName":
|
2017-12-05 20:58:09 -05:00
|
|
|
err = minio.BucketNameInvalid{Bucket: bucket}
|
2017-07-12 19:42:14 -04:00
|
|
|
case "RequestBodyTooLarge":
|
2017-12-05 20:58:09 -05:00
|
|
|
err = minio.PartTooBig{}
|
2017-09-12 19:14:41 -04:00
|
|
|
case "InvalidMetadata":
|
2017-12-05 20:58:09 -05:00
|
|
|
err = minio.UnsupportedMetadata{}
|
2020-04-19 16:42:56 -04:00
|
|
|
case "BlobAccessTierNotSupportedForAccountType":
|
|
|
|
err = minio.NotImplemented{}
|
2017-03-16 15:21:58 -04:00
|
|
|
default:
|
2019-12-02 12:32:19 -05:00
|
|
|
switch statusCode {
|
2017-03-16 15:21:58 -04:00
|
|
|
case http.StatusNotFound:
|
|
|
|
if object != "" {
|
2017-12-05 20:58:09 -05:00
|
|
|
err = minio.ObjectNotFound{
|
|
|
|
Bucket: bucket,
|
|
|
|
Object: object,
|
|
|
|
}
|
2017-03-16 15:21:58 -04:00
|
|
|
} else {
|
2017-12-05 20:58:09 -05:00
|
|
|
err = minio.BucketNotFound{Bucket: bucket}
|
2017-03-16 15:21:58 -04:00
|
|
|
}
|
|
|
|
case http.StatusBadRequest:
|
2017-12-05 20:58:09 -05:00
|
|
|
err = minio.BucketNameInvalid{Bucket: bucket}
|
2017-03-16 15:21:58 -04:00
|
|
|
}
|
|
|
|
}
|
2018-04-05 18:04:40 -04:00
|
|
|
return err
|
2017-03-16 15:21:58 -04:00
|
|
|
}
|
|
|
|
|
2018-04-19 20:24:43 -04:00
|
|
|
// getAzureUploadID - returns new upload ID which is hex encoded 8 bytes random value.
|
2018-03-29 12:54:47 -04:00
|
|
|
// this 8 byte restriction is needed because Azure block id has a restriction of length
|
|
|
|
// upto 8 bytes.
|
2018-04-19 20:24:43 -04:00
|
|
|
func getAzureUploadID() (string, error) {
|
2018-03-29 12:54:47 -04:00
|
|
|
var id [8]byte
|
|
|
|
|
|
|
|
n, err := io.ReadFull(rand.Reader, id[:])
|
2017-09-19 19:08:08 -04:00
|
|
|
if err != nil {
|
2018-04-19 20:24:43 -04:00
|
|
|
return "", err
|
2018-03-29 12:54:47 -04:00
|
|
|
}
|
|
|
|
if n != len(id) {
|
2018-04-19 20:24:43 -04:00
|
|
|
return "", fmt.Errorf("Unexpected random data size. Expected: %d, read: %d)", len(id), n)
|
2017-09-19 19:08:08 -04:00
|
|
|
}
|
2018-03-29 12:54:47 -04:00
|
|
|
|
2018-04-19 20:24:43 -04:00
|
|
|
return hex.EncodeToString(id[:]), nil
|
2017-09-19 19:08:08 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// checkAzureUploadID - returns error in case of given string is upload ID.
|
2018-04-05 18:04:40 -04:00
|
|
|
func checkAzureUploadID(ctx context.Context, uploadID string) (err error) {
|
2017-09-19 19:08:08 -04:00
|
|
|
if len(uploadID) != 16 {
|
2018-04-05 18:04:40 -04:00
|
|
|
return minio.MalformedUploadID{
|
|
|
|
UploadID: uploadID,
|
|
|
|
}
|
2017-09-19 19:08:08 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if _, err = hex.DecodeString(uploadID); err != nil {
|
2018-04-05 18:04:40 -04:00
|
|
|
return minio.MalformedUploadID{
|
|
|
|
UploadID: uploadID,
|
|
|
|
}
|
2017-09-19 19:08:08 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2019-02-06 19:58:43 -05:00
|
|
|
// parses partID from part metadata file name
|
|
|
|
func parseAzurePart(metaPartFileName, prefix string) (partID int, err error) {
|
2019-08-06 15:08:58 -04:00
|
|
|
partStr := strings.TrimPrefix(metaPartFileName, prefix+minio.SlashSeparator)
|
2019-02-06 19:58:43 -05:00
|
|
|
if partID, err = strconv.Atoi(partStr); err != nil || partID <= 0 {
|
|
|
|
err = fmt.Errorf("invalid part number in block id '%s'", string(partID))
|
2017-09-19 19:08:08 -04:00
|
|
|
return
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-02-11 10:38:01 -05:00
|
|
|
// GetMetrics returns this gateway's metrics
|
|
|
|
func (a *azureObjects) GetMetrics(ctx context.Context) (*minio.Metrics, error) {
|
|
|
|
return a.metrics, nil
|
|
|
|
}
|
|
|
|
|
2017-03-16 15:21:58 -04:00
|
|
|
// Shutdown - save any gateway metadata to disk
|
|
|
|
// if necessary and reload upon next restart.
|
2018-03-14 15:01:47 -04:00
|
|
|
func (a *azureObjects) Shutdown(ctx context.Context) error {
|
2017-03-16 15:21:58 -04:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// StorageInfo - Not relevant to Azure backend.
|
2020-05-28 16:03:04 -04:00
|
|
|
func (a *azureObjects) StorageInfo(ctx context.Context, _ bool) (si minio.StorageInfo, _ []error) {
|
2019-11-01 19:58:11 -04:00
|
|
|
si.Backend.Type = minio.BackendGateway
|
|
|
|
si.Backend.GatewayOnline = minio.IsBackendOnline(ctx, a.httpClient, a.endpoint)
|
2020-05-28 16:03:04 -04:00
|
|
|
return si, nil
|
2017-03-16 15:21:58 -04:00
|
|
|
}
|
|
|
|
|
2017-04-27 14:26:00 -04:00
|
|
|
// MakeBucketWithLocation - Create a new container on azure backend.
|
2020-06-12 23:04:01 -04:00
|
|
|
func (a *azureObjects) MakeBucketWithLocation(ctx context.Context, bucket string, opts minio.BucketOptions) error {
|
|
|
|
if opts.LockEnabled || opts.VersioningEnabled {
|
2020-05-08 16:44:44 -04:00
|
|
|
return minio.NotImplemented{}
|
|
|
|
}
|
|
|
|
|
2018-04-23 23:27:33 -04:00
|
|
|
// Verify if bucket (container-name) is valid.
|
|
|
|
// IsValidBucketName has same restrictions as container names mentioned
|
|
|
|
// in azure documentation, so we will simply use the same function here.
|
|
|
|
// Ref - https://docs.microsoft.com/en-us/rest/api/storageservices/naming-and-referencing-containers--blobs--and-metadata
|
|
|
|
if !minio.IsValidBucketName(bucket) {
|
|
|
|
return minio.BucketNameInvalid{Bucket: bucket}
|
|
|
|
}
|
|
|
|
|
2019-12-02 12:32:19 -05:00
|
|
|
containerURL := a.client.NewContainerURL(bucket)
|
|
|
|
_, err := containerURL.Create(ctx, azblob.Metadata{}, azblob.PublicAccessNone)
|
2018-04-05 18:04:40 -04:00
|
|
|
return azureToObjectError(err, bucket)
|
2017-03-16 15:21:58 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// GetBucketInfo - Get bucket metadata..
|
2018-03-14 15:01:47 -04:00
|
|
|
func (a *azureObjects) GetBucketInfo(ctx context.Context, bucket string) (bi minio.BucketInfo, e error) {
|
2017-09-28 18:23:46 -04:00
|
|
|
// Azure does not have an equivalent call, hence use
|
|
|
|
// ListContainers with prefix
|
2019-12-02 12:32:19 -05:00
|
|
|
|
|
|
|
marker := azblob.Marker{}
|
|
|
|
|
|
|
|
for marker.NotDone() {
|
|
|
|
resp, err := a.client.ListContainersSegment(ctx, marker, azblob.ListContainersSegmentOptions{
|
|
|
|
Prefix: bucket,
|
|
|
|
})
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return bi, azureToObjectError(err, bucket)
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, container := range resp.ContainerItems {
|
|
|
|
if container.Name == bucket {
|
|
|
|
t := container.Properties.LastModified
|
2017-12-05 20:58:09 -05:00
|
|
|
return minio.BucketInfo{
|
2017-03-16 15:21:58 -04:00
|
|
|
Name: bucket,
|
|
|
|
Created: t,
|
|
|
|
}, nil
|
|
|
|
} // else continue
|
|
|
|
}
|
2019-12-02 12:32:19 -05:00
|
|
|
|
|
|
|
marker = resp.NextMarker
|
2017-03-16 15:21:58 -04:00
|
|
|
}
|
2018-04-05 18:04:40 -04:00
|
|
|
return bi, minio.BucketNotFound{Bucket: bucket}
|
2017-03-16 15:21:58 -04:00
|
|
|
}
|
|
|
|
|
2019-12-02 12:32:19 -05:00
|
|
|
// ListBuckets - Lists all azure containers, uses Azure equivalent `ServiceURL.ListContainersSegment`.
|
2018-03-14 15:01:47 -04:00
|
|
|
func (a *azureObjects) ListBuckets(ctx context.Context) (buckets []minio.BucketInfo, err error) {
|
2019-12-02 12:32:19 -05:00
|
|
|
marker := azblob.Marker{}
|
|
|
|
|
|
|
|
for marker.NotDone() {
|
|
|
|
resp, err := a.client.ListContainersSegment(ctx, marker, azblob.ListContainersSegmentOptions{})
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return nil, azureToObjectError(err)
|
2017-03-16 15:21:58 -04:00
|
|
|
}
|
2019-12-02 12:32:19 -05:00
|
|
|
|
|
|
|
for _, container := range resp.ContainerItems {
|
|
|
|
t := container.Properties.LastModified
|
|
|
|
buckets = append(buckets, minio.BucketInfo{
|
|
|
|
Name: container.Name,
|
|
|
|
Created: t,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
marker = resp.NextMarker
|
2017-03-16 15:21:58 -04:00
|
|
|
}
|
|
|
|
return buckets, nil
|
|
|
|
}
|
|
|
|
|
2019-12-02 12:32:19 -05:00
|
|
|
// DeleteBucket - delete a container on azure, uses Azure equivalent `ContainerURL.Delete`.
|
2020-03-28 00:52:59 -04:00
|
|
|
func (a *azureObjects) DeleteBucket(ctx context.Context, bucket string, forceDelete bool) error {
|
2020-05-29 16:24:39 -04:00
|
|
|
if !forceDelete {
|
|
|
|
// Check if the container is empty before deleting it.
|
|
|
|
result, err := a.ListObjects(ctx, bucket, "", "", "", 1)
|
|
|
|
if err != nil {
|
|
|
|
return azureToObjectError(err, bucket)
|
|
|
|
}
|
|
|
|
if len(result.Objects) > 0 {
|
|
|
|
return minio.BucketNotEmpty{Bucket: bucket}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-02 12:32:19 -05:00
|
|
|
containerURL := a.client.NewContainerURL(bucket)
|
|
|
|
_, err := containerURL.Delete(ctx, azblob.ContainerAccessConditions{})
|
2018-04-05 18:04:40 -04:00
|
|
|
return azureToObjectError(err, bucket)
|
2017-03-16 15:21:58 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// ListObjects - lists all blobs on azure with in a container filtered by prefix
|
2019-12-02 12:32:19 -05:00
|
|
|
// and marker, uses Azure equivalent `ContainerURL.ListBlobsHierarchySegment`.
|
2018-04-27 19:08:46 -04:00
|
|
|
// To accommodate S3-compatible applications using
|
|
|
|
// ListObjectsV1 to use object keys as markers to control the
|
|
|
|
// listing of objects, we use the following encoding scheme to
|
|
|
|
// distinguish between Azure continuation tokens and application
|
|
|
|
// supplied markers.
|
|
|
|
//
|
|
|
|
// - NextMarker in ListObjectsV1 response is constructed by
|
|
|
|
// prefixing "{minio}" to the Azure continuation token,
|
|
|
|
// e.g, "{minio}CgRvYmoz"
|
|
|
|
//
|
|
|
|
// - Application supplied markers are used as-is to list
|
|
|
|
// object keys that appear after it in the lexicographical order.
|
2018-03-14 15:01:47 -04:00
|
|
|
func (a *azureObjects) ListObjects(ctx context.Context, bucket, prefix, marker, delimiter string, maxKeys int) (result minio.ListObjectsInfo, err error) {
|
2017-12-05 20:58:09 -05:00
|
|
|
var objects []minio.ObjectInfo
|
2017-09-29 15:08:23 -04:00
|
|
|
var prefixes []string
|
2018-04-27 19:08:46 -04:00
|
|
|
|
2019-12-02 12:32:19 -05:00
|
|
|
azureListMarker := azblob.Marker{}
|
2018-04-27 19:08:46 -04:00
|
|
|
if isAzureMarker(marker) {
|
|
|
|
// If application is using Azure continuation token we should
|
|
|
|
// strip the azureTokenPrefix we added in the previous list response.
|
2019-12-02 12:32:19 -05:00
|
|
|
azureMarker := strings.TrimPrefix(marker, azureMarkerPrefix)
|
|
|
|
azureListMarker.Val = &azureMarker
|
2018-04-27 19:08:46 -04:00
|
|
|
}
|
|
|
|
|
2019-12-02 12:32:19 -05:00
|
|
|
containerURL := a.client.NewContainerURL(bucket)
|
2017-09-29 15:08:23 -04:00
|
|
|
for len(objects) == 0 && len(prefixes) == 0 {
|
2019-12-02 12:32:19 -05:00
|
|
|
resp, err := containerURL.ListBlobsHierarchySegment(ctx, azureListMarker, delimiter, azblob.ListBlobsSegmentOptions{
|
2017-09-29 15:08:23 -04:00
|
|
|
Prefix: prefix,
|
2019-12-02 12:32:19 -05:00
|
|
|
MaxResults: int32(maxKeys),
|
2017-06-17 01:17:00 -04:00
|
|
|
})
|
2017-09-29 15:08:23 -04:00
|
|
|
if err != nil {
|
2018-04-05 18:04:40 -04:00
|
|
|
return result, azureToObjectError(err, bucket, prefix)
|
2017-09-29 15:08:23 -04:00
|
|
|
}
|
|
|
|
|
2019-12-02 12:32:19 -05:00
|
|
|
for _, blob := range resp.Segment.BlobItems {
|
2018-05-08 22:08:47 -04:00
|
|
|
if delimiter == "" && strings.HasPrefix(blob.Name, minio.GatewayMinioSysTmp) {
|
2018-04-27 19:08:46 -04:00
|
|
|
// We filter out minio.GatewayMinioSysTmp entries in the recursive listing.
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if !isAzureMarker(marker) && blob.Name <= marker {
|
|
|
|
// If the application used ListObjectsV1 style marker then we
|
|
|
|
// skip all the entries till we reach the marker.
|
2017-09-29 15:08:23 -04:00
|
|
|
continue
|
|
|
|
}
|
2019-03-20 21:11:46 -04:00
|
|
|
// Populate correct ETag's if possible, this code primarily exists
|
|
|
|
// because AWS S3 indicates that
|
|
|
|
//
|
|
|
|
// https://docs.aws.amazon.com/AmazonS3/latest/API/RESTCommonResponseHeaders.html
|
|
|
|
//
|
|
|
|
// Objects created by the PUT Object, POST Object, or Copy operation,
|
|
|
|
// or through the AWS Management Console, and are encrypted by SSE-S3
|
|
|
|
// or plaintext, have ETags that are an MD5 digest of their object data.
|
|
|
|
//
|
|
|
|
// Some applications depend on this behavior refer https://github.com/minio/minio/issues/6550
|
|
|
|
// So we handle it here and make this consistent.
|
2019-12-02 12:32:19 -05:00
|
|
|
etag := minio.ToS3ETag(string(blob.Properties.Etag))
|
2019-03-20 21:11:46 -04:00
|
|
|
switch {
|
2019-12-02 12:32:19 -05:00
|
|
|
case len(blob.Properties.ContentMD5) != 0:
|
|
|
|
etag = hex.EncodeToString(blob.Properties.ContentMD5)
|
2019-03-20 21:11:46 -04:00
|
|
|
case blob.Metadata["md5sum"] != "":
|
|
|
|
etag = blob.Metadata["md5sum"]
|
|
|
|
delete(blob.Metadata, "md5sum")
|
|
|
|
}
|
|
|
|
|
2017-12-05 20:58:09 -05:00
|
|
|
objects = append(objects, minio.ObjectInfo{
|
2017-09-29 15:08:23 -04:00
|
|
|
Bucket: bucket,
|
2018-04-27 19:08:46 -04:00
|
|
|
Name: blob.Name,
|
2019-12-02 12:32:19 -05:00
|
|
|
ModTime: blob.Properties.LastModified,
|
|
|
|
Size: *blob.Properties.ContentLength,
|
2019-03-20 21:11:46 -04:00
|
|
|
ETag: etag,
|
2019-12-02 12:32:19 -05:00
|
|
|
ContentType: *blob.Properties.ContentType,
|
|
|
|
ContentEncoding: *blob.Properties.ContentEncoding,
|
2020-04-19 16:42:56 -04:00
|
|
|
UserDefined: blob.Metadata,
|
2017-09-29 15:08:23 -04:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-12-02 12:32:19 -05:00
|
|
|
for _, blobPrefix := range resp.Segment.BlobPrefixes {
|
|
|
|
if blobPrefix.Name == minio.GatewayMinioSysTmp {
|
2018-04-27 19:08:46 -04:00
|
|
|
// We don't do strings.HasPrefix(blob.Name, minio.GatewayMinioSysTmp) here so that
|
|
|
|
// we can use tools like mc to inspect the contents of minio.sys.tmp/
|
|
|
|
// It is OK to allow listing of minio.sys.tmp/ in non-recursive mode as it aids in debugging.
|
|
|
|
continue
|
2017-09-29 15:08:23 -04:00
|
|
|
}
|
2019-12-02 12:32:19 -05:00
|
|
|
if !isAzureMarker(marker) && blobPrefix.Name <= marker {
|
2018-04-27 19:08:46 -04:00
|
|
|
// If the application used ListObjectsV1 style marker then we
|
|
|
|
// skip all the entries till we reach the marker.
|
|
|
|
continue
|
|
|
|
}
|
2019-12-02 12:32:19 -05:00
|
|
|
prefixes = append(prefixes, blobPrefix.Name)
|
2017-09-29 15:08:23 -04:00
|
|
|
}
|
2017-09-19 19:08:08 -04:00
|
|
|
|
2018-04-27 19:08:46 -04:00
|
|
|
azureListMarker = resp.NextMarker
|
2019-12-02 12:32:19 -05:00
|
|
|
if !azureListMarker.NotDone() {
|
2018-04-27 19:08:46 -04:00
|
|
|
// Reached end of listing.
|
2017-09-19 19:08:08 -04:00
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
2017-09-29 15:08:23 -04:00
|
|
|
|
|
|
|
result.Objects = objects
|
|
|
|
result.Prefixes = prefixes
|
2019-12-02 12:32:19 -05:00
|
|
|
if azureListMarker.NotDone() {
|
2018-04-27 19:08:46 -04:00
|
|
|
// We add the {minio} prefix so that we know in the subsequent request that this
|
|
|
|
// marker is a azure continuation token and not ListObjectV1 marker.
|
2019-12-02 12:32:19 -05:00
|
|
|
result.NextMarker = azureMarkerPrefix + *azureListMarker.Val
|
2018-04-27 19:08:46 -04:00
|
|
|
result.IsTruncated = true
|
|
|
|
}
|
2017-06-17 01:17:00 -04:00
|
|
|
return result, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// ListObjectsV2 - list all blobs in Azure bucket filtered by prefix
|
2018-03-14 15:01:47 -04:00
|
|
|
func (a *azureObjects) ListObjectsV2(ctx context.Context, bucket, prefix, continuationToken, delimiter string, maxKeys int, fetchOwner bool, startAfter string) (result minio.ListObjectsV2Info, err error) {
|
2017-09-29 15:08:23 -04:00
|
|
|
marker := continuationToken
|
2018-07-01 00:22:45 -04:00
|
|
|
if marker == "" {
|
2017-09-29 15:08:23 -04:00
|
|
|
marker = startAfter
|
2017-03-16 15:21:58 -04:00
|
|
|
}
|
2017-09-19 19:08:08 -04:00
|
|
|
|
2017-12-05 20:58:09 -05:00
|
|
|
var resultV1 minio.ListObjectsInfo
|
2018-03-14 15:01:47 -04:00
|
|
|
resultV1, err = a.ListObjects(ctx, bucket, prefix, marker, delimiter, maxKeys)
|
2017-09-29 15:08:23 -04:00
|
|
|
if err != nil {
|
|
|
|
return result, err
|
2017-09-19 19:08:08 -04:00
|
|
|
}
|
2017-09-29 15:08:23 -04:00
|
|
|
|
|
|
|
result.Objects = resultV1.Objects
|
|
|
|
result.Prefixes = resultV1.Prefixes
|
|
|
|
result.ContinuationToken = continuationToken
|
|
|
|
result.NextContinuationToken = resultV1.NextMarker
|
|
|
|
result.IsTruncated = (resultV1.NextMarker != "")
|
2017-03-16 15:21:58 -04:00
|
|
|
return result, nil
|
|
|
|
}
|
|
|
|
|
2018-09-20 22:22:09 -04:00
|
|
|
// GetObjectNInfo - returns object info and locked object ReadCloser
|
2018-09-27 06:06:45 -04:00
|
|
|
func (a *azureObjects) GetObjectNInfo(ctx context.Context, bucket, object string, rs *minio.HTTPRangeSpec, h http.Header, lockType minio.LockType, opts minio.ObjectOptions) (gr *minio.GetObjectReader, err error) {
|
2018-09-20 22:22:09 -04:00
|
|
|
var objInfo minio.ObjectInfo
|
2018-09-27 06:06:45 -04:00
|
|
|
objInfo, err = a.GetObjectInfo(ctx, bucket, object, opts)
|
2018-09-20 22:22:09 -04:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
var startOffset, length int64
|
|
|
|
startOffset, length, err = rs.GetOffsetLength(objInfo.Size)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
pr, pw := io.Pipe()
|
|
|
|
go func() {
|
2018-09-27 06:06:45 -04:00
|
|
|
err := a.GetObject(ctx, bucket, object, startOffset, length, pw, objInfo.ETag, opts)
|
2018-09-20 22:22:09 -04:00
|
|
|
pw.CloseWithError(err)
|
|
|
|
}()
|
2018-09-21 14:42:06 -04:00
|
|
|
// Setup cleanup function to cause the above go-routine to
|
|
|
|
// exit in case of partial read
|
|
|
|
pipeCloser := func() { pr.Close() }
|
2020-04-21 01:01:59 -04:00
|
|
|
return minio.NewGetObjectReaderFromReader(pr, objInfo, opts, pipeCloser)
|
2018-09-20 22:22:09 -04:00
|
|
|
}
|
|
|
|
|
2017-03-16 15:21:58 -04:00
|
|
|
// GetObject - reads an object from azure. Supports additional
|
|
|
|
// parameters like offset and length which are synonymous with
|
|
|
|
// HTTP Range requests.
|
|
|
|
//
|
|
|
|
// startOffset indicates the starting read location of the object.
|
|
|
|
// length indicates the total length of the object.
|
2018-09-10 12:42:43 -04:00
|
|
|
func (a *azureObjects) GetObject(ctx context.Context, bucket, object string, startOffset int64, length int64, writer io.Writer, etag string, opts minio.ObjectOptions) error {
|
2017-10-26 21:01:46 -04:00
|
|
|
// startOffset cannot be negative.
|
|
|
|
if startOffset < 0 {
|
2018-04-05 18:04:40 -04:00
|
|
|
return azureToObjectError(minio.InvalidRange{}, bucket, object)
|
2017-10-26 21:01:46 -04:00
|
|
|
}
|
|
|
|
|
2019-12-02 12:32:19 -05:00
|
|
|
blobURL := a.client.NewContainerURL(bucket).NewBlobURL(object)
|
|
|
|
blob, err := blobURL.Download(ctx, startOffset, length, azblob.BlobAccessConditions{}, false)
|
2017-03-16 15:21:58 -04:00
|
|
|
if err != nil {
|
2018-04-05 18:04:40 -04:00
|
|
|
return azureToObjectError(err, bucket, object)
|
2017-03-16 15:21:58 -04:00
|
|
|
}
|
2019-12-02 12:32:19 -05:00
|
|
|
|
|
|
|
rc := blob.Body(azblob.RetryReaderOptions{MaxRetryRequests: azureDownloadRetryAttempts})
|
|
|
|
|
2017-03-16 15:21:58 -04:00
|
|
|
_, err = io.Copy(writer, rc)
|
|
|
|
rc.Close()
|
2018-04-05 18:04:40 -04:00
|
|
|
return err
|
2017-03-16 15:21:58 -04:00
|
|
|
}
|
|
|
|
|
2017-12-05 20:58:09 -05:00
|
|
|
// GetObjectInfo - reads blob metadata properties and replies back minio.ObjectInfo,
|
2019-12-02 12:32:19 -05:00
|
|
|
// uses Azure equivalent `BlobURL.GetProperties`.
|
2018-09-10 12:42:43 -04:00
|
|
|
func (a *azureObjects) GetObjectInfo(ctx context.Context, bucket, object string, opts minio.ObjectOptions) (objInfo minio.ObjectInfo, err error) {
|
2019-12-02 12:32:19 -05:00
|
|
|
blobURL := a.client.NewContainerURL(bucket).NewBlobURL(object)
|
|
|
|
blob, err := blobURL.GetProperties(ctx, azblob.BlobAccessConditions{})
|
2017-05-30 23:05:41 -04:00
|
|
|
if err != nil {
|
2018-04-05 18:04:40 -04:00
|
|
|
return objInfo, azureToObjectError(err, bucket, object)
|
2017-05-30 23:05:41 -04:00
|
|
|
}
|
|
|
|
|
2018-10-03 02:08:16 -04:00
|
|
|
// Populate correct ETag's if possible, this code primarily exists
|
|
|
|
// because AWS S3 indicates that
|
|
|
|
//
|
|
|
|
// https://docs.aws.amazon.com/AmazonS3/latest/API/RESTCommonResponseHeaders.html
|
|
|
|
//
|
|
|
|
// Objects created by the PUT Object, POST Object, or Copy operation,
|
|
|
|
// or through the AWS Management Console, and are encrypted by SSE-S3
|
|
|
|
// or plaintext, have ETags that are an MD5 digest of their object data.
|
|
|
|
//
|
|
|
|
// Some applications depend on this behavior refer https://github.com/minio/minio/issues/6550
|
|
|
|
// So we handle it here and make this consistent.
|
2019-12-02 12:32:19 -05:00
|
|
|
etag := minio.ToS3ETag(string(blob.ETag()))
|
|
|
|
metadata := blob.NewMetadata()
|
|
|
|
contentMD5 := blob.ContentMD5()
|
2018-10-03 02:08:16 -04:00
|
|
|
switch {
|
2019-12-02 12:32:19 -05:00
|
|
|
case len(contentMD5) != 0:
|
|
|
|
etag = hex.EncodeToString(contentMD5)
|
|
|
|
case metadata["md5sum"] != "":
|
|
|
|
etag = metadata["md5sum"]
|
|
|
|
delete(metadata, "md5sum")
|
2018-10-03 02:08:16 -04:00
|
|
|
}
|
|
|
|
|
2017-12-05 20:58:09 -05:00
|
|
|
return minio.ObjectInfo{
|
2017-09-28 18:23:46 -04:00
|
|
|
Bucket: bucket,
|
2019-12-02 12:32:19 -05:00
|
|
|
UserDefined: azurePropertiesToS3Meta(metadata, blob.NewHTTPHeaders(), blob.ContentLength()),
|
2018-10-03 02:08:16 -04:00
|
|
|
ETag: etag,
|
2019-12-02 12:32:19 -05:00
|
|
|
ModTime: blob.LastModified(),
|
2017-09-28 18:23:46 -04:00
|
|
|
Name: object,
|
2019-12-02 12:32:19 -05:00
|
|
|
Size: blob.ContentLength(),
|
|
|
|
ContentType: blob.ContentType(),
|
|
|
|
ContentEncoding: blob.ContentEncoding(),
|
2020-04-19 16:42:56 -04:00
|
|
|
StorageClass: azureTierToS3StorageClass(blob.AccessTier()),
|
2017-12-05 20:58:09 -05:00
|
|
|
}, nil
|
2017-03-16 15:21:58 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// PutObject - Create a new blob with the incoming data,
|
2019-12-02 12:32:19 -05:00
|
|
|
// uses Azure equivalent `UploadStreamToBlockBlob`.
|
2019-02-09 00:31:06 -05:00
|
|
|
func (a *azureObjects) PutObject(ctx context.Context, bucket, object string, r *minio.PutObjReader, opts minio.ObjectOptions) (objInfo minio.ObjectInfo, err error) {
|
2018-11-14 20:36:41 -05:00
|
|
|
data := r.Reader
|
2018-10-03 02:08:16 -04:00
|
|
|
|
2019-12-02 12:32:19 -05:00
|
|
|
if data.Size() > azureBlockSize/2 {
|
|
|
|
if len(opts.UserDefined) == 0 {
|
|
|
|
opts.UserDefined = map[string]string{}
|
2018-10-03 02:08:16 -04:00
|
|
|
}
|
|
|
|
|
2019-12-02 12:32:19 -05:00
|
|
|
// Save md5sum for future processing on the object.
|
|
|
|
opts.UserDefined["x-amz-meta-md5sum"] = r.MD5CurrentHexString()
|
2018-10-03 02:08:16 -04:00
|
|
|
}
|
|
|
|
|
2019-12-02 12:32:19 -05:00
|
|
|
metadata, properties, err := s3MetaToAzureProperties(ctx, opts.UserDefined)
|
|
|
|
if err != nil {
|
2017-10-12 15:16:24 -04:00
|
|
|
return objInfo, azureToObjectError(err, bucket, object)
|
|
|
|
}
|
2019-12-02 12:32:19 -05:00
|
|
|
blobURL := a.client.NewContainerURL(bucket).NewBlockBlobURL(object)
|
2018-10-03 02:08:16 -04:00
|
|
|
|
2019-12-02 12:32:19 -05:00
|
|
|
_, err = azblob.UploadStreamToBlockBlob(ctx, data, blobURL, azblob.UploadStreamToBlockBlobOptions{
|
|
|
|
BufferSize: azureUploadChunkSize,
|
|
|
|
MaxBuffers: azureUploadConcurrency,
|
|
|
|
BlobHTTPHeaders: properties,
|
|
|
|
Metadata: metadata,
|
|
|
|
})
|
2017-03-16 15:21:58 -04:00
|
|
|
if err != nil {
|
2018-04-05 18:04:40 -04:00
|
|
|
return objInfo, azureToObjectError(err, bucket, object)
|
2017-03-16 15:21:58 -04:00
|
|
|
}
|
2018-10-03 02:08:16 -04:00
|
|
|
|
2018-09-10 12:42:43 -04:00
|
|
|
return a.GetObjectInfo(ctx, bucket, object, opts)
|
2017-03-16 15:21:58 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// CopyObject - Copies a blob from source container to destination container.
|
2019-12-02 12:32:19 -05:00
|
|
|
// Uses Azure equivalent `BlobURL.StartCopyFromURL`.
|
2018-09-10 12:42:43 -04:00
|
|
|
func (a *azureObjects) CopyObject(ctx context.Context, srcBucket, srcObject, destBucket, destObject string, srcInfo minio.ObjectInfo, srcOpts, dstOpts minio.ObjectOptions) (objInfo minio.ObjectInfo, err error) {
|
2019-03-06 15:38:41 -05:00
|
|
|
if srcOpts.CheckCopyPrecondFn != nil && srcOpts.CheckCopyPrecondFn(srcInfo, "") {
|
|
|
|
return minio.ObjectInfo{}, minio.PreConditionFailed{}
|
|
|
|
}
|
2020-05-08 14:30:35 -04:00
|
|
|
srcBlob := a.client.NewContainerURL(srcBucket).NewBlobURL(srcObject)
|
|
|
|
srcBlobURL := srcBlob.URL()
|
|
|
|
|
|
|
|
srcProps, err := srcBlob.GetProperties(ctx, azblob.BlobAccessConditions{})
|
|
|
|
if err != nil {
|
|
|
|
return objInfo, azureToObjectError(err, srcBucket, srcObject)
|
|
|
|
}
|
2019-12-02 12:32:19 -05:00
|
|
|
destBlob := a.client.NewContainerURL(destBucket).NewBlobURL(destObject)
|
2020-05-08 14:30:35 -04:00
|
|
|
|
2018-04-05 18:04:40 -04:00
|
|
|
azureMeta, props, err := s3MetaToAzureProperties(ctx, srcInfo.UserDefined)
|
2017-10-12 15:16:24 -04:00
|
|
|
if err != nil {
|
|
|
|
return objInfo, azureToObjectError(err, srcBucket, srcObject)
|
|
|
|
}
|
2020-05-08 14:30:35 -04:00
|
|
|
props.ContentMD5 = srcProps.ContentMD5()
|
2019-12-02 12:32:19 -05:00
|
|
|
res, err := destBlob.StartCopyFromURL(ctx, srcBlobURL, azureMeta, azblob.ModifiedAccessConditions{}, azblob.BlobAccessConditions{})
|
2017-03-16 15:21:58 -04:00
|
|
|
if err != nil {
|
2018-04-05 18:04:40 -04:00
|
|
|
return objInfo, azureToObjectError(err, srcBucket, srcObject)
|
2017-03-16 15:21:58 -04:00
|
|
|
}
|
2019-12-02 12:32:19 -05:00
|
|
|
// StartCopyFromURL is an asynchronous operation so need to poll for completion,
|
|
|
|
// see https://docs.microsoft.com/en-us/rest/api/storageservices/copy-blob#remarks.
|
|
|
|
copyStatus := res.CopyStatus()
|
|
|
|
for copyStatus != azblob.CopyStatusSuccess {
|
|
|
|
destProps, err := destBlob.GetProperties(ctx, azblob.BlobAccessConditions{})
|
|
|
|
if err != nil {
|
|
|
|
return objInfo, azureToObjectError(err, srcBucket, srcObject)
|
|
|
|
}
|
|
|
|
copyStatus = destProps.CopyStatus()
|
|
|
|
}
|
|
|
|
|
2018-05-02 00:50:00 -04:00
|
|
|
// Azure will copy metadata from the source object when an empty metadata map is provided.
|
|
|
|
// To handle the case where the source object should be copied without its metadata,
|
|
|
|
// the metadata must be removed from the dest. object after the copy completes
|
2019-12-02 12:32:19 -05:00
|
|
|
if len(azureMeta) == 0 {
|
2020-04-19 16:42:56 -04:00
|
|
|
_, err = destBlob.SetMetadata(ctx, azureMeta, azblob.BlobAccessConditions{})
|
2018-05-02 00:50:00 -04:00
|
|
|
if err != nil {
|
|
|
|
return objInfo, azureToObjectError(err, srcBucket, srcObject)
|
|
|
|
}
|
|
|
|
}
|
2019-12-02 12:32:19 -05:00
|
|
|
|
|
|
|
_, err = destBlob.SetHTTPHeaders(ctx, props, azblob.BlobAccessConditions{})
|
2017-09-29 13:58:40 -04:00
|
|
|
if err != nil {
|
2018-04-05 18:04:40 -04:00
|
|
|
return objInfo, azureToObjectError(err, srcBucket, srcObject)
|
2017-09-29 13:58:40 -04:00
|
|
|
}
|
2020-04-19 16:42:56 -04:00
|
|
|
|
|
|
|
if _, ok := srcInfo.UserDefined["x-amz-storage-class"]; ok {
|
|
|
|
_, err = destBlob.SetTier(ctx, s3StorageClassToAzureTier(srcInfo.UserDefined["x-amz-storage-class"]),
|
|
|
|
azblob.LeaseAccessConditions{})
|
|
|
|
if err != nil {
|
|
|
|
return objInfo, azureToObjectError(err, srcBucket, srcObject)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-10 12:42:43 -04:00
|
|
|
return a.GetObjectInfo(ctx, destBucket, destObject, dstOpts)
|
2017-03-16 15:21:58 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// DeleteObject - Deletes a blob on azure container, uses Azure
|
2019-12-02 12:32:19 -05:00
|
|
|
// equivalent `BlobURL.Delete`.
|
2020-06-12 23:04:01 -04:00
|
|
|
func (a *azureObjects) DeleteObject(ctx context.Context, bucket, object string, opts minio.ObjectOptions) (minio.ObjectInfo, error) {
|
2019-12-02 12:32:19 -05:00
|
|
|
blob := a.client.NewContainerURL(bucket).NewBlobURL(object)
|
|
|
|
_, err := blob.Delete(ctx, azblob.DeleteSnapshotsOptionNone, azblob.BlobAccessConditions{})
|
2017-03-16 15:21:58 -04:00
|
|
|
if err != nil {
|
2020-06-12 23:04:01 -04:00
|
|
|
return minio.ObjectInfo{}, azureToObjectError(err, bucket, object)
|
2017-03-16 15:21:58 -04:00
|
|
|
}
|
2020-06-12 23:04:01 -04:00
|
|
|
return minio.ObjectInfo{
|
|
|
|
Bucket: bucket,
|
|
|
|
Name: object,
|
|
|
|
}, nil
|
2017-03-16 15:21:58 -04:00
|
|
|
}
|
|
|
|
|
2020-06-12 23:04:01 -04:00
|
|
|
func (a *azureObjects) DeleteObjects(ctx context.Context, bucket string, objects []minio.ObjectToDelete, opts minio.ObjectOptions) ([]minio.DeletedObject, []error) {
|
2019-05-13 15:25:49 -04:00
|
|
|
errs := make([]error, len(objects))
|
2020-06-12 23:04:01 -04:00
|
|
|
dobjects := make([]minio.DeletedObject, len(objects))
|
2019-05-13 15:25:49 -04:00
|
|
|
for idx, object := range objects {
|
2020-06-12 23:04:01 -04:00
|
|
|
_, errs[idx] = a.DeleteObject(ctx, bucket, object.ObjectName, opts)
|
|
|
|
if errs[idx] == nil {
|
|
|
|
dobjects[idx] = minio.DeletedObject{
|
|
|
|
ObjectName: object.ObjectName,
|
|
|
|
}
|
|
|
|
}
|
2019-05-13 15:25:49 -04:00
|
|
|
}
|
2020-06-12 23:04:01 -04:00
|
|
|
return dobjects, errs
|
2019-05-13 15:25:49 -04:00
|
|
|
}
|
|
|
|
|
2017-09-19 19:08:08 -04:00
|
|
|
// ListMultipartUploads - It's decided not to support List Multipart Uploads, hence returning empty result.
|
2018-03-14 15:01:47 -04:00
|
|
|
func (a *azureObjects) ListMultipartUploads(ctx context.Context, bucket, prefix, keyMarker, uploadIDMarker, delimiter string, maxUploads int) (result minio.ListMultipartsInfo, err error) {
|
2017-09-19 19:08:08 -04:00
|
|
|
// It's decided not to support List Multipart Uploads, hence returning empty result.
|
2017-03-16 15:21:58 -04:00
|
|
|
return result, nil
|
|
|
|
}
|
|
|
|
|
2017-09-19 19:08:08 -04:00
|
|
|
type azureMultipartMetadata struct {
|
|
|
|
Name string `json:"name"`
|
|
|
|
Metadata map[string]string `json:"metadata"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func getAzureMetadataObjectName(objectName, uploadID string) string {
|
|
|
|
return fmt.Sprintf(metadataObjectNameTemplate, uploadID, sha256.Sum256([]byte(objectName)))
|
|
|
|
}
|
|
|
|
|
2019-02-06 19:58:43 -05:00
|
|
|
// gets the name of part metadata file for multipart upload operations
|
|
|
|
func getAzureMetadataPartName(objectName, uploadID string, partID int) string {
|
|
|
|
partMetaPrefix := getAzureMetadataPartPrefix(uploadID, objectName)
|
|
|
|
return path.Join(partMetaPrefix, fmt.Sprintf("%d", partID))
|
|
|
|
}
|
|
|
|
|
|
|
|
// gets the prefix of part metadata file
|
|
|
|
func getAzureMetadataPartPrefix(uploadID, objectName string) string {
|
|
|
|
return fmt.Sprintf(metadataPartNamePrefix, uploadID, sha256.Sum256([]byte(objectName)))
|
|
|
|
}
|
|
|
|
|
2018-04-05 18:04:40 -04:00
|
|
|
func (a *azureObjects) checkUploadIDExists(ctx context.Context, bucketName, objectName, uploadID string) (err error) {
|
2019-12-02 12:32:19 -05:00
|
|
|
blobURL := a.client.NewContainerURL(bucketName).NewBlobURL(
|
2017-09-28 18:23:46 -04:00
|
|
|
getAzureMetadataObjectName(objectName, uploadID))
|
2019-12-02 12:32:19 -05:00
|
|
|
_, err = blobURL.GetProperties(ctx, azblob.BlobAccessConditions{})
|
2018-04-05 18:04:40 -04:00
|
|
|
err = azureToObjectError(err, bucketName, objectName)
|
2017-12-05 20:58:09 -05:00
|
|
|
oerr := minio.ObjectNotFound{
|
|
|
|
Bucket: bucketName,
|
|
|
|
Object: objectName,
|
|
|
|
}
|
2018-04-10 12:36:37 -04:00
|
|
|
if err == oerr {
|
2018-04-05 18:04:40 -04:00
|
|
|
err = minio.InvalidUploadID{
|
2017-12-05 20:58:09 -05:00
|
|
|
UploadID: uploadID,
|
2018-04-05 18:04:40 -04:00
|
|
|
}
|
2017-09-19 19:08:08 -04:00
|
|
|
}
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2019-12-02 12:32:19 -05:00
|
|
|
// NewMultipartUpload - Use Azure equivalent `BlobURL.Upload`.
|
2019-02-09 00:31:06 -05:00
|
|
|
func (a *azureObjects) NewMultipartUpload(ctx context.Context, bucket, object string, opts minio.ObjectOptions) (uploadID string, err error) {
|
2018-04-19 20:24:43 -04:00
|
|
|
uploadID, err = getAzureUploadID()
|
|
|
|
if err != nil {
|
|
|
|
logger.LogIf(ctx, err)
|
|
|
|
return "", err
|
|
|
|
}
|
2017-09-19 19:08:08 -04:00
|
|
|
metadataObject := getAzureMetadataObjectName(object, uploadID)
|
2017-03-16 15:21:58 -04:00
|
|
|
|
2017-09-19 19:08:08 -04:00
|
|
|
var jsonData []byte
|
2019-02-09 00:31:06 -05:00
|
|
|
if jsonData, err = json.Marshal(azureMultipartMetadata{Name: object, Metadata: opts.UserDefined}); err != nil {
|
2018-04-05 18:04:40 -04:00
|
|
|
logger.LogIf(ctx, err)
|
|
|
|
return "", err
|
2017-03-16 15:21:58 -04:00
|
|
|
}
|
2017-09-05 19:56:23 -04:00
|
|
|
|
2019-12-02 12:32:19 -05:00
|
|
|
blobURL := a.client.NewContainerURL(bucket).NewBlockBlobURL(metadataObject)
|
|
|
|
_, err = blobURL.Upload(ctx, bytes.NewReader(jsonData), azblob.BlobHTTPHeaders{}, azblob.Metadata{}, azblob.BlobAccessConditions{})
|
2017-09-19 19:08:08 -04:00
|
|
|
if err != nil {
|
2018-04-05 18:04:40 -04:00
|
|
|
return "", azureToObjectError(err, bucket, metadataObject)
|
2017-03-16 15:21:58 -04:00
|
|
|
}
|
2017-09-05 19:56:23 -04:00
|
|
|
|
2017-09-19 19:08:08 -04:00
|
|
|
return uploadID, nil
|
|
|
|
}
|
|
|
|
|
2020-06-01 14:12:18 -04:00
|
|
|
func (a *azureObjects) CopyObjectPart(ctx context.Context, srcBucket, srcObject, dstBucket, dstObject string, uploadID string, partID int,
|
|
|
|
startOffset int64, length int64, srcInfo minio.ObjectInfo, srcOpts, dstOpts minio.ObjectOptions) (info minio.PartInfo, err error) {
|
|
|
|
return a.PutObjectPart(ctx, dstBucket, dstObject, uploadID, partID, srcInfo.PutObjReader, dstOpts)
|
|
|
|
}
|
|
|
|
|
2019-12-02 12:32:19 -05:00
|
|
|
// PutObjectPart - Use Azure equivalent `BlobURL.StageBlock`.
|
2018-11-14 20:36:41 -05:00
|
|
|
func (a *azureObjects) PutObjectPart(ctx context.Context, bucket, object, uploadID string, partID int, r *minio.PutObjReader, opts minio.ObjectOptions) (info minio.PartInfo, err error) {
|
|
|
|
data := r.Reader
|
2018-04-05 18:04:40 -04:00
|
|
|
if err = a.checkUploadIDExists(ctx, bucket, object, uploadID); err != nil {
|
2017-09-19 19:08:08 -04:00
|
|
|
return info, err
|
|
|
|
}
|
|
|
|
|
2018-04-05 18:04:40 -04:00
|
|
|
if err = checkAzureUploadID(ctx, uploadID); err != nil {
|
2017-09-19 19:08:08 -04:00
|
|
|
return info, err
|
2017-03-16 15:21:58 -04:00
|
|
|
}
|
2017-05-22 18:42:00 -04:00
|
|
|
|
2019-02-06 19:58:43 -05:00
|
|
|
partMetaV1 := newPartMetaV1(uploadID, partID)
|
2019-12-02 12:32:19 -05:00
|
|
|
subPartSize, subPartNumber := int64(azureUploadChunkSize), 1
|
|
|
|
for remainingSize := data.Size(); remainingSize > 0; remainingSize -= subPartSize {
|
2017-09-05 19:56:23 -04:00
|
|
|
if remainingSize < subPartSize {
|
|
|
|
subPartSize = remainingSize
|
|
|
|
}
|
|
|
|
|
2019-02-06 19:58:43 -05:00
|
|
|
id := base64.StdEncoding.EncodeToString([]byte(minio.MustGetUUID()))
|
2019-12-02 12:32:19 -05:00
|
|
|
blobURL := a.client.NewContainerURL(bucket).NewBlockBlobURL(object)
|
|
|
|
body, err := ioutil.ReadAll(io.LimitReader(data, subPartSize))
|
|
|
|
if err != nil {
|
|
|
|
return info, azureToObjectError(err, bucket, object)
|
|
|
|
}
|
|
|
|
_, err = blobURL.StageBlock(ctx, id, bytes.NewReader(body), azblob.LeaseAccessConditions{}, nil)
|
2017-09-05 19:56:23 -04:00
|
|
|
if err != nil {
|
2018-04-05 18:04:40 -04:00
|
|
|
return info, azureToObjectError(err, bucket, object)
|
2017-09-05 19:56:23 -04:00
|
|
|
}
|
2019-09-30 21:42:18 -04:00
|
|
|
partMetaV1.BlockIDs = append(partMetaV1.BlockIDs, id)
|
2017-09-05 19:56:23 -04:00
|
|
|
subPartNumber++
|
2017-03-16 15:21:58 -04:00
|
|
|
}
|
|
|
|
|
2019-02-06 19:58:43 -05:00
|
|
|
partMetaV1.ETag = r.MD5CurrentHexString()
|
|
|
|
partMetaV1.Size = data.Size()
|
|
|
|
|
|
|
|
// maintain per part md5sum in a temporary part metadata file until upload
|
|
|
|
// is finalized.
|
|
|
|
metadataObject := getAzureMetadataPartName(object, uploadID, partID)
|
|
|
|
var jsonData []byte
|
|
|
|
if jsonData, err = json.Marshal(partMetaV1); err != nil {
|
|
|
|
logger.LogIf(ctx, err)
|
|
|
|
return info, err
|
|
|
|
}
|
|
|
|
|
2019-12-02 12:32:19 -05:00
|
|
|
blobURL := a.client.NewContainerURL(bucket).NewBlockBlobURL(metadataObject)
|
|
|
|
_, err = blobURL.Upload(ctx, bytes.NewReader(jsonData), azblob.BlobHTTPHeaders{}, azblob.Metadata{}, azblob.BlobAccessConditions{})
|
2019-02-06 19:58:43 -05:00
|
|
|
if err != nil {
|
|
|
|
return info, azureToObjectError(err, bucket, metadataObject)
|
|
|
|
}
|
|
|
|
|
2017-03-16 15:21:58 -04:00
|
|
|
info.PartNumber = partID
|
2019-02-06 19:58:43 -05:00
|
|
|
info.ETag = partMetaV1.ETag
|
2017-12-05 20:58:09 -05:00
|
|
|
info.LastModified = minio.UTCNow()
|
2017-09-19 15:40:27 -04:00
|
|
|
info.Size = data.Size()
|
2017-03-16 15:21:58 -04:00
|
|
|
return info, nil
|
|
|
|
}
|
|
|
|
|
2020-05-28 15:36:20 -04:00
|
|
|
// GetMultipartInfo returns multipart info of the uploadId of the object
|
|
|
|
func (a *azureObjects) GetMultipartInfo(ctx context.Context, bucket, object, uploadID string, opts minio.ObjectOptions) (result minio.MultipartInfo, err error) {
|
|
|
|
if err = a.checkUploadIDExists(ctx, bucket, object, uploadID); err != nil {
|
|
|
|
return result, err
|
|
|
|
}
|
|
|
|
|
|
|
|
result.Bucket = bucket
|
|
|
|
result.Object = object
|
|
|
|
result.UploadID = uploadID
|
|
|
|
return result, nil
|
|
|
|
}
|
|
|
|
|
2019-12-02 12:32:19 -05:00
|
|
|
// ListObjectParts - Use Azure equivalent `ContainerURL.ListBlobsHierarchySegment`.
|
2019-01-05 17:16:43 -05:00
|
|
|
func (a *azureObjects) ListObjectParts(ctx context.Context, bucket, object, uploadID string, partNumberMarker int, maxParts int, opts minio.ObjectOptions) (result minio.ListPartsInfo, err error) {
|
2018-04-05 18:04:40 -04:00
|
|
|
if err = a.checkUploadIDExists(ctx, bucket, object, uploadID); err != nil {
|
2017-09-19 19:08:08 -04:00
|
|
|
return result, err
|
2017-03-16 15:21:58 -04:00
|
|
|
}
|
|
|
|
|
2017-11-20 17:03:20 -05:00
|
|
|
result.Bucket = bucket
|
|
|
|
result.Object = object
|
|
|
|
result.UploadID = uploadID
|
|
|
|
result.MaxParts = maxParts
|
|
|
|
|
2019-12-02 12:32:19 -05:00
|
|
|
azureListMarker := ""
|
|
|
|
marker := azblob.Marker{Val: &azureListMarker}
|
|
|
|
|
2019-02-06 19:58:43 -05:00
|
|
|
var parts []minio.PartInfo
|
2019-12-02 12:32:19 -05:00
|
|
|
var delimiter string
|
2019-02-06 19:58:43 -05:00
|
|
|
maxKeys := maxPartsCount
|
|
|
|
if partNumberMarker == 0 {
|
|
|
|
maxKeys = maxParts
|
2017-11-27 20:42:27 -05:00
|
|
|
}
|
2019-02-06 19:58:43 -05:00
|
|
|
prefix := getAzureMetadataPartPrefix(uploadID, object)
|
2019-12-02 12:32:19 -05:00
|
|
|
containerURL := a.client.NewContainerURL(bucket)
|
|
|
|
resp, err := containerURL.ListBlobsHierarchySegment(ctx, marker, delimiter, azblob.ListBlobsSegmentOptions{
|
2019-02-06 19:58:43 -05:00
|
|
|
Prefix: prefix,
|
2019-12-02 12:32:19 -05:00
|
|
|
MaxResults: int32(maxKeys),
|
2019-02-06 19:58:43 -05:00
|
|
|
})
|
2017-11-20 17:03:20 -05:00
|
|
|
if err != nil {
|
2019-02-06 19:58:43 -05:00
|
|
|
return result, azureToObjectError(err, bucket, prefix)
|
|
|
|
}
|
|
|
|
|
2019-12-02 12:32:19 -05:00
|
|
|
for _, blob := range resp.Segment.BlobItems {
|
2019-02-06 19:58:43 -05:00
|
|
|
if delimiter == "" && !strings.HasPrefix(blob.Name, minio.GatewayMinioSysTmp) {
|
|
|
|
// We filter out non minio.GatewayMinioSysTmp entries in the recursive listing.
|
|
|
|
continue
|
2017-11-20 17:03:20 -05:00
|
|
|
}
|
2019-02-06 19:58:43 -05:00
|
|
|
// filter temporary metadata file for blob
|
|
|
|
if strings.HasSuffix(blob.Name, "azure.json") {
|
2017-11-20 17:03:20 -05:00
|
|
|
continue
|
|
|
|
}
|
2019-12-02 12:32:19 -05:00
|
|
|
if !isAzureMarker(*marker.Val) && blob.Name <= *marker.Val {
|
2019-02-06 19:58:43 -05:00
|
|
|
// If the application used ListObjectsV1 style marker then we
|
|
|
|
// skip all the entries till we reach the marker.
|
2017-11-20 17:03:20 -05:00
|
|
|
continue
|
|
|
|
}
|
2019-02-06 19:58:43 -05:00
|
|
|
partNumber, err := parseAzurePart(blob.Name, prefix)
|
|
|
|
if err != nil {
|
2018-04-05 18:04:40 -04:00
|
|
|
return result, azureToObjectError(fmt.Errorf("Unexpected error"), bucket, object)
|
2017-11-20 17:03:20 -05:00
|
|
|
}
|
2019-02-06 19:58:43 -05:00
|
|
|
var metadata partMetadataV1
|
2019-12-02 12:32:19 -05:00
|
|
|
blobURL := containerURL.NewBlobURL(blob.Name)
|
|
|
|
blob, err := blobURL.Download(ctx, 0, azblob.CountToEnd, azblob.BlobAccessConditions{}, false)
|
|
|
|
if err != nil {
|
2019-02-06 19:58:43 -05:00
|
|
|
return result, azureToObjectError(fmt.Errorf("Unexpected error"), bucket, object)
|
|
|
|
}
|
2019-12-02 12:32:19 -05:00
|
|
|
metadataReader := blob.Body(azblob.RetryReaderOptions{MaxRetryRequests: azureDownloadRetryAttempts})
|
2019-02-06 19:58:43 -05:00
|
|
|
if err = json.NewDecoder(metadataReader).Decode(&metadata); err != nil {
|
|
|
|
logger.LogIf(ctx, err)
|
|
|
|
return result, azureToObjectError(err, bucket, object)
|
|
|
|
}
|
|
|
|
parts = append(parts, minio.PartInfo{
|
|
|
|
PartNumber: partNumber,
|
|
|
|
Size: metadata.Size,
|
|
|
|
ETag: metadata.ETag,
|
|
|
|
})
|
2017-11-20 17:03:20 -05:00
|
|
|
}
|
2018-02-27 22:03:00 -05:00
|
|
|
sort.Slice(parts, func(i int, j int) bool {
|
2017-11-20 17:03:20 -05:00
|
|
|
return parts[i].PartNumber < parts[j].PartNumber
|
|
|
|
})
|
|
|
|
partsCount := 0
|
|
|
|
i := 0
|
|
|
|
if partNumberMarker != 0 {
|
|
|
|
// If the marker was set, skip the entries till the marker.
|
|
|
|
for _, part := range parts {
|
|
|
|
i++
|
|
|
|
if part.PartNumber == partNumberMarker {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for partsCount < maxParts && i < len(parts) {
|
|
|
|
result.Parts = append(result.Parts, parts[i])
|
|
|
|
i++
|
|
|
|
partsCount++
|
|
|
|
}
|
|
|
|
|
|
|
|
if i < len(parts) {
|
|
|
|
result.IsTruncated = true
|
|
|
|
if partsCount != 0 {
|
|
|
|
result.NextPartNumberMarker = result.Parts[partsCount-1].PartNumber
|
|
|
|
}
|
|
|
|
}
|
|
|
|
result.PartNumberMarker = partNumberMarker
|
2017-03-16 15:21:58 -04:00
|
|
|
return result, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// AbortMultipartUpload - Not Implemented.
|
|
|
|
// There is no corresponding API in azure to abort an incomplete upload. The uncommmitted blocks
|
|
|
|
// gets deleted after one week.
|
2018-03-14 15:01:47 -04:00
|
|
|
func (a *azureObjects) AbortMultipartUpload(ctx context.Context, bucket, object, uploadID string) (err error) {
|
2018-04-05 18:04:40 -04:00
|
|
|
if err = a.checkUploadIDExists(ctx, bucket, object, uploadID); err != nil {
|
2017-09-19 19:08:08 -04:00
|
|
|
return err
|
|
|
|
}
|
2019-02-06 19:58:43 -05:00
|
|
|
var partNumberMarker int
|
|
|
|
for {
|
|
|
|
lpi, err := a.ListObjectParts(ctx, bucket, object, uploadID, partNumberMarker, maxPartsCount, minio.ObjectOptions{})
|
|
|
|
if err != nil {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
for _, part := range lpi.Parts {
|
2019-12-02 12:32:19 -05:00
|
|
|
pblob := a.client.NewContainerURL(bucket).NewBlobURL(
|
2019-02-06 19:58:43 -05:00
|
|
|
getAzureMetadataPartName(object, uploadID, part.PartNumber))
|
2019-12-02 12:32:19 -05:00
|
|
|
pblob.Delete(ctx, azblob.DeleteSnapshotsOptionNone, azblob.BlobAccessConditions{})
|
2019-02-06 19:58:43 -05:00
|
|
|
}
|
|
|
|
partNumberMarker = lpi.NextPartNumberMarker
|
|
|
|
if !lpi.IsTruncated {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
2017-09-19 19:08:08 -04:00
|
|
|
|
2019-12-02 12:32:19 -05:00
|
|
|
blobURL := a.client.NewContainerURL(bucket).NewBlobURL(
|
2017-09-28 18:23:46 -04:00
|
|
|
getAzureMetadataObjectName(object, uploadID))
|
2019-12-02 12:32:19 -05:00
|
|
|
_, err = blobURL.Delete(ctx, azblob.DeleteSnapshotsOptionNone, azblob.BlobAccessConditions{})
|
|
|
|
return err
|
2017-03-16 15:21:58 -04:00
|
|
|
}
|
|
|
|
|
2019-12-02 12:32:19 -05:00
|
|
|
// CompleteMultipartUpload - Use Azure equivalent `BlobURL.CommitBlockList`.
|
2018-11-14 20:36:41 -05:00
|
|
|
func (a *azureObjects) CompleteMultipartUpload(ctx context.Context, bucket, object, uploadID string, uploadedParts []minio.CompletePart, opts minio.ObjectOptions) (objInfo minio.ObjectInfo, err error) {
|
2017-09-19 19:08:08 -04:00
|
|
|
metadataObject := getAzureMetadataObjectName(object, uploadID)
|
2018-04-05 18:04:40 -04:00
|
|
|
if err = a.checkUploadIDExists(ctx, bucket, object, uploadID); err != nil {
|
2017-09-19 19:08:08 -04:00
|
|
|
return objInfo, err
|
|
|
|
}
|
|
|
|
|
2018-04-05 18:04:40 -04:00
|
|
|
if err = checkAzureUploadID(ctx, uploadID); err != nil {
|
2017-09-19 19:08:08 -04:00
|
|
|
return objInfo, err
|
|
|
|
}
|
|
|
|
|
2019-12-02 12:32:19 -05:00
|
|
|
blobURL := a.client.NewContainerURL(bucket).NewBlobURL(metadataObject)
|
|
|
|
blob, err := blobURL.Download(ctx, 0, azblob.CountToEnd, azblob.BlobAccessConditions{}, false)
|
|
|
|
if err != nil {
|
2018-04-05 18:04:40 -04:00
|
|
|
return objInfo, azureToObjectError(err, bucket, metadataObject)
|
2017-09-19 19:08:08 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
var metadata azureMultipartMetadata
|
2019-12-02 12:32:19 -05:00
|
|
|
metadataReader := blob.Body(azblob.RetryReaderOptions{MaxRetryRequests: azureDownloadRetryAttempts})
|
2017-09-19 19:08:08 -04:00
|
|
|
if err = json.NewDecoder(metadataReader).Decode(&metadata); err != nil {
|
2018-04-05 18:04:40 -04:00
|
|
|
logger.LogIf(ctx, err)
|
|
|
|
return objInfo, azureToObjectError(err, bucket, metadataObject)
|
2017-03-16 15:21:58 -04:00
|
|
|
}
|
2017-09-05 19:56:23 -04:00
|
|
|
|
2019-12-02 12:32:19 -05:00
|
|
|
objBlob := a.client.NewContainerURL(bucket).NewBlockBlobURL(object)
|
2017-09-05 19:56:23 -04:00
|
|
|
|
2019-12-02 12:32:19 -05:00
|
|
|
var allBlocks []string
|
2017-09-05 19:56:23 -04:00
|
|
|
for i, part := range uploadedParts {
|
2019-02-06 19:58:43 -05:00
|
|
|
var partMetadata partMetadataV1
|
|
|
|
partMetadataObject := getAzureMetadataPartName(object, uploadID, part.PartNumber)
|
2019-12-02 12:32:19 -05:00
|
|
|
pblobURL := a.client.NewContainerURL(bucket).NewBlobURL(partMetadataObject)
|
|
|
|
pblob, err := pblobURL.Download(ctx, 0, azblob.CountToEnd, azblob.BlobAccessConditions{}, false)
|
|
|
|
if err != nil {
|
2019-02-06 19:58:43 -05:00
|
|
|
return objInfo, azureToObjectError(err, bucket, partMetadataObject)
|
2017-09-05 19:56:23 -04:00
|
|
|
}
|
|
|
|
|
2019-12-02 12:32:19 -05:00
|
|
|
partMetadataReader := pblob.Body(azblob.RetryReaderOptions{MaxRetryRequests: azureDownloadRetryAttempts})
|
2019-02-06 19:58:43 -05:00
|
|
|
if err = json.NewDecoder(partMetadataReader).Decode(&partMetadata); err != nil {
|
|
|
|
logger.LogIf(ctx, err)
|
|
|
|
return objInfo, azureToObjectError(err, bucket, partMetadataObject)
|
|
|
|
}
|
2017-09-05 19:56:23 -04:00
|
|
|
|
2019-02-06 19:58:43 -05:00
|
|
|
if partMetadata.ETag != part.ETag {
|
|
|
|
return objInfo, minio.InvalidPart{}
|
|
|
|
}
|
2019-12-02 12:32:19 -05:00
|
|
|
allBlocks = append(allBlocks, partMetadata.BlockIDs...)
|
2019-02-06 19:58:43 -05:00
|
|
|
if i < (len(uploadedParts)-1) && partMetadata.Size < azureS3MinPartSize {
|
2018-04-05 18:04:40 -04:00
|
|
|
return objInfo, minio.PartTooSmall{
|
|
|
|
PartNumber: uploadedParts[i].PartNumber,
|
2019-02-06 19:58:43 -05:00
|
|
|
PartSize: partMetadata.Size,
|
2018-04-05 18:04:40 -04:00
|
|
|
PartETag: uploadedParts[i].ETag,
|
|
|
|
}
|
2017-09-05 19:56:23 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-02 12:32:19 -05:00
|
|
|
objMetadata, objProperties, err := s3MetaToAzureProperties(ctx, metadata.Metadata)
|
2019-04-18 02:50:25 -04:00
|
|
|
if err != nil {
|
|
|
|
return objInfo, azureToObjectError(err, bucket, object)
|
|
|
|
}
|
2020-03-18 19:19:29 -04:00
|
|
|
objMetadata["md5sum"] = minio.ComputeCompleteMultipartMD5(uploadedParts)
|
2019-12-02 12:32:19 -05:00
|
|
|
|
|
|
|
_, err = objBlob.CommitBlockList(ctx, allBlocks, objProperties, objMetadata, azblob.BlobAccessConditions{})
|
2019-04-18 02:50:25 -04:00
|
|
|
if err != nil {
|
|
|
|
return objInfo, azureToObjectError(err, bucket, object)
|
2017-03-16 15:21:58 -04:00
|
|
|
}
|
2019-02-06 19:58:43 -05:00
|
|
|
var partNumberMarker int
|
|
|
|
for {
|
|
|
|
lpi, err := a.ListObjectParts(ctx, bucket, object, uploadID, partNumberMarker, maxPartsCount, minio.ObjectOptions{})
|
|
|
|
if err != nil {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
for _, part := range lpi.Parts {
|
2019-12-02 12:32:19 -05:00
|
|
|
pblob := a.client.NewContainerURL(bucket).NewBlobURL(
|
2019-02-06 19:58:43 -05:00
|
|
|
getAzureMetadataPartName(object, uploadID, part.PartNumber))
|
2019-12-02 12:32:19 -05:00
|
|
|
pblob.Delete(ctx, azblob.DeleteSnapshotsOptionNone, azblob.BlobAccessConditions{})
|
2019-02-06 19:58:43 -05:00
|
|
|
}
|
|
|
|
partNumberMarker = lpi.NextPartNumberMarker
|
|
|
|
if !lpi.IsTruncated {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-02 12:32:19 -05:00
|
|
|
_, derr := blobURL.Delete(ctx, azblob.DeleteSnapshotsOptionNone, azblob.BlobAccessConditions{})
|
2019-02-06 19:58:43 -05:00
|
|
|
logger.GetReqInfo(ctx).AppendTags("uploadID", uploadID)
|
|
|
|
logger.LogIf(ctx, derr)
|
|
|
|
|
2018-09-10 12:42:43 -04:00
|
|
|
return a.GetObjectInfo(ctx, bucket, object, minio.ObjectOptions{})
|
2017-03-16 15:21:58 -04:00
|
|
|
}
|
|
|
|
|
2018-02-09 18:19:30 -05:00
|
|
|
// SetBucketPolicy - Azure supports three types of container policies:
|
2019-12-02 12:32:19 -05:00
|
|
|
// azblob.PublicAccessContainer - readonly in minio terminology
|
|
|
|
// azblob.PublicAccessBlob - readonly without listing in minio terminology
|
|
|
|
// azblob.PublicAccessNone - none in minio terminology
|
2017-03-16 15:21:58 -04:00
|
|
|
// As the common denominator for minio and azure is readonly and none, we support
|
|
|
|
// these two policies at the bucket level.
|
2018-04-24 18:53:30 -04:00
|
|
|
func (a *azureObjects) SetBucketPolicy(ctx context.Context, bucket string, bucketPolicy *policy.Policy) error {
|
|
|
|
policyInfo, err := minio.PolicyToBucketAccessPolicy(bucketPolicy)
|
|
|
|
if err != nil {
|
|
|
|
// This should not happen.
|
|
|
|
logger.LogIf(ctx, err)
|
|
|
|
return azureToObjectError(err, bucket)
|
|
|
|
}
|
2017-05-02 15:27:25 -04:00
|
|
|
|
2018-04-24 18:53:30 -04:00
|
|
|
var policies []minio.BucketAccessPolicy
|
|
|
|
for prefix, policy := range miniogopolicy.GetPolicies(policyInfo.Statements, bucket, "") {
|
2017-12-05 20:58:09 -05:00
|
|
|
policies = append(policies, minio.BucketAccessPolicy{
|
2017-05-02 15:27:25 -04:00
|
|
|
Prefix: prefix,
|
|
|
|
Policy: policy,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
prefix := bucket + "/*" // For all objects inside the bucket.
|
|
|
|
if len(policies) != 1 {
|
2018-04-05 18:04:40 -04:00
|
|
|
return minio.NotImplemented{}
|
2017-05-02 15:27:25 -04:00
|
|
|
}
|
|
|
|
if policies[0].Prefix != prefix {
|
2018-04-05 18:04:40 -04:00
|
|
|
return minio.NotImplemented{}
|
2017-05-02 15:27:25 -04:00
|
|
|
}
|
2018-04-24 18:53:30 -04:00
|
|
|
if policies[0].Policy != miniogopolicy.BucketPolicyReadOnly {
|
2018-04-05 18:04:40 -04:00
|
|
|
return minio.NotImplemented{}
|
2017-05-02 15:27:25 -04:00
|
|
|
}
|
2019-12-02 12:32:19 -05:00
|
|
|
perm := azblob.PublicAccessContainer
|
|
|
|
container := a.client.NewContainerURL(bucket)
|
|
|
|
_, err = container.SetAccessPolicy(ctx, perm, nil, azblob.ContainerAccessConditions{})
|
2018-04-05 18:04:40 -04:00
|
|
|
return azureToObjectError(err, bucket)
|
2017-03-16 15:21:58 -04:00
|
|
|
}
|
|
|
|
|
2018-02-09 18:19:30 -05:00
|
|
|
// GetBucketPolicy - Get the container ACL and convert it to canonical []bucketAccessPolicy
|
2018-04-24 18:53:30 -04:00
|
|
|
func (a *azureObjects) GetBucketPolicy(ctx context.Context, bucket string) (*policy.Policy, error) {
|
2019-12-02 12:32:19 -05:00
|
|
|
container := a.client.NewContainerURL(bucket)
|
|
|
|
perm, err := container.GetAccessPolicy(ctx, azblob.LeaseAccessConditions{})
|
2017-05-02 15:27:25 -04:00
|
|
|
if err != nil {
|
2018-04-24 18:53:30 -04:00
|
|
|
return nil, azureToObjectError(err, bucket)
|
2017-05-02 15:27:25 -04:00
|
|
|
}
|
2018-04-24 18:53:30 -04:00
|
|
|
|
2019-12-02 12:32:19 -05:00
|
|
|
permAccessType := perm.BlobPublicAccess()
|
|
|
|
|
|
|
|
if permAccessType == azblob.PublicAccessNone {
|
2018-04-24 18:53:30 -04:00
|
|
|
return nil, minio.BucketPolicyNotFound{Bucket: bucket}
|
2019-12-02 12:32:19 -05:00
|
|
|
} else if permAccessType != azblob.PublicAccessContainer {
|
2018-04-24 18:53:30 -04:00
|
|
|
return nil, azureToObjectError(minio.NotImplemented{})
|
|
|
|
}
|
|
|
|
|
|
|
|
return &policy.Policy{
|
|
|
|
Version: policy.DefaultVersion,
|
|
|
|
Statements: []policy.Statement{
|
|
|
|
policy.NewStatement(
|
|
|
|
policy.Allow,
|
|
|
|
policy.NewPrincipal("*"),
|
|
|
|
policy.NewActionSet(
|
|
|
|
policy.GetBucketLocationAction,
|
|
|
|
policy.ListBucketAction,
|
|
|
|
policy.GetObjectAction,
|
|
|
|
),
|
|
|
|
policy.NewResourceSet(
|
|
|
|
policy.NewResource(bucket, ""),
|
|
|
|
policy.NewResource(bucket, "*"),
|
|
|
|
),
|
|
|
|
condition.NewFunctions(),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
}, nil
|
2017-03-16 15:21:58 -04:00
|
|
|
}
|
|
|
|
|
2018-02-09 18:19:30 -05:00
|
|
|
// DeleteBucketPolicy - Set the container ACL to "private"
|
2018-03-14 15:01:47 -04:00
|
|
|
func (a *azureObjects) DeleteBucketPolicy(ctx context.Context, bucket string) error {
|
2019-12-02 12:32:19 -05:00
|
|
|
perm := azblob.PublicAccessNone
|
|
|
|
containerURL := a.client.NewContainerURL(bucket)
|
|
|
|
_, err := containerURL.SetAccessPolicy(ctx, perm, nil, azblob.ContainerAccessConditions{})
|
2018-04-05 18:04:40 -04:00
|
|
|
return azureToObjectError(err)
|
2017-03-16 15:21:58 -04:00
|
|
|
}
|
2018-09-27 23:36:17 -04:00
|
|
|
|
|
|
|
// IsCompressionSupported returns whether compression is applicable for this layer.
|
|
|
|
func (a *azureObjects) IsCompressionSupported() bool {
|
|
|
|
return false
|
|
|
|
}
|
2019-12-28 11:54:43 -05:00
|
|
|
|
|
|
|
// IsReady returns whether the layer is ready to take requests.
|
|
|
|
func (a *azureObjects) IsReady(ctx context.Context) bool {
|
|
|
|
return minio.IsBackendOnline(ctx, a.httpClient, a.endpoint)
|
|
|
|
}
|