storj.io/minio@v0.0.0-20230509071714-0cbc90f649b1/cmd/api-resources.go (about)

     1  /*
     2   * MinIO Cloud Storage, (C) 2015, 2016, 2017, 2018 MinIO, Inc.
     3   *
     4   * Licensed under the Apache License, Version 2.0 (the "License");
     5   * you may not use this file except in compliance with the License.
     6   * You may obtain a copy of the License at
     7   *
     8   *     http://www.apache.org/licenses/LICENSE-2.0
     9   *
    10   * Unless required by applicable law or agreed to in writing, software
    11   * distributed under the License is distributed on an "AS IS" BASIS,
    12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13   * See the License for the specific language governing permissions and
    14   * limitations under the License.
    15   */
    16  
    17  package cmd
    18  
    19  import (
    20  	"encoding/base64"
    21  	"net/url"
    22  	"strconv"
    23  )
    24  
    25  // Parse bucket url queries
    26  func getListObjectsV1Args(values url.Values) (prefix, marker, delimiter string, maxkeys int, encodingType string, errCode APIErrorCode) {
    27  	errCode = ErrNone
    28  
    29  	if values.Get("max-keys") != "" {
    30  		var err error
    31  		if maxkeys, err = strconv.Atoi(values.Get("max-keys")); err != nil {
    32  			errCode = ErrInvalidMaxKeys
    33  			return
    34  		}
    35  	} else {
    36  		maxkeys = maxObjectList
    37  	}
    38  
    39  	prefix = trimLeadingSlash(values.Get("prefix"))
    40  	marker = trimLeadingSlash(values.Get("marker"))
    41  	delimiter = values.Get("delimiter")
    42  	encodingType = values.Get("encoding-type")
    43  	return
    44  }
    45  
    46  func getListBucketObjectVersionsArgs(values url.Values) (prefix, marker, delimiter string, maxkeys int, encodingType, versionIDMarker string, errCode APIErrorCode) {
    47  	errCode = ErrNone
    48  
    49  	if values.Get("max-keys") != "" {
    50  		var err error
    51  		if maxkeys, err = strconv.Atoi(values.Get("max-keys")); err != nil {
    52  			errCode = ErrInvalidMaxKeys
    53  			return
    54  		}
    55  	} else {
    56  		maxkeys = maxObjectList
    57  	}
    58  
    59  	prefix = trimLeadingSlash(values.Get("prefix"))
    60  	marker = trimLeadingSlash(values.Get("key-marker"))
    61  	delimiter = values.Get("delimiter")
    62  	encodingType = values.Get("encoding-type")
    63  	versionIDMarker = values.Get("version-id-marker")
    64  	return
    65  }
    66  
    67  // Parse bucket url queries for ListObjects V2.
    68  func getListObjectsV2Args(values url.Values) (prefix, token, startAfter, delimiter string, fetchOwner bool, maxkeys int, encodingType string, errCode APIErrorCode) {
    69  	errCode = ErrNone
    70  
    71  	// The continuation-token cannot be empty.
    72  	if val, ok := values["continuation-token"]; ok {
    73  		if len(val[0]) == 0 {
    74  			errCode = ErrIncorrectContinuationToken
    75  			return
    76  		}
    77  	}
    78  
    79  	if values.Get("max-keys") != "" {
    80  		var err error
    81  		if maxkeys, err = strconv.Atoi(values.Get("max-keys")); err != nil {
    82  			errCode = ErrInvalidMaxKeys
    83  			return
    84  		}
    85  	} else {
    86  		maxkeys = maxObjectList
    87  	}
    88  
    89  	prefix = trimLeadingSlash(values.Get("prefix"))
    90  	startAfter = trimLeadingSlash(values.Get("start-after"))
    91  	delimiter = values.Get("delimiter")
    92  	fetchOwner = values.Get("fetch-owner") == "true"
    93  	encodingType = values.Get("encoding-type")
    94  
    95  	if token = values.Get("continuation-token"); token != "" {
    96  		decodedToken, err := base64.StdEncoding.DecodeString(token)
    97  		if err != nil {
    98  			errCode = ErrIncorrectContinuationToken
    99  			return
   100  		}
   101  		token = string(decodedToken)
   102  	}
   103  	return
   104  }
   105  
   106  // Parse bucket url queries for ?uploads
   107  func getBucketMultipartResources(values url.Values) (prefix, keyMarker, uploadIDMarker, delimiter string, maxUploads int, encodingType string, errCode APIErrorCode) {
   108  	errCode = ErrNone
   109  
   110  	if values.Get("max-uploads") != "" {
   111  		var err error
   112  		if maxUploads, err = strconv.Atoi(values.Get("max-uploads")); err != nil {
   113  			errCode = ErrInvalidMaxUploads
   114  			return
   115  		}
   116  	} else {
   117  		maxUploads = maxUploadsList
   118  	}
   119  
   120  	prefix = trimLeadingSlash(values.Get("prefix"))
   121  	keyMarker = trimLeadingSlash(values.Get("key-marker"))
   122  	uploadIDMarker = values.Get("upload-id-marker")
   123  	delimiter = values.Get("delimiter")
   124  	encodingType = values.Get("encoding-type")
   125  	return
   126  }
   127  
   128  // Parse object url queries
   129  func getObjectResources(values url.Values) (uploadID string, partNumberMarker, maxParts int, encodingType string, errCode APIErrorCode) {
   130  	var err error
   131  	errCode = ErrNone
   132  
   133  	if values.Get("max-parts") != "" {
   134  		if maxParts, err = strconv.Atoi(values.Get("max-parts")); err != nil {
   135  			errCode = ErrInvalidMaxParts
   136  			return
   137  		}
   138  	} else {
   139  		maxParts = maxPartsList
   140  	}
   141  
   142  	if values.Get("part-number-marker") != "" {
   143  		if partNumberMarker, err = strconv.Atoi(values.Get("part-number-marker")); err != nil {
   144  			errCode = ErrInvalidPartNumberMarker
   145  			return
   146  		}
   147  	}
   148  
   149  	uploadID = values.Get("uploadId")
   150  	encodingType = values.Get("encoding-type")
   151  	return
   152  }