| 31 | |
| 32 | const services = { |
| 33 | getService(authInfo, request, log, splitter, cb, overrideUserbucket) { |
| 34 | const canonicalID = authInfo.getCanonicalID(); |
| 35 | assert.strictEqual(typeof splitter, 'string'); |
| 36 | const prefix = `${canonicalID}${splitter}`; |
| 37 | const bucketUsers = overrideUserbucket || usersBucket; |
| 38 | // Note: we are limiting max keys on a bucket listing to 10000 |
| 39 | // AWS does not limit but they only allow 100 buckets |
| 40 | // (without special increase) |
| 41 | // TODO: Consider implementing pagination like object listing |
| 42 | // with respect to bucket listing so can go beyond 10000 |
| 43 | metadata.listObject(bucketUsers, { prefix, maxKeys: 10000 }, log, |
| 44 | (err, listResponse) => { |
| 45 | // If MD responds with NoSuchBucket, this means the |
| 46 | // hidden usersBucket has not yet been created for |
| 47 | // the domain. If this is the case, it means |
| 48 | // that no buckets in this domain have been created so |
| 49 | // it follows that this particular user has no buckets. |
| 50 | // So, the get service listing should not have any |
| 51 | // buckets to list. By returning an empty array, the |
| 52 | // getService API will just respond with the user info |
| 53 | // without listing any buckets. |
| 54 | if (err?.is?.NoSuchBucket) { |
| 55 | log.trace('no buckets found'); |
| 56 | // If we checked the old user bucket, that means we |
| 57 | // already checked the new user bucket. If neither the |
| 58 | // old user bucket or the new user bucket exist, no buckets |
| 59 | // have yet been created in the namespace so an empty |
| 60 | // listing should be returned |
| 61 | if (overrideUserbucket) { |
| 62 | return cb(null, [], splitter); |
| 63 | } |
| 64 | // Since there were no results from checking the |
| 65 | // new users bucket, we check the old users bucket |
| 66 | return this.getService(authInfo, request, log, |
| 67 | constants.oldSplitter, cb, oldUsersBucket); |
| 68 | } |
| 69 | if (err) { |
| 70 | log.error('error from metadata', { error: err }); |
| 71 | return cb(err); |
| 72 | } |
| 73 | return cb(null, listResponse.Contents, splitter); |
| 74 | }); |
| 75 | }, |
| 76 | |
| 77 | /** |
| 78 | * Check that hashedStream.completedHash matches header contentMd5. |