MCPcopy Index your code
hub / github.com/scality/cloudserver / _validateStartRestore

Function _validateStartRestore

lib/api/apiUtils/object/coldStorage.js:81–121  ·  view source on GitHub ↗

* Check if restore can be done. * * @param {ObjectMD} objectMD - object metadata * @param {object} log - werelogs logger * @return {ArsenalError|undefined} - undefined if the conditions for RestoreObject are fulfilled

(objectMD, log)

Source from the content-addressed store, hash-verified

79 * @return {ArsenalError|undefined} - undefined if the conditions for RestoreObject are fulfilled
80 */
81function _validateStartRestore(objectMD, log) {
82 if (objectMD.archive?.restoreCompletedAt) {
83 if (new Date(objectMD.archive?.restoreWillExpireAt) < new Date(Date.now())) {
84 // return InvalidObjectState error if the restored object is expired
85 // but restore info md of this object has not yet been cleared
86 log.debug('The restored object already expired.',
87 {
88 archive: objectMD.archive,
89 method: '_validateStartRestore',
90 });
91 return errors.InvalidObjectState;
92 }
93
94 // If object is already restored, no further check is needed
95 // Furthermore, we cannot check if the location is cold, as the `dataStoreName` would have
96 // been reset.
97 return undefined;
98 }
99 const isLocationCold = locationConstraints[objectMD.dataStoreName]?.isCold;
100 if (!isLocationCold) {
101 // return InvalidObjectState error if the object is not in cold storage,
102 // not in cold storage means either location cold flag not exists or cold flag is explicit false
103 log.debug('The bucket of the object is not in a cold storage location.',
104 {
105 isLocationCold,
106 method: '_validateStartRestore',
107 });
108 return errors.InvalidObjectState;
109 }
110 if (objectMD.archive?.restoreRequestedAt) {
111 // return RestoreAlreadyInProgress error if the object is currently being restored
112 // check if archive.restoreRequestAt exists and archive.restoreCompletedAt not yet exists
113 log.debug('The object is currently being restored.',
114 {
115 archive: objectMD.archive,
116 method: '_validateStartRestore',
117 });
118 return errors.RestoreAlreadyInProgress;
119 }
120 return undefined;
121}
122
123/**
124 * Check if "put version id" is allowed

Callers 1

startRestoreFunction · 0.85

Calls 1

debugMethod · 0.80

Tested by

no test coverage detected