@@ -8,14 +8,9 @@ const escapeForXml = s3middleware.escapeForXml;
88const { pushMetric } = require ( '../utapi/utilities' ) ;
99const versionIdUtils = versioning . VersionID ;
1010const monitoring = require ( '../utilities/monitoringHandler' ) ;
11- const { generateToken, decryptToken }
12- = require ( '../api/apiUtils/object/continueToken' ) ;
11+ const { generateToken, decryptToken } = require ( '../api/apiUtils/object/continueToken' ) ;
1312
14- // do not url encode the continuation tokens
15- const skipUrlEncoding = new Set ( [
16- 'ContinuationToken' ,
17- 'NextContinuationToken' ,
18- ] ) ;
13+ const xmlParamsToSkipUrlEncoding = new Set ( [ 'ContinuationToken' , 'NextContinuationToken' ] ) ;
1914
2015/* Sample XML response for GET bucket objects V2:
2116<ListBucketResult xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
@@ -122,17 +117,16 @@ function processVersions(bucketName, listParams, list) {
122117 { tag : 'IsTruncated' , value : isTruncated } ,
123118 ] ;
124119
125- const escapeXmlFn = listParams . encoding === 'url' ?
126- querystring . escape : escapeForXml ;
120+ const escapeXmlFn = listParams . encoding === 'url' ? querystring . escape : escapeForXml ;
127121 xmlParams . forEach ( p => {
128122 if ( p . value ) {
129123 const val = p . tag !== 'NextVersionIdMarker' || p . value === 'null' ?
130- p . value : versionIdUtils . encode ( p . value ) ;
124+ p . value :
125+ versionIdUtils . encode ( p . value ) ;
131126 xml . push ( `<${ p . tag } >${ escapeXmlFn ( val ) } </${ p . tag } >` ) ;
132127 }
133128 } ) ;
134- let lastKey = listParams . keyMarker ?
135- escapeXmlFn ( listParams . keyMarker ) : undefined ;
129+ let lastKey = listParams . keyMarker ? escapeXmlFn ( listParams . keyMarker ) : undefined ;
136130 list . Versions . forEach ( item => {
137131 const v = item . value ;
138132 const objectKey = escapeXmlFn ( item . key ) ;
@@ -143,7 +137,8 @@ function processVersions(bucketName, listParams, list) {
143137 `<Key>${ objectKey } </Key>` ,
144138 '<VersionId>' ,
145139 ( v . IsNull || v . VersionId === undefined ) ?
146- 'null' : versionIdUtils . encode ( v . VersionId ) ,
140+ 'null'
141+ : versionIdUtils . encode ( v . VersionId ) ,
147142 '</VersionId>' ,
148143 `<IsLatest>${ isLatest } </IsLatest>` ,
149144 `<LastModified>${ v . LastModified } </LastModified>` ,
@@ -182,31 +177,19 @@ function processMasterVersions(bucketName, listParams, list) {
182177 ] ;
183178
184179 if ( listParams . v2 ) {
185- xmlParams . push (
186- { tag : 'StartAfter' , value : listParams . startAfter || '' } ) ;
187- xmlParams . push (
188- { tag : 'FetchOwner' , value : `${ listParams . fetchOwner } ` } ) ;
189- xmlParams . push ( {
190- tag : 'ContinuationToken' ,
191- value : generateToken ( listParams . continuationToken ) || '' ,
192- } ) ;
193- xmlParams . push ( {
194- tag : 'NextContinuationToken' ,
195- value : generateToken ( list . NextContinuationToken ) ,
196- } ) ;
197- xmlParams . push ( {
198- tag : 'KeyCount' ,
199- value : list . Contents ? list . Contents . length : 0 ,
200- } ) ;
180+ xmlParams . push ( { tag : 'StartAfter' , value : listParams . startAfter || '' } ) ;
181+ xmlParams . push ( { tag : 'FetchOwner' , value : `${ listParams . fetchOwner } ` } ) ;
182+ xmlParams . push ( { tag : 'ContinuationToken' , value : generateToken ( listParams . continuationToken ) || '' , } ) ;
183+ xmlParams . push ( { tag : 'NextContinuationToken' , value : generateToken ( list . NextContinuationToken ) , } ) ;
184+ xmlParams . push ( { tag : 'KeyCount' , value : list . Contents ? list . Contents . length : 0 , } ) ;
201185 } else {
202186 xmlParams . push ( { tag : 'Marker' , value : listParams . marker || '' } ) ;
203187 xmlParams . push ( { tag : 'NextMarker' , value : list . NextMarker } ) ;
204188 }
205189
206- const escapeXmlFn = listParams . encoding === 'url' ?
207- querystring . escape : escapeForXml ;
190+ const escapeXmlFn = listParams . encoding === 'url' ? querystring . escape : escapeForXml ;
208191 xmlParams . forEach ( p => {
209- if ( p . value && skipUrlEncoding . has ( p . tag ) ) {
192+ if ( p . value && xmlParamsToSkipUrlEncoding . has ( p . tag ) ) {
210193 xml . push ( `<${ p . tag } >${ p . value } </${ p . tag } >` ) ;
211194 } else if ( p . value || p . tag === 'KeyCount' || p . tag === 'MaxKeys' ) {
212195 xml . push ( `<${ p . tag } >${ escapeXmlFn ( p . value ) } </${ p . tag } >` ) ;
@@ -246,10 +229,10 @@ function processMasterVersions(bucketName, listParams, list) {
246229 ) ;
247230 } ) ;
248231 list . CommonPrefixes . forEach ( item => {
249- const val = escapeXmlFn ( item ) ;
250- xml . push ( `<CommonPrefixes><Prefix>${ val } </Prefix></CommonPrefixes>` ) ;
232+ xml . push ( `<CommonPrefixes><Prefix>${ escapeXmlFn ( item ) } </Prefix></CommonPrefixes>` ) ;
251233 } ) ;
252234 xml . push ( '</ListBucketResult>' ) ;
235+
253236 return xml . join ( '' ) ;
254237}
255238
@@ -289,17 +272,13 @@ function bucketGet(authInfo, request, log, callback) {
289272 'List Type specified in Request' ) ) ;
290273 }
291274 if ( v2 ) {
292- log . addDefaultFields ( {
293- action : 'ListObjectsV2' ,
294- } ) ;
275+ log . addDefaultFields ( { action : 'ListObjectsV2' , } ) ;
295276 if ( request . serverAccessLog ) {
296277 // eslint-disable-next-line no-param-reassign
297278 request . serverAccessLog . analyticsAction = 'ListObjectsV2' ;
298279 }
299280 } else if ( params . versions !== undefined ) {
300- log . addDefaultFields ( {
301- action : 'ListObjectVersions' ,
302- } ) ;
281+ log . addDefaultFields ( { action : 'ListObjectVersions' , } ) ;
303282 if ( request . serverAccessLog ) {
304283 // eslint-disable-next-line no-param-reassign
305284 request . serverAccessLog . analyticsAction = 'ListObjectVersions' ;
@@ -308,16 +287,14 @@ function bucketGet(authInfo, request, log, callback) {
308287 log . debug ( 'processing request' , { method : 'bucketGet' } ) ;
309288 const encoding = params [ 'encoding-type' ] ;
310289 if ( encoding !== undefined && encoding !== 'url' ) {
311- monitoring . promMetrics (
312- 'GET' , bucketName , 400 , 'listBucket' ) ;
290+ monitoring . promMetrics ( 'GET' , bucketName , 400 , 'listBucket' ) ;
313291 return callback ( errorInstances . InvalidArgument . customizeDescription ( 'Invalid ' +
314292 'Encoding Method specified in Request' ) ) ;
315293 }
316- const requestMaxKeys = params [ 'max-keys' ] ?
317- Number . parseInt ( params [ 'max-keys' ] , 10 ) : 1000 ;
294+
295+ const requestMaxKeys = params [ 'max-keys' ] ? Number . parseInt ( params [ 'max-keys' ] , 10 ) : 1000 ;
318296 if ( Number . isNaN ( requestMaxKeys ) || requestMaxKeys < 0 ) {
319- monitoring . promMetrics (
320- 'GET' , bucketName , 400 , 'listBucket' ) ;
297+ monitoring . promMetrics ( 'GET' , bucketName , 400 , 'listBucket' ) ;
321298 return callback ( errors . InvalidArgument ) ;
322299 }
323300 // AWS only returns 1000 keys even if max keys are greater.
@@ -344,28 +321,26 @@ function bucketGet(authInfo, request, log, callback) {
344321 if ( v2 ) {
345322 listParams . v2 = true ;
346323 listParams . startAfter = params [ 'start-after' ] ;
347- listParams . continuationToken =
348- decryptToken ( params [ 'continuation-token' ] ) ;
324+ listParams . continuationToken = decryptToken ( params [ 'continuation-token' ] ) ;
349325 listParams . fetchOwner = params [ 'fetch-owner' ] === 'true' ;
350326 } else {
351327 listParams . marker = params . marker ;
352328 }
353329
354330 standardMetadataValidateBucket ( metadataValParams , request . actionImplicitDenies , log , ( err , bucket ) => {
355- const corsHeaders = collectCorsHeaders ( request . headers . origin ,
356- request . method , bucket ) ;
331+ const corsHeaders = collectCorsHeaders ( request . headers . origin , request . method , bucket ) ;
357332 if ( err ) {
358333 log . debug ( 'error processing request' , { error : err } ) ;
359- monitoring . promMetrics (
360- 'GET' , bucketName , err . code , 'listBucket' ) ;
334+ monitoring . promMetrics ( 'GET' , bucketName , err . code , 'listBucket' ) ;
361335 return callback ( err , null , corsHeaders ) ;
362336 }
363337 if ( params . versions !== undefined ) {
364338 listParams . listingType = 'DelimiterVersions' ;
365339 delete listParams . marker ;
366340 listParams . keyMarker = params [ 'key-marker' ] ;
367341 listParams . versionIdMarker = params [ 'version-id-marker' ] ?
368- versionIdUtils . decode ( params [ 'version-id-marker' ] ) : undefined ;
342+ versionIdUtils . decode ( params [ 'version-id-marker' ] ) :
343+ undefined ;
369344 }
370345 if ( ! requestMaxKeys ) {
371346 const emptyList = {
@@ -381,8 +356,7 @@ function bucketGet(authInfo, request, log, callback) {
381356 ( err , list ) => {
382357 if ( err ) {
383358 log . debug ( 'error processing request' , { error : err } ) ;
384- monitoring . promMetrics (
385- 'GET' , bucketName , err . code , 'listBucket' ) ;
359+ monitoring . promMetrics ( 'GET' , bucketName , err . code , 'listBucket' ) ;
386360 return callback ( err , null , corsHeaders ) ;
387361 }
388362 return handleResult ( listParams , requestMaxKeys , encoding , authInfo ,
0 commit comments