* locationStorageCheck - will ensure there is enough space left for object on * PUT operations, or will update metric on DELETE * NOTE: storage limit may not be exactly enforced in the case of concurrent * requests when near limit * @param {string} location - name of location to check quota * @
(location, updateSize, log, cb)
| 20 | * @return {undefined} |
| 21 | */ |
| 22 | function locationStorageCheck(location, updateSize, log, cb) { |
| 23 | const lc = config.locationConstraints; |
| 24 | const sizeLimitGB = lc[location] ? lc[location].sizeLimitGB : undefined; |
| 25 | if (updateSize === 0 || sizeLimitGB === undefined || sizeLimitGB === null) { |
| 26 | return cb(); |
| 27 | } |
| 28 | // no need to list location metric, since it should be decreased |
| 29 | if (updateSize < 0) { |
| 30 | return pushLocationMetric(location, updateSize, log, cb); |
| 31 | } |
| 32 | return getLocationMetric(location, log, (err, bytesStored) => { |
| 33 | if (err) { |
| 34 | log.error(`Error listing metrics from Utapi: ${err.message}`); |
| 35 | return cb(err); |
| 36 | } |
| 37 | const newStorageSize = parseInt(bytesStored, 10) + updateSize; |
| 38 | const sizeLimitBytes = _gbToBytes(sizeLimitGB); |
| 39 | if (sizeLimitBytes < newStorageSize) { |
| 40 | return cb(errorInstances.AccessDenied.customizeDescription( |
| 41 | `The assigned storage space limit for location ${location} ` + |
| 42 | 'will be exceeded')); |
| 43 | } |
| 44 | return pushLocationMetric(location, updateSize, log, cb); |
| 45 | }); |
| 46 | } |
| 47 | |
| 48 | module.exports = locationStorageCheck; |
nothing calls this directly
no test coverage detected