* Bucket Put Versioning - Create or update bucket Versioning * @param {AuthInfo} authInfo - Instance of AuthInfo class with requester's info * @param {object} request - http request object * @param {object} log - Werelogs logger * @param {function} callback - callback to server * @return {undef
(authInfo, request, log, callback)
| 94 | * @return {undefined} |
| 95 | */ |
| 96 | function bucketPutVersioning(authInfo, request, log, callback) { |
| 97 | log.debug('processing request', { method: 'bucketPutVersioning' }); |
| 98 | |
| 99 | const bucketName = request.bucketName; |
| 100 | const metadataValParams = { |
| 101 | authInfo, |
| 102 | bucketName, |
| 103 | requestType: request.apiMethods || 'bucketPutVersioning', |
| 104 | request, |
| 105 | }; |
| 106 | return waterfall([ |
| 107 | next => _parseXML(request, log, next), |
| 108 | next => standardMetadataValidateBucket(metadataValParams, request.actionImplicitDenies, log, |
| 109 | (err, bucket) => next(err, bucket)), // ignore extra null object, |
| 110 | (bucket, next) => parseString(request.post, (err, result) => { |
| 111 | // just for linting; there should not be any parsing error here |
| 112 | if (err) { |
| 113 | return next(err, bucket); |
| 114 | } |
| 115 | // prevent enabling versioning on an nfs exported bucket |
| 116 | if (bucket.isNFS()) { |
| 117 | const error = new Error(); |
| 118 | error.code = 'NFSBUCKET'; |
| 119 | return next(error); |
| 120 | } |
| 121 | // _checkBackendVersioningImplemented returns false if versioning |
| 122 | // is not implemented on the bucket backend |
| 123 | if (!_checkBackendVersioningImplemented(bucket)) { |
| 124 | log.debug(externalVersioningErrorMessage, |
| 125 | { method: 'bucketPutVersioning', |
| 126 | error: errors.NotImplemented }); |
| 127 | const error = errorInstances.NotImplemented.customizeDescription( |
| 128 | externalVersioningErrorMessage); |
| 129 | return next(error, bucket); |
| 130 | } |
| 131 | const versioningConfiguration = {}; |
| 132 | if (result.VersioningConfiguration.Status) { |
| 133 | versioningConfiguration.Status = |
| 134 | result.VersioningConfiguration.Status[0]; |
| 135 | } |
| 136 | if (result.VersioningConfiguration.MfaDelete) { |
| 137 | versioningConfiguration.MfaDelete = |
| 138 | result.VersioningConfiguration.MfaDelete[0]; |
| 139 | } |
| 140 | // the configuration has been checked before |
| 141 | return next(null, bucket, versioningConfiguration); |
| 142 | }), |
| 143 | (bucket, versioningConfiguration, next) => { |
| 144 | // check if replication is enabled if versioning is being suspended |
| 145 | const replicationConfig = bucket.getReplicationConfiguration(); |
| 146 | const isIngestionBucket = bucket.isIngestionBucket && bucket.isIngestionBucket(); |
| 147 | const invalidAction = |
| 148 | versioningConfiguration.Status === 'Suspended' |
| 149 | && (isIngestionBucket || replicationConfig?.rules?.some(r => r.enabled)); |
| 150 | if (invalidAction) { |
| 151 | const errorMsg = isIngestionBucket ? |
| 152 | ingestionVersioningErrorMessage : replicationVersioningErrorMessage; |
| 153 | next(errorInstances.InvalidBucketState |