* Check if "put version id" is allowed * * @param {ObjectMD} objMD - object metadata * @param {string} versionId - object's version id * @param {object} log - werelogs logger * @return {ArsenalError|undefined} - undefined if "put version id" is allowed
(objMD, versionId, log)
| 129 | * @return {ArsenalError|undefined} - undefined if "put version id" is allowed |
| 130 | */ |
| 131 | function validatePutVersionId(objMD, versionId, log) { |
| 132 | if (!objMD) { |
| 133 | const err = versionId ? errors.NoSuchVersion : errors.NoSuchKey; |
| 134 | log.error('error no object metadata found', { method: 'validatePutVersionId', versionId }); |
| 135 | return err; |
| 136 | } |
| 137 | |
| 138 | if (objMD.isDeleteMarker) { |
| 139 | log.error('version is a delete marker', { method: 'validatePutVersionId', versionId }); |
| 140 | return errors.MethodNotAllowed; |
| 141 | } |
| 142 | |
| 143 | const isLocationCold = locationConstraints[objMD.dataStoreName]?.isCold; |
| 144 | if (!isLocationCold) { |
| 145 | log.error('The object data is not stored in a cold storage location.', |
| 146 | { |
| 147 | isLocationCold, |
| 148 | dataStoreName: objMD.dataStoreName, |
| 149 | method: 'validatePutVersionId', |
| 150 | }); |
| 151 | return errors.InvalidObjectState; |
| 152 | } |
| 153 | |
| 154 | // make sure object archive restoration is in progress |
| 155 | // NOTE: we do not use putObjectVersion to update the restoration period. |
| 156 | if (!objMD.archive || !objMD.archive.restoreRequestedAt || !objMD.archive.restoreRequestedDays |
| 157 | || objMD.archive.restoreCompletedAt || objMD.archive.restoreWillExpireAt) { |
| 158 | log.error('object archive restoration is not in progress', |
| 159 | { method: 'validatePutVersionId', versionId }); |
| 160 | return errors.InvalidObjectState; |
| 161 | } |
| 162 | |
| 163 | return undefined; |
| 164 | } |
| 165 | |
| 166 | /** |
| 167 | * Check if the object is already restored, and update the expiration date accordingly: |
no test coverage detected