| 
									
										
										
										
											2016-07-18 03:32:05 +08:00
										 |  |  | /* | 
					
						
							| 
									
										
										
										
											2019-04-10 02:39:42 +08:00
										 |  |  |  * MinIO Cloud Storage, (C) 2016 MinIO, Inc. | 
					
						
							| 
									
										
										
										
											2016-07-18 03:32:05 +08: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-19 07:23:42 +08:00
										 |  |  | package cmd | 
					
						
							| 
									
										
										
										
											2016-07-18 03:32:05 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | import ( | 
					
						
							|  |  |  | 	"net/http" | 
					
						
							| 
									
										
										
										
											2019-02-24 14:14:24 +08:00
										 |  |  | 	"strings" | 
					
						
							| 
									
										
										
										
											2016-07-18 03:32:05 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	"github.com/gorilla/mux" | 
					
						
							| 
									
										
										
										
											2018-08-18 03:52:14 +08:00
										 |  |  | 	"github.com/minio/minio/cmd/crypto" | 
					
						
							| 
									
										
										
										
											2018-10-13 03:25:59 +08:00
										 |  |  | 	"github.com/minio/minio/cmd/logger" | 
					
						
							| 
									
										
										
										
											2018-08-18 03:52:14 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-28 06:12:34 +08:00
										 |  |  | 	"github.com/minio/minio/pkg/bucket/policy" | 
					
						
							| 
									
										
										
										
											2016-07-18 03:32:05 +08:00
										 |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // Validate all the ListObjects query arguments, returns an APIErrorCode
 | 
					
						
							|  |  |  | // if one of the args do not meet the required conditions.
 | 
					
						
							| 
									
										
										
										
											2019-04-10 02:39:42 +08:00
										 |  |  | // Special conditions required by MinIO server are as below
 | 
					
						
							| 
									
										
										
										
											2016-07-18 03:32:05 +08: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-16 09:35:41 +08:00
										 |  |  | func validateListObjectsArgs(marker, delimiter, encodingType string, maxKeys int) APIErrorCode { | 
					
						
							| 
									
										
										
										
											2016-07-18 03:32:05 +08:00
										 |  |  | 	// Max keys cannot be negative.
 | 
					
						
							|  |  |  | 	if maxKeys < 0 { | 
					
						
							|  |  |  | 		return ErrInvalidMaxKeys | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-24 14:14:24 +08:00
										 |  |  | 	if encodingType != "" { | 
					
						
							|  |  |  | 		// Only url encoding type is supported
 | 
					
						
							|  |  |  | 		if strings.ToLower(encodingType) != "url" { | 
					
						
							|  |  |  | 			return ErrInvalidEncodingMethod | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-18 03:32:05 +08:00
										 |  |  | 	return ErrNone | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-20 05:02:54 +08:00
										 |  |  | // ListBucketObjectVersions - GET Bucket Object versions
 | 
					
						
							|  |  |  | // You can use the versions subresource to list metadata about all
 | 
					
						
							|  |  |  | // of the versions of objects in a bucket.
 | 
					
						
							|  |  |  | func (api objectAPIHandlers) ListBucketObjectVersionsHandler(w http.ResponseWriter, r *http.Request) { | 
					
						
							|  |  |  | 	ctx := newContext(r, w, "ListBucketObjectVersions") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	defer logger.AuditLog(w, r, "ListBucketObjectVersions", 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 listBucketVersions query params to their native values.
 | 
					
						
							|  |  |  | 	// versionIDMarker is ignored here.
 | 
					
						
							|  |  |  | 	prefix, marker, delimiter, maxkeys, encodingType, _, errCode := getListBucketObjectVersionsArgs(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.
 | 
					
						
							| 
									
										
										
										
											2019-10-16 09:35:41 +08:00
										 |  |  | 	if s3Error := validateListObjectsArgs(marker, delimiter, encodingType, maxkeys); s3Error != ErrNone { | 
					
						
							| 
									
										
										
										
											2019-08-20 05:02:54 +08:00
										 |  |  | 		writeErrorResponse(ctx, w, errorCodes.ToAPIErr(s3Error), r.URL, guessIsBrowserReq(r)) | 
					
						
							|  |  |  | 		return | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	listObjects := objectAPI.ListObjects | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// 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.
 | 
					
						
							|  |  |  | 	listObjectsInfo, err := listObjects(ctx, bucket, prefix, marker, delimiter, maxkeys) | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		writeErrorResponse(ctx, w, toAPIError(ctx, err), r.URL, guessIsBrowserReq(r)) | 
					
						
							|  |  |  | 		return | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for i := range listObjectsInfo.Objects { | 
					
						
							|  |  |  | 		var actualSize int64 | 
					
						
							|  |  |  | 		if listObjectsInfo.Objects[i].IsCompressed() { | 
					
						
							|  |  |  | 			// Read the decompressed size from the meta.json.
 | 
					
						
							|  |  |  | 			actualSize = listObjectsInfo.Objects[i].GetActualSize() | 
					
						
							|  |  |  | 			if actualSize < 0 { | 
					
						
							|  |  |  | 				writeErrorResponse(ctx, w, errorCodes.ToAPIErr(ErrInvalidDecompressedSize), | 
					
						
							|  |  |  | 					r.URL, guessIsBrowserReq(r)) | 
					
						
							|  |  |  | 				return | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			// Set the info.Size to the actualSize.
 | 
					
						
							|  |  |  | 			listObjectsInfo.Objects[i].Size = actualSize | 
					
						
							|  |  |  | 		} else if crypto.IsEncrypted(listObjectsInfo.Objects[i].UserDefined) { | 
					
						
							|  |  |  | 			listObjectsInfo.Objects[i].ETag = getDecryptedETag(r.Header, listObjectsInfo.Objects[i], false) | 
					
						
							|  |  |  | 			listObjectsInfo.Objects[i].Size, err = listObjectsInfo.Objects[i].DecryptedSize() | 
					
						
							|  |  |  | 			if err != nil { | 
					
						
							|  |  |  | 				writeErrorResponse(ctx, w, toAPIError(ctx, err), r.URL, guessIsBrowserReq(r)) | 
					
						
							|  |  |  | 				return | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	response := generateListVersionsResponse(bucket, prefix, marker, delimiter, encodingType, maxkeys, listObjectsInfo) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Write success response.
 | 
					
						
							|  |  |  | 	writeSuccessResponseXML(w, encodeResponse(response)) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-21 17:54:49 +08: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 | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	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 | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for i := range listObjectsV2Info.Objects { | 
					
						
							|  |  |  | 		var actualSize int64 | 
					
						
							|  |  |  | 		if listObjectsV2Info.Objects[i].IsCompressed() { | 
					
						
							|  |  |  | 			// Read the decompressed size from the meta.json.
 | 
					
						
							|  |  |  | 			actualSize = listObjectsV2Info.Objects[i].GetActualSize() | 
					
						
							|  |  |  | 			if actualSize < 0 { | 
					
						
							|  |  |  | 				writeErrorResponse(ctx, w, errorCodes.ToAPIErr(ErrInvalidDecompressedSize), r.URL, guessIsBrowserReq(r)) | 
					
						
							|  |  |  | 				return | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			// Set the info.Size to the actualSize.
 | 
					
						
							|  |  |  | 			listObjectsV2Info.Objects[i].Size = actualSize | 
					
						
							|  |  |  | 		} else if crypto.IsEncrypted(listObjectsV2Info.Objects[i].UserDefined) { | 
					
						
							|  |  |  | 			listObjectsV2Info.Objects[i].ETag = getDecryptedETag(r.Header, listObjectsV2Info.Objects[i], false) | 
					
						
							|  |  |  | 			listObjectsV2Info.Objects[i].Size, err = listObjectsV2Info.Objects[i].DecryptedSize() | 
					
						
							|  |  |  | 			if err != nil { | 
					
						
							|  |  |  | 				writeErrorResponse(ctx, w, toAPIError(ctx, err), r.URL, guessIsBrowserReq(r)) | 
					
						
							|  |  |  | 				return | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	response := generateListObjectsV2Response(bucket, prefix, token, | 
					
						
							|  |  |  | 		listObjectsV2Info.NextContinuationToken, startAfter, | 
					
						
							|  |  |  | 		delimiter, encodingType, fetchOwner, listObjectsV2Info.IsTruncated, | 
					
						
							|  |  |  | 		maxKeys, listObjectsV2Info.Objects, listObjectsV2Info.Prefixes, true) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Write success response.
 | 
					
						
							|  |  |  | 	writeSuccessResponseXML(w, encodeResponse(response)) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-18 03:32:05 +08:00
										 |  |  | // ListObjectsV2Handler - GET Bucket (List Objects) Version 2.
 | 
					
						
							|  |  |  | // --------------------------
 | 
					
						
							| 
									
										
										
										
											2019-10-31 04:20:01 +08:00
										 |  |  | // This implementation of the GET operation returns some or all (up to 10000)
 | 
					
						
							| 
									
										
										
										
											2016-07-18 03:32:05 +08: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-10 02:39:42 +08:00
										 |  |  | // MinIO continues to support ListObjectsV1 for supporting legacy tools.
 | 
					
						
							| 
									
										
										
										
											2016-07-18 03:32:05 +08:00
										 |  |  | func (api objectAPIHandlers) ListObjectsV2Handler(w http.ResponseWriter, r *http.Request) { | 
					
						
							| 
									
										
										
										
											2018-07-21 09:46:32 +08:00
										 |  |  | 	ctx := newContext(r, w, "ListObjectsV2") | 
					
						
							| 
									
										
										
										
											2018-03-15 03:01:47 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-22 12:03:24 +08:00
										 |  |  | 	defer logger.AuditLog(w, r, "ListObjectsV2", mustGetClaimsFromToken(r)) | 
					
						
							| 
									
										
										
										
											2018-10-13 03:25:59 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-18 03:32:05 +08:00
										 |  |  | 	vars := mux.Vars(r) | 
					
						
							|  |  |  | 	bucket := vars["bucket"] | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-11 09:47:49 +08:00
										 |  |  | 	objectAPI := api.ObjectAPI() | 
					
						
							|  |  |  | 	if objectAPI == nil { | 
					
						
							| 
									
										
										
										
											2019-02-14 08:07:21 +08:00
										 |  |  | 		writeErrorResponse(ctx, w, errorCodes.ToAPIErr(ErrServerNotInitialized), r.URL, guessIsBrowserReq(r)) | 
					
						
							| 
									
										
										
										
											2016-08-11 09:47:49 +08:00
										 |  |  | 		return | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-25 06:53:30 +08:00
										 |  |  | 	if s3Error := checkRequestAuthType(ctx, r, policy.ListBucketAction, bucket, ""); s3Error != ErrNone { | 
					
						
							| 
									
										
										
										
											2019-02-14 08:07:21 +08:00
										 |  |  | 		writeErrorResponse(ctx, w, errorCodes.ToAPIErr(s3Error), r.URL, guessIsBrowserReq(r)) | 
					
						
							| 
									
										
										
										
											2016-07-18 03:32:05 +08:00
										 |  |  | 		return | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-11-22 05:51:05 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-26 03:35:43 +08:00
										 |  |  | 	urlValues := r.URL.Query() | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-18 03:32:05 +08:00
										 |  |  | 	// Extract all the listObjectsV2 query params to their native values.
 | 
					
						
							| 
									
										
										
										
											2019-02-24 14:14:24 +08:00
										 |  |  | 	prefix, token, startAfter, delimiter, fetchOwner, maxKeys, encodingType, errCode := getListObjectsV2Args(urlValues) | 
					
						
							| 
									
										
										
										
											2018-06-26 03:35:43 +08:00
										 |  |  | 	if errCode != ErrNone { | 
					
						
							| 
									
										
										
										
											2019-02-14 08:07:21 +08:00
										 |  |  | 		writeErrorResponse(ctx, w, errorCodes.ToAPIErr(errCode), r.URL, guessIsBrowserReq(r)) | 
					
						
							| 
									
										
										
										
											2018-06-26 03:35:43 +08:00
										 |  |  | 		return | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-07-18 03:32:05 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-11 01:44:38 +08:00
										 |  |  | 	// Validate the query params before beginning to serve the request.
 | 
					
						
							|  |  |  | 	// fetch-owner is not validated since it is a boolean
 | 
					
						
							| 
									
										
										
										
											2019-10-16 09:35:41 +08:00
										 |  |  | 	if s3Error := validateListObjectsArgs(token, delimiter, encodingType, maxKeys); s3Error != ErrNone { | 
					
						
							| 
									
										
										
										
											2019-02-14 08:07:21 +08:00
										 |  |  | 		writeErrorResponse(ctx, w, errorCodes.ToAPIErr(s3Error), r.URL, guessIsBrowserReq(r)) | 
					
						
							| 
									
										
										
										
											2016-07-18 03:32:05 +08:00
										 |  |  | 		return | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2019-02-12 17:25:52 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-29 05:14:06 +08:00
										 |  |  | 	listObjectsV2 := objectAPI.ListObjectsV2 | 
					
						
							| 
									
										
										
										
											2019-08-10 08:09:08 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-18 03:32:05 +08:00
										 |  |  | 	// Inititate a list objects operation based on the input params.
 | 
					
						
							|  |  |  | 	// On success would return back ListObjectsInfo object to be
 | 
					
						
							| 
									
										
										
										
											2018-06-29 07:02:02 +08:00
										 |  |  | 	// marshaled into S3 compatible XML header.
 | 
					
						
							| 
									
										
										
										
											2018-07-01 12:22:45 +08:00
										 |  |  | 	listObjectsV2Info, err := listObjectsV2(ctx, bucket, prefix, token, delimiter, maxKeys, fetchOwner, startAfter) | 
					
						
							| 
									
										
										
										
											2016-07-18 03:32:05 +08:00
										 |  |  | 	if err != nil { | 
					
						
							| 
									
										
										
										
											2019-02-14 08:07:21 +08:00
										 |  |  | 		writeErrorResponse(ctx, w, toAPIError(ctx, err), r.URL, guessIsBrowserReq(r)) | 
					
						
							| 
									
										
										
										
											2016-07-18 03:32:05 +08:00
										 |  |  | 		return | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-02 03:37:57 +08:00
										 |  |  | 	for i := range listObjectsV2Info.Objects { | 
					
						
							| 
									
										
										
										
											2018-09-28 11:36:17 +08:00
										 |  |  | 		var actualSize int64 | 
					
						
							|  |  |  | 		if listObjectsV2Info.Objects[i].IsCompressed() { | 
					
						
							|  |  |  | 			// Read the decompressed size from the meta.json.
 | 
					
						
							|  |  |  | 			actualSize = listObjectsV2Info.Objects[i].GetActualSize() | 
					
						
							|  |  |  | 			if actualSize < 0 { | 
					
						
							| 
									
										
										
										
											2019-02-14 08:07:21 +08:00
										 |  |  | 				writeErrorResponse(ctx, w, errorCodes.ToAPIErr(ErrInvalidDecompressedSize), r.URL, guessIsBrowserReq(r)) | 
					
						
							| 
									
										
										
										
											2018-09-28 11:36:17 +08:00
										 |  |  | 				return | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			// Set the info.Size to the actualSize.
 | 
					
						
							|  |  |  | 			listObjectsV2Info.Objects[i].Size = actualSize | 
					
						
							|  |  |  | 		} else if crypto.IsEncrypted(listObjectsV2Info.Objects[i].UserDefined) { | 
					
						
							| 
									
										
										
										
											2018-11-15 09:36:41 +08:00
										 |  |  | 			listObjectsV2Info.Objects[i].ETag = getDecryptedETag(r.Header, listObjectsV2Info.Objects[i], false) | 
					
						
							| 
									
										
										
										
											2018-03-02 03:37:57 +08:00
										 |  |  | 			listObjectsV2Info.Objects[i].Size, err = listObjectsV2Info.Objects[i].DecryptedSize() | 
					
						
							|  |  |  | 			if err != nil { | 
					
						
							| 
									
										
										
										
											2019-02-14 08:07:21 +08:00
										 |  |  | 				writeErrorResponse(ctx, w, toAPIError(ctx, err), r.URL, guessIsBrowserReq(r)) | 
					
						
							| 
									
										
										
										
											2018-03-02 03:37:57 +08:00
										 |  |  | 				return | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-21 17:54:49 +08:00
										 |  |  | 	response := generateListObjectsV2Response(bucket, prefix, token, | 
					
						
							|  |  |  | 		listObjectsV2Info.NextContinuationToken, startAfter, | 
					
						
							|  |  |  | 		delimiter, encodingType, fetchOwner, listObjectsV2Info.IsTruncated, | 
					
						
							|  |  |  | 		maxKeys, listObjectsV2Info.Objects, listObjectsV2Info.Prefixes, false) | 
					
						
							| 
									
										
										
										
											2017-01-06 16:37:00 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-18 03:32:05 +08:00
										 |  |  | 	// Write success response.
 | 
					
						
							| 
									
										
										
										
											2017-01-06 16:37:00 +08:00
										 |  |  | 	writeSuccessResponseXML(w, encodeResponse(response)) | 
					
						
							| 
									
										
										
										
											2016-07-18 03:32:05 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // ListObjectsV1Handler - GET Bucket (List Objects) Version 1.
 | 
					
						
							|  |  |  | // --------------------------
 | 
					
						
							| 
									
										
										
										
											2019-10-31 04:20:01 +08:00
										 |  |  | // This implementation of the GET operation returns some or all (up to 10000)
 | 
					
						
							| 
									
										
										
										
											2016-07-18 03:32:05 +08: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-21 09:46:32 +08:00
										 |  |  | 	ctx := newContext(r, w, "ListObjectsV1") | 
					
						
							| 
									
										
										
										
											2018-03-15 03:01:47 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-22 12:03:24 +08:00
										 |  |  | 	defer logger.AuditLog(w, r, "ListObjectsV1", mustGetClaimsFromToken(r)) | 
					
						
							| 
									
										
										
										
											2018-10-13 03:25:59 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-18 03:32:05 +08:00
										 |  |  | 	vars := mux.Vars(r) | 
					
						
							|  |  |  | 	bucket := vars["bucket"] | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-11 09:47:49 +08:00
										 |  |  | 	objectAPI := api.ObjectAPI() | 
					
						
							|  |  |  | 	if objectAPI == nil { | 
					
						
							| 
									
										
										
										
											2019-02-14 08:07:21 +08:00
										 |  |  | 		writeErrorResponse(ctx, w, errorCodes.ToAPIErr(ErrServerNotInitialized), r.URL, guessIsBrowserReq(r)) | 
					
						
							| 
									
										
										
										
											2016-08-11 09:47:49 +08:00
										 |  |  | 		return | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-25 06:53:30 +08:00
										 |  |  | 	if s3Error := checkRequestAuthType(ctx, r, policy.ListBucketAction, bucket, ""); s3Error != ErrNone { | 
					
						
							| 
									
										
										
										
											2019-02-14 08:07:21 +08:00
										 |  |  | 		writeErrorResponse(ctx, w, errorCodes.ToAPIErr(s3Error), r.URL, guessIsBrowserReq(r)) | 
					
						
							| 
									
										
										
										
											2016-07-18 03:32:05 +08:00
										 |  |  | 		return | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Extract all the litsObjectsV1 query params to their native values.
 | 
					
						
							| 
									
										
										
										
											2019-02-24 14:14:24 +08:00
										 |  |  | 	prefix, marker, delimiter, maxKeys, encodingType, s3Error := getListObjectsV1Args(r.URL.Query()) | 
					
						
							| 
									
										
										
										
											2018-10-18 22:31:46 +08:00
										 |  |  | 	if s3Error != ErrNone { | 
					
						
							| 
									
										
										
										
											2019-02-14 08:07:21 +08:00
										 |  |  | 		writeErrorResponse(ctx, w, errorCodes.ToAPIErr(s3Error), r.URL, guessIsBrowserReq(r)) | 
					
						
							| 
									
										
										
										
											2018-10-18 22:31:46 +08:00
										 |  |  | 		return | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-07-18 03:32:05 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-12 17:25:52 +08:00
										 |  |  | 	// Validate all the query params before beginning to serve the request.
 | 
					
						
							| 
									
										
										
										
											2019-10-16 09:35:41 +08:00
										 |  |  | 	if s3Error := validateListObjectsArgs(marker, delimiter, encodingType, maxKeys); s3Error != ErrNone { | 
					
						
							| 
									
										
										
										
											2019-02-14 08:07:21 +08:00
										 |  |  | 		writeErrorResponse(ctx, w, errorCodes.ToAPIErr(s3Error), r.URL, guessIsBrowserReq(r)) | 
					
						
							| 
									
										
										
										
											2016-07-18 03:32:05 +08:00
										 |  |  | 		return | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2019-02-12 17:25:52 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-29 05:14:06 +08:00
										 |  |  | 	listObjects := objectAPI.ListObjects | 
					
						
							| 
									
										
										
										
											2019-02-12 17:25:52 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-18 03:32:05 +08:00
										 |  |  | 	// Inititate a list objects operation based on the input params.
 | 
					
						
							|  |  |  | 	// On success would return back ListObjectsInfo object to be
 | 
					
						
							| 
									
										
										
										
											2018-06-29 07:02:02 +08:00
										 |  |  | 	// marshaled into S3 compatible XML header.
 | 
					
						
							| 
									
										
										
										
											2018-03-29 05:14:06 +08:00
										 |  |  | 	listObjectsInfo, err := listObjects(ctx, bucket, prefix, marker, delimiter, maxKeys) | 
					
						
							| 
									
										
										
										
											2016-07-18 03:32:05 +08:00
										 |  |  | 	if err != nil { | 
					
						
							| 
									
										
										
										
											2019-02-14 08:07:21 +08:00
										 |  |  | 		writeErrorResponse(ctx, w, toAPIError(ctx, err), r.URL, guessIsBrowserReq(r)) | 
					
						
							| 
									
										
										
										
											2016-07-18 03:32:05 +08:00
										 |  |  | 		return | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-03-02 03:37:57 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	for i := range listObjectsInfo.Objects { | 
					
						
							| 
									
										
										
										
											2018-09-28 11:36:17 +08:00
										 |  |  | 		var actualSize int64 | 
					
						
							|  |  |  | 		if listObjectsInfo.Objects[i].IsCompressed() { | 
					
						
							|  |  |  | 			// Read the decompressed size from the meta.json.
 | 
					
						
							|  |  |  | 			actualSize = listObjectsInfo.Objects[i].GetActualSize() | 
					
						
							|  |  |  | 			if actualSize < 0 { | 
					
						
							| 
									
										
										
										
											2019-02-14 08:07:21 +08:00
										 |  |  | 				writeErrorResponse(ctx, w, errorCodes.ToAPIErr(ErrInvalidDecompressedSize), r.URL, guessIsBrowserReq(r)) | 
					
						
							| 
									
										
										
										
											2018-09-28 11:36:17 +08:00
										 |  |  | 				return | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			// Set the info.Size to the actualSize.
 | 
					
						
							|  |  |  | 			listObjectsInfo.Objects[i].Size = actualSize | 
					
						
							|  |  |  | 		} else if crypto.IsEncrypted(listObjectsInfo.Objects[i].UserDefined) { | 
					
						
							| 
									
										
										
										
											2018-11-15 09:36:41 +08:00
										 |  |  | 			listObjectsInfo.Objects[i].ETag = getDecryptedETag(r.Header, listObjectsInfo.Objects[i], false) | 
					
						
							| 
									
										
										
										
											2018-03-02 03:37:57 +08:00
										 |  |  | 			listObjectsInfo.Objects[i].Size, err = listObjectsInfo.Objects[i].DecryptedSize() | 
					
						
							|  |  |  | 			if err != nil { | 
					
						
							| 
									
										
										
										
											2019-02-14 08:07:21 +08:00
										 |  |  | 				writeErrorResponse(ctx, w, toAPIError(ctx, err), r.URL, guessIsBrowserReq(r)) | 
					
						
							| 
									
										
										
										
											2018-03-02 03:37:57 +08:00
										 |  |  | 				return | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2019-02-24 14:14:24 +08:00
										 |  |  | 	response := generateListObjectsV1Response(bucket, prefix, marker, delimiter, encodingType, maxKeys, listObjectsInfo) | 
					
						
							| 
									
										
										
										
											2017-01-06 16:37:00 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-18 03:32:05 +08:00
										 |  |  | 	// Write success response.
 | 
					
						
							| 
									
										
										
										
											2017-01-06 16:37:00 +08:00
										 |  |  | 	writeSuccessResponseXML(w, encodeResponse(response)) | 
					
						
							| 
									
										
										
										
											2016-07-18 03:32:05 +08:00
										 |  |  | } |