2016-07-17 15:32:05 -04:00
|
|
|
/*
|
2019-04-09 14:39:42 -04:00
|
|
|
* MinIO Cloud Storage, (C) 2016 MinIO, Inc.
|
2016-07-17 15:32:05 -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.
|
|
|
|
*/
|
|
|
|
|
2016-08-18 19:23:42 -04:00
|
|
|
package cmd
|
2016-07-17 15:32:05 -04:00
|
|
|
|
|
|
|
import (
|
2020-07-02 13:56:22 -04:00
|
|
|
"context"
|
2020-07-03 14:53:03 -04:00
|
|
|
"fmt"
|
2016-07-17 15:32:05 -04:00
|
|
|
"net/http"
|
2020-07-03 14:53:03 -04:00
|
|
|
"strconv"
|
2019-02-24 01:14:24 -05:00
|
|
|
"strings"
|
2016-07-17 15:32:05 -04:00
|
|
|
|
|
|
|
"github.com/gorilla/mux"
|
2018-10-12 15:25:59 -04:00
|
|
|
"github.com/minio/minio/cmd/logger"
|
2018-08-17 15:52:14 -04:00
|
|
|
|
2020-01-27 17:12:34 -05:00
|
|
|
"github.com/minio/minio/pkg/bucket/policy"
|
2020-08-14 14:56:35 -04:00
|
|
|
"github.com/minio/minio/pkg/sync/errgroup"
|
2016-07-17 15:32:05 -04:00
|
|
|
)
|
|
|
|
|
2020-08-14 14:56:35 -04:00
|
|
|
func concurrentDecryptETag(ctx context.Context, objects []ObjectInfo) {
|
|
|
|
inParallel := func(objects []ObjectInfo) {
|
|
|
|
g := errgroup.WithNErrs(len(objects))
|
|
|
|
for index := range objects {
|
|
|
|
index := index
|
|
|
|
g.Go(func() error {
|
|
|
|
objects[index].ETag = objects[index].GetActualETag(nil)
|
|
|
|
objects[index].Size, _ = objects[index].GetActualSize()
|
|
|
|
return nil
|
|
|
|
}, index)
|
|
|
|
}
|
|
|
|
g.Wait()
|
|
|
|
}
|
|
|
|
const maxConcurrent = 500
|
|
|
|
for {
|
|
|
|
if len(objects) < maxConcurrent {
|
|
|
|
inParallel(objects)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
inParallel(objects[:maxConcurrent])
|
|
|
|
objects = objects[maxConcurrent:]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-17 15:32:05 -04:00
|
|
|
// Validate all the ListObjects query arguments, returns an APIErrorCode
|
|
|
|
// if one of the args do not meet the required conditions.
|
2019-04-09 14:39:42 -04:00
|
|
|
// Special conditions required by MinIO server are as below
|
2016-07-17 15:32:05 -04:00
|
|
|
// - delimiter if set should be equal to '/', otherwise the request is rejected.
|
|
|
|
// - marker if set should have a common prefix with 'prefix' param, otherwise
|
|
|
|
// the request is rejected.
|
2019-10-15 21:35:41 -04:00
|
|
|
func validateListObjectsArgs(marker, delimiter, encodingType string, maxKeys int) APIErrorCode {
|
2016-07-17 15:32:05 -04:00
|
|
|
// Max keys cannot be negative.
|
|
|
|
if maxKeys < 0 {
|
|
|
|
return ErrInvalidMaxKeys
|
|
|
|
}
|
|
|
|
|
2019-02-24 01:14:24 -05:00
|
|
|
if encodingType != "" {
|
|
|
|
// Only url encoding type is supported
|
|
|
|
if strings.ToLower(encodingType) != "url" {
|
|
|
|
return ErrInvalidEncodingMethod
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-17 15:32:05 -04:00
|
|
|
return ErrNone
|
|
|
|
}
|
|
|
|
|
2020-06-12 23:04:01 -04:00
|
|
|
// ListObjectVersions - GET Bucket Object versions
|
2019-08-19 17:02:54 -04:00
|
|
|
// You can use the versions subresource to list metadata about all
|
|
|
|
// of the versions of objects in a bucket.
|
2020-06-12 23:04:01 -04:00
|
|
|
func (api objectAPIHandlers) ListObjectVersionsHandler(w http.ResponseWriter, r *http.Request) {
|
|
|
|
ctx := newContext(r, w, "ListObjectVersions")
|
2019-08-19 17:02:54 -04:00
|
|
|
|
2020-06-12 23:04:01 -04:00
|
|
|
defer logger.AuditLog(w, r, "ListObjectVersions", mustGetClaimsFromToken(r))
|
2019-08-19 17:02:54 -04:00
|
|
|
|
|
|
|
vars := mux.Vars(r)
|
|
|
|
bucket := vars["bucket"]
|
|
|
|
|
|
|
|
objectAPI := api.ObjectAPI()
|
|
|
|
if objectAPI == nil {
|
|
|
|
writeErrorResponse(ctx, w, errorCodes.ToAPIErr(ErrServerNotInitialized), r.URL, guessIsBrowserReq(r))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if s3Error := checkRequestAuthType(ctx, r, policy.ListBucketAction, bucket, ""); s3Error != ErrNone {
|
|
|
|
writeErrorResponse(ctx, w, errorCodes.ToAPIErr(s3Error), r.URL, guessIsBrowserReq(r))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
urlValues := r.URL.Query()
|
|
|
|
|
|
|
|
// Extract all the listBucketVersions query params to their native values.
|
2020-06-12 23:04:01 -04:00
|
|
|
prefix, marker, delimiter, maxkeys, encodingType, versionIDMarker, errCode := getListBucketObjectVersionsArgs(urlValues)
|
2019-08-19 17:02:54 -04:00
|
|
|
if errCode != ErrNone {
|
|
|
|
writeErrorResponse(ctx, w, errorCodes.ToAPIErr(errCode), r.URL, guessIsBrowserReq(r))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// Validate the query params before beginning to serve the request.
|
2019-10-15 21:35:41 -04:00
|
|
|
if s3Error := validateListObjectsArgs(marker, delimiter, encodingType, maxkeys); s3Error != ErrNone {
|
2019-08-19 17:02:54 -04:00
|
|
|
writeErrorResponse(ctx, w, errorCodes.ToAPIErr(s3Error), r.URL, guessIsBrowserReq(r))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-08-13 19:31:58 -04:00
|
|
|
if proxyRequestByBucket(ctx, w, r, bucket) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-06-12 23:04:01 -04:00
|
|
|
listObjectVersions := objectAPI.ListObjectVersions
|
2019-08-19 17:02:54 -04:00
|
|
|
|
2020-06-12 23:04:01 -04:00
|
|
|
// Inititate a list object versions operation based on the input params.
|
2019-08-19 17:02:54 -04:00
|
|
|
// On success would return back ListObjectsInfo object to be
|
|
|
|
// marshaled into S3 compatible XML header.
|
2020-06-12 23:04:01 -04:00
|
|
|
listObjectVersionsInfo, err := listObjectVersions(ctx, bucket, prefix, marker, versionIDMarker, delimiter, maxkeys)
|
2019-08-19 17:02:54 -04:00
|
|
|
if err != nil {
|
|
|
|
writeErrorResponse(ctx, w, toAPIError(ctx, err), r.URL, guessIsBrowserReq(r))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-08-14 14:56:35 -04:00
|
|
|
concurrentDecryptETag(ctx, listObjectVersionsInfo.Objects)
|
2019-08-19 17:02:54 -04:00
|
|
|
|
2020-06-12 23:04:01 -04:00
|
|
|
response := generateListVersionsResponse(bucket, prefix, marker, versionIDMarker, delimiter, encodingType, maxkeys, listObjectVersionsInfo)
|
2019-08-19 17:02:54 -04:00
|
|
|
|
|
|
|
// Write success response.
|
|
|
|
writeSuccessResponseXML(w, encodeResponse(response))
|
|
|
|
}
|
|
|
|
|
2019-11-21 04:54:49 -05:00
|
|
|
// ListObjectsV2MHandler - GET Bucket (List Objects) Version 2 with metadata.
|
|
|
|
// --------------------------
|
|
|
|
// This implementation of the GET operation returns some or all (up to 10000)
|
|
|
|
// of the objects in a bucket. You can use the request parame<ters as selection
|
|
|
|
// criteria to return a subset of the objects in a bucket.
|
|
|
|
//
|
|
|
|
// NOTE: It is recommended that this API to be used for application development.
|
|
|
|
// MinIO continues to support ListObjectsV1 and V2 for supporting legacy tools.
|
|
|
|
func (api objectAPIHandlers) ListObjectsV2MHandler(w http.ResponseWriter, r *http.Request) {
|
|
|
|
ctx := newContext(r, w, "ListObjectsV2M")
|
|
|
|
|
|
|
|
defer logger.AuditLog(w, r, "ListObjectsV2M", mustGetClaimsFromToken(r))
|
|
|
|
|
|
|
|
vars := mux.Vars(r)
|
|
|
|
bucket := vars["bucket"]
|
|
|
|
|
|
|
|
objectAPI := api.ObjectAPI()
|
|
|
|
if objectAPI == nil {
|
|
|
|
writeErrorResponse(ctx, w, errorCodes.ToAPIErr(ErrServerNotInitialized), r.URL, guessIsBrowserReq(r))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if s3Error := checkRequestAuthType(ctx, r, policy.ListBucketAction, bucket, ""); s3Error != ErrNone {
|
|
|
|
writeErrorResponse(ctx, w, errorCodes.ToAPIErr(s3Error), r.URL, guessIsBrowserReq(r))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
urlValues := r.URL.Query()
|
|
|
|
|
|
|
|
// Extract all the listObjectsV2 query params to their native values.
|
|
|
|
prefix, token, startAfter, delimiter, fetchOwner, maxKeys, encodingType, errCode := getListObjectsV2Args(urlValues)
|
|
|
|
if errCode != ErrNone {
|
|
|
|
writeErrorResponse(ctx, w, errorCodes.ToAPIErr(errCode), r.URL, guessIsBrowserReq(r))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// Validate the query params before beginning to serve the request.
|
|
|
|
// fetch-owner is not validated since it is a boolean
|
|
|
|
if s3Error := validateListObjectsArgs(token, delimiter, encodingType, maxKeys); s3Error != ErrNone {
|
|
|
|
writeErrorResponse(ctx, w, errorCodes.ToAPIErr(s3Error), r.URL, guessIsBrowserReq(r))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-07-03 14:53:03 -04:00
|
|
|
// Analyze continuation token and route the request accordingly
|
2020-07-03 22:27:13 -04:00
|
|
|
var success bool
|
|
|
|
token, success = proxyRequestByToken(ctx, w, r, token)
|
|
|
|
if success {
|
|
|
|
return
|
2020-07-02 13:56:22 -04:00
|
|
|
}
|
|
|
|
|
2019-11-21 04:54:49 -05:00
|
|
|
listObjectsV2 := objectAPI.ListObjectsV2
|
|
|
|
|
|
|
|
// Inititate a list objects operation based on the input params.
|
|
|
|
// On success would return back ListObjectsInfo object to be
|
|
|
|
// marshaled into S3 compatible XML header.
|
|
|
|
listObjectsV2Info, err := listObjectsV2(ctx, bucket, prefix, token, delimiter, maxKeys, fetchOwner, startAfter)
|
|
|
|
if err != nil {
|
|
|
|
writeErrorResponse(ctx, w, toAPIError(ctx, err), r.URL, guessIsBrowserReq(r))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-08-14 14:56:35 -04:00
|
|
|
concurrentDecryptETag(ctx, listObjectsV2Info.Objects)
|
2019-11-21 04:54:49 -05:00
|
|
|
|
2020-07-03 14:53:03 -04:00
|
|
|
// The next continuation token has id@node_index format to optimize paginated listing
|
2020-07-03 22:27:13 -04:00
|
|
|
nextContinuationToken := listObjectsV2Info.NextContinuationToken
|
|
|
|
if nextContinuationToken != "" && listObjectsV2Info.IsTruncated {
|
|
|
|
nextContinuationToken = fmt.Sprintf("%s@%d", listObjectsV2Info.NextContinuationToken, getLocalNodeIndex())
|
|
|
|
}
|
2020-07-03 14:53:03 -04:00
|
|
|
|
|
|
|
response := generateListObjectsV2Response(bucket, prefix, token, nextContinuationToken, startAfter,
|
2019-11-21 04:54:49 -05:00
|
|
|
delimiter, encodingType, fetchOwner, listObjectsV2Info.IsTruncated,
|
|
|
|
maxKeys, listObjectsV2Info.Objects, listObjectsV2Info.Prefixes, true)
|
|
|
|
|
|
|
|
// Write success response.
|
|
|
|
writeSuccessResponseXML(w, encodeResponse(response))
|
|
|
|
}
|
|
|
|
|
2016-07-17 15:32:05 -04:00
|
|
|
// ListObjectsV2Handler - GET Bucket (List Objects) Version 2.
|
|
|
|
// --------------------------
|
2019-10-30 16:20:01 -04:00
|
|
|
// This implementation of the GET operation returns some or all (up to 10000)
|
2016-07-17 15:32:05 -04:00
|
|
|
// of the objects in a bucket. You can use the request parameters as selection
|
|
|
|
// criteria to return a subset of the objects in a bucket.
|
|
|
|
//
|
|
|
|
// NOTE: It is recommended that this API to be used for application development.
|
2019-04-09 14:39:42 -04:00
|
|
|
// MinIO continues to support ListObjectsV1 for supporting legacy tools.
|
2016-07-17 15:32:05 -04:00
|
|
|
func (api objectAPIHandlers) ListObjectsV2Handler(w http.ResponseWriter, r *http.Request) {
|
2018-07-20 21:46:32 -04:00
|
|
|
ctx := newContext(r, w, "ListObjectsV2")
|
2018-03-14 15:01:47 -04:00
|
|
|
|
2018-11-21 23:03:24 -05:00
|
|
|
defer logger.AuditLog(w, r, "ListObjectsV2", mustGetClaimsFromToken(r))
|
2018-10-12 15:25:59 -04:00
|
|
|
|
2016-07-17 15:32:05 -04:00
|
|
|
vars := mux.Vars(r)
|
|
|
|
bucket := vars["bucket"]
|
|
|
|
|
2016-08-10 21:47:49 -04:00
|
|
|
objectAPI := api.ObjectAPI()
|
|
|
|
if objectAPI == nil {
|
2019-02-13 19:07:21 -05:00
|
|
|
writeErrorResponse(ctx, w, errorCodes.ToAPIErr(ErrServerNotInitialized), r.URL, guessIsBrowserReq(r))
|
2016-08-10 21:47:49 -04:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-04-24 18:53:30 -04:00
|
|
|
if s3Error := checkRequestAuthType(ctx, r, policy.ListBucketAction, bucket, ""); s3Error != ErrNone {
|
2019-02-13 19:07:21 -05:00
|
|
|
writeErrorResponse(ctx, w, errorCodes.ToAPIErr(s3Error), r.URL, guessIsBrowserReq(r))
|
2016-07-17 15:32:05 -04:00
|
|
|
return
|
|
|
|
}
|
2016-11-21 16:51:05 -05:00
|
|
|
|
2018-06-25 15:35:43 -04:00
|
|
|
urlValues := r.URL.Query()
|
|
|
|
|
2016-07-17 15:32:05 -04:00
|
|
|
// Extract all the listObjectsV2 query params to their native values.
|
2019-02-24 01:14:24 -05:00
|
|
|
prefix, token, startAfter, delimiter, fetchOwner, maxKeys, encodingType, errCode := getListObjectsV2Args(urlValues)
|
2018-06-25 15:35:43 -04:00
|
|
|
if errCode != ErrNone {
|
2019-02-13 19:07:21 -05:00
|
|
|
writeErrorResponse(ctx, w, errorCodes.ToAPIErr(errCode), r.URL, guessIsBrowserReq(r))
|
2018-06-25 15:35:43 -04:00
|
|
|
return
|
|
|
|
}
|
2016-07-17 15:32:05 -04:00
|
|
|
|
2016-09-10 13:44:38 -04:00
|
|
|
// Validate the query params before beginning to serve the request.
|
|
|
|
// fetch-owner is not validated since it is a boolean
|
2019-10-15 21:35:41 -04:00
|
|
|
if s3Error := validateListObjectsArgs(token, delimiter, encodingType, maxKeys); s3Error != ErrNone {
|
2019-02-13 19:07:21 -05:00
|
|
|
writeErrorResponse(ctx, w, errorCodes.ToAPIErr(s3Error), r.URL, guessIsBrowserReq(r))
|
2016-07-17 15:32:05 -04:00
|
|
|
return
|
|
|
|
}
|
2019-02-12 04:25:52 -05:00
|
|
|
|
2020-07-03 14:53:03 -04:00
|
|
|
// Analyze continuation token and route the request accordingly
|
2020-07-03 22:27:13 -04:00
|
|
|
var success bool
|
|
|
|
token, success = proxyRequestByToken(ctx, w, r, token)
|
|
|
|
if success {
|
|
|
|
return
|
2020-07-02 13:56:22 -04:00
|
|
|
}
|
|
|
|
|
2018-03-28 17:14:06 -04:00
|
|
|
listObjectsV2 := objectAPI.ListObjectsV2
|
2019-08-09 20:09:08 -04:00
|
|
|
|
2016-07-17 15:32:05 -04:00
|
|
|
// Inititate a list objects operation based on the input params.
|
|
|
|
// On success would return back ListObjectsInfo object to be
|
2018-06-28 19:02:02 -04:00
|
|
|
// marshaled into S3 compatible XML header.
|
2018-07-01 00:22:45 -04:00
|
|
|
listObjectsV2Info, err := listObjectsV2(ctx, bucket, prefix, token, delimiter, maxKeys, fetchOwner, startAfter)
|
2016-07-17 15:32:05 -04:00
|
|
|
if err != nil {
|
2019-02-13 19:07:21 -05:00
|
|
|
writeErrorResponse(ctx, w, toAPIError(ctx, err), r.URL, guessIsBrowserReq(r))
|
2016-07-17 15:32:05 -04:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-08-14 14:56:35 -04:00
|
|
|
concurrentDecryptETag(ctx, listObjectsV2Info.Objects)
|
2018-03-01 14:37:57 -05:00
|
|
|
|
2020-07-03 14:53:03 -04:00
|
|
|
// The next continuation token has id@node_index format to optimize paginated listing
|
2020-07-03 22:27:13 -04:00
|
|
|
nextContinuationToken := listObjectsV2Info.NextContinuationToken
|
|
|
|
if nextContinuationToken != "" && listObjectsV2Info.IsTruncated {
|
|
|
|
nextContinuationToken = fmt.Sprintf("%s@%d", listObjectsV2Info.NextContinuationToken, getLocalNodeIndex())
|
|
|
|
}
|
2020-07-03 14:53:03 -04:00
|
|
|
|
|
|
|
response := generateListObjectsV2Response(bucket, prefix, token, nextContinuationToken, startAfter,
|
2019-11-21 04:54:49 -05:00
|
|
|
delimiter, encodingType, fetchOwner, listObjectsV2Info.IsTruncated,
|
|
|
|
maxKeys, listObjectsV2Info.Objects, listObjectsV2Info.Prefixes, false)
|
2017-01-06 03:37:00 -05:00
|
|
|
|
2016-07-17 15:32:05 -04:00
|
|
|
// Write success response.
|
2017-01-06 03:37:00 -05:00
|
|
|
writeSuccessResponseXML(w, encodeResponse(response))
|
2016-07-17 15:32:05 -04:00
|
|
|
}
|
|
|
|
|
2020-07-03 14:53:03 -04:00
|
|
|
func getLocalNodeIndex() int {
|
|
|
|
if len(globalProxyEndpoints) == 0 {
|
|
|
|
return -1
|
|
|
|
}
|
|
|
|
for i, ep := range globalProxyEndpoints {
|
|
|
|
if ep.IsLocal {
|
|
|
|
return i
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return -1
|
2020-07-02 13:56:22 -04:00
|
|
|
}
|
|
|
|
|
2020-07-03 22:27:13 -04:00
|
|
|
func parseRequestToken(token string) (subToken string, nodeIndex int) {
|
|
|
|
if token == "" {
|
|
|
|
return token, -1
|
|
|
|
}
|
2020-07-03 14:53:03 -04:00
|
|
|
i := strings.Index(token, "@")
|
|
|
|
if i < 0 {
|
2020-07-03 22:27:13 -04:00
|
|
|
return token, -1
|
2020-07-03 14:53:03 -04:00
|
|
|
}
|
|
|
|
nodeIndex, err := strconv.Atoi(token[i+1:])
|
|
|
|
if err != nil {
|
2020-07-03 22:27:13 -04:00
|
|
|
return token, -1
|
2020-07-02 13:56:22 -04:00
|
|
|
}
|
2020-07-03 14:53:03 -04:00
|
|
|
subToken = token[:i]
|
2020-07-03 22:27:13 -04:00
|
|
|
return subToken, nodeIndex
|
|
|
|
}
|
|
|
|
|
|
|
|
func proxyRequestByToken(ctx context.Context, w http.ResponseWriter, r *http.Request, token string) (string, bool) {
|
|
|
|
subToken, nodeIndex := parseRequestToken(token)
|
|
|
|
if nodeIndex > 0 {
|
|
|
|
return subToken, proxyRequestByNodeIndex(ctx, w, r, nodeIndex)
|
|
|
|
}
|
|
|
|
return subToken, false
|
2020-07-03 14:53:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func proxyRequestByNodeIndex(ctx context.Context, w http.ResponseWriter, r *http.Request, index int) (success bool) {
|
|
|
|
if len(globalProxyEndpoints) == 0 {
|
2020-07-02 13:56:22 -04:00
|
|
|
return false
|
|
|
|
}
|
2020-07-03 14:53:03 -04:00
|
|
|
if index < 0 || index >= len(globalProxyEndpoints) {
|
2020-07-02 13:56:22 -04:00
|
|
|
return false
|
|
|
|
}
|
2020-07-03 14:53:03 -04:00
|
|
|
ep := globalProxyEndpoints[index]
|
|
|
|
if ep.IsLocal {
|
|
|
|
return false
|
2020-07-02 13:56:22 -04:00
|
|
|
}
|
2020-07-03 14:53:03 -04:00
|
|
|
return proxyRequest(ctx, w, r, ep)
|
|
|
|
}
|
|
|
|
|
|
|
|
func proxyRequestByBucket(ctx context.Context, w http.ResponseWriter, r *http.Request, bucket string) (success bool) {
|
|
|
|
return proxyRequestByNodeIndex(ctx, w, r, crcHashMod(bucket, len(globalProxyEndpoints)))
|
2020-07-02 13:56:22 -04:00
|
|
|
}
|
|
|
|
|
2016-07-17 15:32:05 -04:00
|
|
|
// ListObjectsV1Handler - GET Bucket (List Objects) Version 1.
|
|
|
|
// --------------------------
|
2019-10-30 16:20:01 -04:00
|
|
|
// This implementation of the GET operation returns some or all (up to 10000)
|
2016-07-17 15:32:05 -04:00
|
|
|
// of the objects in a bucket. You can use the request parameters as selection
|
|
|
|
// criteria to return a subset of the objects in a bucket.
|
|
|
|
//
|
|
|
|
func (api objectAPIHandlers) ListObjectsV1Handler(w http.ResponseWriter, r *http.Request) {
|
2018-07-20 21:46:32 -04:00
|
|
|
ctx := newContext(r, w, "ListObjectsV1")
|
2018-03-14 15:01:47 -04:00
|
|
|
|
2018-11-21 23:03:24 -05:00
|
|
|
defer logger.AuditLog(w, r, "ListObjectsV1", mustGetClaimsFromToken(r))
|
2018-10-12 15:25:59 -04:00
|
|
|
|
2016-07-17 15:32:05 -04:00
|
|
|
vars := mux.Vars(r)
|
|
|
|
bucket := vars["bucket"]
|
|
|
|
|
2016-08-10 21:47:49 -04:00
|
|
|
objectAPI := api.ObjectAPI()
|
|
|
|
if objectAPI == nil {
|
2019-02-13 19:07:21 -05:00
|
|
|
writeErrorResponse(ctx, w, errorCodes.ToAPIErr(ErrServerNotInitialized), r.URL, guessIsBrowserReq(r))
|
2016-08-10 21:47:49 -04:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-04-24 18:53:30 -04:00
|
|
|
if s3Error := checkRequestAuthType(ctx, r, policy.ListBucketAction, bucket, ""); s3Error != ErrNone {
|
2019-02-13 19:07:21 -05:00
|
|
|
writeErrorResponse(ctx, w, errorCodes.ToAPIErr(s3Error), r.URL, guessIsBrowserReq(r))
|
2016-07-17 15:32:05 -04:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// Extract all the litsObjectsV1 query params to their native values.
|
2019-02-24 01:14:24 -05:00
|
|
|
prefix, marker, delimiter, maxKeys, encodingType, s3Error := getListObjectsV1Args(r.URL.Query())
|
2018-10-18 10:31:46 -04:00
|
|
|
if s3Error != ErrNone {
|
2019-02-13 19:07:21 -05:00
|
|
|
writeErrorResponse(ctx, w, errorCodes.ToAPIErr(s3Error), r.URL, guessIsBrowserReq(r))
|
2018-10-18 10:31:46 -04:00
|
|
|
return
|
|
|
|
}
|
2016-07-17 15:32:05 -04:00
|
|
|
|
2019-02-12 04:25:52 -05:00
|
|
|
// Validate all the query params before beginning to serve the request.
|
2019-10-15 21:35:41 -04:00
|
|
|
if s3Error := validateListObjectsArgs(marker, delimiter, encodingType, maxKeys); s3Error != ErrNone {
|
2019-02-13 19:07:21 -05:00
|
|
|
writeErrorResponse(ctx, w, errorCodes.ToAPIErr(s3Error), r.URL, guessIsBrowserReq(r))
|
2016-07-17 15:32:05 -04:00
|
|
|
return
|
|
|
|
}
|
2019-02-12 04:25:52 -05:00
|
|
|
|
2020-07-03 14:53:03 -04:00
|
|
|
if proxyRequestByBucket(ctx, w, r, bucket) {
|
2020-07-02 13:56:22 -04:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-03-28 17:14:06 -04:00
|
|
|
listObjects := objectAPI.ListObjects
|
2019-02-12 04:25:52 -05:00
|
|
|
|
2016-07-17 15:32:05 -04:00
|
|
|
// Inititate a list objects operation based on the input params.
|
|
|
|
// On success would return back ListObjectsInfo object to be
|
2018-06-28 19:02:02 -04:00
|
|
|
// marshaled into S3 compatible XML header.
|
2018-03-28 17:14:06 -04:00
|
|
|
listObjectsInfo, err := listObjects(ctx, bucket, prefix, marker, delimiter, maxKeys)
|
2016-07-17 15:32:05 -04:00
|
|
|
if err != nil {
|
2019-02-13 19:07:21 -05:00
|
|
|
writeErrorResponse(ctx, w, toAPIError(ctx, err), r.URL, guessIsBrowserReq(r))
|
2016-07-17 15:32:05 -04:00
|
|
|
return
|
|
|
|
}
|
2018-03-01 14:37:57 -05:00
|
|
|
|
2020-08-14 14:56:35 -04:00
|
|
|
concurrentDecryptETag(ctx, listObjectsInfo.Objects)
|
2020-05-24 14:19:17 -04:00
|
|
|
|
2019-02-24 01:14:24 -05:00
|
|
|
response := generateListObjectsV1Response(bucket, prefix, marker, delimiter, encodingType, maxKeys, listObjectsInfo)
|
2017-01-06 03:37:00 -05:00
|
|
|
|
2016-07-17 15:32:05 -04:00
|
|
|
// Write success response.
|
2017-01-06 03:37:00 -05:00
|
|
|
writeSuccessResponseXML(w, encodeResponse(response))
|
2016-07-17 15:32:05 -04:00
|
|
|
}
|