* Creates bucket * @param {AuthInfo} authInfo - Instance of AuthInfo class with * requester's info * @param {string} bucketName - name of bucket * @param {object} headers - request headers * @param {string} locationConstraint - locationConstraint provided in *
(authInfo, bucketName, headers,
locationConstraint, log, cb)
| 164 | * @return {undefined} |
| 165 | */ |
| 166 | function createBucket(authInfo, bucketName, headers, |
| 167 | locationConstraint, log, cb) { |
| 168 | // Prefer using undefined instead of null for unused properties so they are not present in metadata payload |
| 169 | log.trace('Creating bucket'); |
| 170 | assert.strictEqual(typeof bucketName, 'string'); |
| 171 | const canonicalID = authInfo.getCanonicalID(); |
| 172 | const ownerDisplayName = |
| 173 | authInfo.getAccountDisplayName(); |
| 174 | const creationDate = new Date().toJSON(); |
| 175 | const isNFSEnabled = headers['x-scal-nfs-enabled'] === 'true' || undefined; |
| 176 | const headerObjectLock = headers['x-amz-bucket-object-lock-enabled']; |
| 177 | const objectLockEnabled |
| 178 | = headerObjectLock && headerObjectLock.toLowerCase() === 'true'; |
| 179 | const bucket = new BucketInfo(bucketName, canonicalID, ownerDisplayName, |
| 180 | creationDate, BucketInfo.currentModelVersion(), undefined, undefined, undefined, undefined, |
| 181 | undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, isNFSEnabled, |
| 182 | undefined, undefined, objectLockEnabled); |
| 183 | let locationConstraintVal = null; |
| 184 | |
| 185 | if (locationConstraint) { |
| 186 | const [locationConstraintStr, ingestion] = |
| 187 | locationConstraint.split(zenkoSeparator); |
| 188 | if (locationConstraintStr) { |
| 189 | locationConstraintVal = locationConstraintStr; |
| 190 | bucket.setLocationConstraint(locationConstraintStr); |
| 191 | } |
| 192 | if (ingestion === 'ingest') { |
| 193 | bucket.enableIngestion(); |
| 194 | //automatically enable versioning for ingestion buckets |
| 195 | bucket.setVersioningConfiguration({ Status: 'Enabled' }); |
| 196 | } |
| 197 | } |
| 198 | if (objectLockEnabled) { |
| 199 | // default versioning configuration AWS sets |
| 200 | // when a bucket is created with object lock |
| 201 | const versioningConfiguration = { |
| 202 | Status: 'Enabled', |
| 203 | MfaDelete: 'Disabled', |
| 204 | }; |
| 205 | bucket.setVersioningConfiguration(versioningConfiguration); |
| 206 | } |
| 207 | const parseAclParams = { |
| 208 | headers, |
| 209 | resourceType: 'bucket', |
| 210 | acl: bucket.acl, |
| 211 | log, |
| 212 | }; |
| 213 | async.parallel({ |
| 214 | prepareNewBucketMD: function prepareNewBucketMD(callback) { |
| 215 | acl.parseAclFromHeaders(parseAclParams, (err, parsedACL) => { |
| 216 | if (err) { |
| 217 | log.debug('error parsing acl from headers', { |
| 218 | error: err, |
| 219 | }); |
| 220 | return callback(err); |
| 221 | } |
| 222 | bucket.setFullAcl(parsedACL); |
| 223 | return callback(null, bucket); |
no test coverage detected