@@ -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 ) ;
@@ -144,7 +138,8 @@ function processVersions(bucketName, listParams, list) {
144138 `<Key>${ objectKey } </Key>` ,
145139 '<VersionId>' ,
146140 ( v . IsNull || v . VersionId === undefined ) ?
147- 'null' : versionIdUtils . encode ( v . VersionId ) ,
141+ 'null'
142+ : versionIdUtils . encode ( v . VersionId ) ,
148143 '</VersionId>' ,
149144 `<IsLatest>${ isLatest } </IsLatest>` ,
150145 `<LastModified>${ v . LastModified } </LastModified>` ,
@@ -186,31 +181,19 @@ function processMasterVersions(bucketName, listParams, list) {
186181 ] ;
187182
188183 if ( listParams . v2 ) {
189- xmlParams . push (
190- { tag : 'StartAfter' , value : listParams . startAfter || '' } ) ;
191- xmlParams . push (
192- { tag : 'FetchOwner' , value : `${ listParams . fetchOwner } ` } ) ;
193- xmlParams . push ( {
194- tag : 'ContinuationToken' ,
195- value : generateToken ( listParams . continuationToken ) || '' ,
196- } ) ;
197- xmlParams . push ( {
198- tag : 'NextContinuationToken' ,
199- value : generateToken ( list . NextContinuationToken ) ,
200- } ) ;
201- xmlParams . push ( {
202- tag : 'KeyCount' ,
203- value : list . Contents ? list . Contents . length : 0 ,
204- } ) ;
184+ xmlParams . push ( { tag : 'StartAfter' , value : listParams . startAfter || '' } ) ;
185+ xmlParams . push ( { tag : 'FetchOwner' , value : `${ listParams . fetchOwner } ` } ) ;
186+ xmlParams . push ( { tag : 'ContinuationToken' , value : generateToken ( listParams . continuationToken ) || '' } ) ;
187+ xmlParams . push ( { tag : 'NextContinuationToken' , value : generateToken ( list . NextContinuationToken ) } ) ;
188+ xmlParams . push ( { tag : 'KeyCount' , value : list . Contents ? list . Contents . length : 0 } ) ;
205189 } else {
206190 xmlParams . push ( { tag : 'Marker' , value : listParams . marker || '' } ) ;
207191 xmlParams . push ( { tag : 'NextMarker' , value : list . NextMarker } ) ;
208192 }
209193
210- const escapeXmlFn = listParams . encoding === 'url' ?
211- querystring . escape : escapeForXml ;
194+ const escapeXmlFn = listParams . encoding === 'url' ? querystring . escape : escapeForXml ;
212195 xmlParams . forEach ( p => {
213- if ( p . value && skipUrlEncoding . has ( p . tag ) ) {
196+ if ( p . value && xmlParamsToSkipUrlEncoding . has ( p . tag ) ) {
214197 xml . push ( `<${ p . tag } >${ p . value } </${ p . tag } >` ) ;
215198 } else if ( p . value || p . tag === 'KeyCount' || p . tag === 'MaxKeys' ) {
216199 xml . push ( `<${ p . tag } >${ escapeXmlFn ( p . value ) } </${ p . tag } >` ) ;
@@ -255,10 +238,10 @@ function processMasterVersions(bucketName, listParams, list) {
255238 ) ;
256239 } ) ;
257240 list . CommonPrefixes . forEach ( item => {
258- const val = escapeXmlFn ( item ) ;
259- xml . push ( `<CommonPrefixes><Prefix>${ val } </Prefix></CommonPrefixes>` ) ;
241+ xml . push ( `<CommonPrefixes><Prefix>${ escapeXmlFn ( item ) } </Prefix></CommonPrefixes>` ) ;
260242 } ) ;
261243 xml . push ( '</ListBucketResult>' ) ;
244+
262245 return xml . join ( '' ) ;
263246}
264247
@@ -349,17 +332,13 @@ function bucketGet(authInfo, request, log, callback) {
349332 'List Type specified in Request' ) ) ;
350333 }
351334 if ( v2 ) {
352- log . addDefaultFields ( {
353- action : 'ListObjectsV2' ,
354- } ) ;
335+ log . addDefaultFields ( { action : 'ListObjectsV2' } ) ;
355336 if ( request . serverAccessLog ) {
356337 // eslint-disable-next-line no-param-reassign
357338 request . serverAccessLog . analyticsAction = 'ListObjectsV2' ;
358339 }
359340 } else if ( params . versions !== undefined ) {
360- log . addDefaultFields ( {
361- action : 'ListObjectVersions' ,
362- } ) ;
341+ log . addDefaultFields ( { action : 'ListObjectVersions' } ) ;
363342 if ( request . serverAccessLog ) {
364343 // eslint-disable-next-line no-param-reassign
365344 request . serverAccessLog . analyticsAction = 'ListObjectVersions' ;
@@ -368,16 +347,14 @@ function bucketGet(authInfo, request, log, callback) {
368347 log . debug ( 'processing request' , { method : 'bucketGet' } ) ;
369348 const encoding = params [ 'encoding-type' ] ;
370349 if ( encoding !== undefined && encoding !== 'url' ) {
371- monitoring . promMetrics (
372- 'GET' , bucketName , 400 , 'listBucket' ) ;
350+ monitoring . promMetrics ( 'GET' , bucketName , 400 , 'listBucket' ) ;
373351 return callback ( errorInstances . InvalidArgument . customizeDescription ( 'Invalid ' +
374352 'Encoding Method specified in Request' ) ) ;
375353 }
376- const requestMaxKeys = params [ 'max-keys' ] ?
377- Number . parseInt ( params [ 'max-keys' ] , 10 ) : 1000 ;
354+
355+ const requestMaxKeys = params [ 'max-keys' ] ? Number . parseInt ( params [ 'max-keys' ] , 10 ) : 1000 ;
378356 if ( Number . isNaN ( requestMaxKeys ) || requestMaxKeys < 0 ) {
379- monitoring . promMetrics (
380- 'GET' , bucketName , 400 , 'listBucket' ) ;
357+ monitoring . promMetrics ( 'GET' , bucketName , 400 , 'listBucket' ) ;
381358 return callback ( errors . InvalidArgument ) ;
382359 }
383360 // AWS only returns 1000 keys even if max keys are greater.
@@ -405,8 +382,7 @@ function bucketGet(authInfo, request, log, callback) {
405382 if ( v2 ) {
406383 listParams . v2 = true ;
407384 listParams . startAfter = params [ 'start-after' ] ;
408- listParams . continuationToken =
409- decryptToken ( params [ 'continuation-token' ] ) ;
385+ listParams . continuationToken = decryptToken ( params [ 'continuation-token' ] ) ;
410386 listParams . fetchOwner = params [ 'fetch-owner' ] === 'true' ;
411387 } else {
412388 listParams . marker = params . marker ;
@@ -426,7 +402,8 @@ function bucketGet(authInfo, request, log, callback) {
426402 delete listParams . marker ;
427403 listParams . keyMarker = params [ 'key-marker' ] ;
428404 listParams . versionIdMarker = params [ 'version-id-marker' ] ?
429- versionIdUtils . decode ( params [ 'version-id-marker' ] ) : undefined ;
405+ versionIdUtils . decode ( params [ 'version-id-marker' ] ) :
406+ undefined ;
430407 }
431408
432409 if ( ! requestMaxKeys ) {
0 commit comments