Skip to content

Commit 1e8ce50

Browse files
authored
Merge f8f095b into 9674d4a
2 parents 9674d4a + f8f095b commit 1e8ce50

File tree

4 files changed

+32
-57
lines changed

4 files changed

+32
-57
lines changed

postinstall.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const pkg = require('./package.json');
22

3-
const version = parseFloat(process.version.substr(1));
3+
const version = parseFloat(process.version.substring(1));
44
const minimum = parseFloat(pkg.engines.node.match(/\d+/g).join('.'));
55

66
module.exports = function () {

src/Adapters/Files/GridFSBucketAdapter.js

+23-48
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,11 @@ export class GridFSBucketAdapter extends FilesAdapter {
2828
this._algorithm = 'aes-256-gcm';
2929
this._encryptionKey =
3030
encryptionKey !== undefined
31-
? crypto.createHash('sha256').update(String(encryptionKey)).digest('base64').substr(0, 32)
31+
? crypto
32+
.createHash('sha256')
33+
.update(String(encryptionKey))
34+
.digest('base64')
35+
.substring(0, 32)
3236
: null;
3337
const defaultMongoOptions = {
3438
useNewUrlParser: true,
@@ -138,8 +142,8 @@ export class GridFSBucketAdapter extends FilesAdapter {
138142
}
139143

140144
async rotateEncryptionKey(options = {}) {
141-
var fileNames = [];
142-
var oldKeyFileAdapter = {};
145+
let fileNames = [];
146+
let oldKeyFileAdapter = {};
143147
const bucket = await this._getBucket();
144148
if (options.oldKey !== undefined) {
145149
oldKeyFileAdapter = new GridFSBucketAdapter(
@@ -158,51 +162,22 @@ export class GridFSBucketAdapter extends FilesAdapter {
158162
fileNames.push(file.filename);
159163
});
160164
}
161-
return new Promise(resolve => {
162-
var fileNamesNotRotated = fileNames;
163-
var fileNamesRotated = [];
164-
var fileNameTotal = fileNames.length;
165-
var fileNameIndex = 0;
166-
fileNames.forEach(fileName => {
167-
oldKeyFileAdapter
168-
.getFileData(fileName)
169-
.then(plainTextData => {
170-
//Overwrite file with data encrypted with new key
171-
this.createFile(fileName, plainTextData)
172-
.then(() => {
173-
fileNamesRotated.push(fileName);
174-
fileNamesNotRotated = fileNamesNotRotated.filter(function (value) {
175-
return value !== fileName;
176-
});
177-
fileNameIndex += 1;
178-
if (fileNameIndex == fileNameTotal) {
179-
resolve({
180-
rotated: fileNamesRotated,
181-
notRotated: fileNamesNotRotated,
182-
});
183-
}
184-
})
185-
.catch(() => {
186-
fileNameIndex += 1;
187-
if (fileNameIndex == fileNameTotal) {
188-
resolve({
189-
rotated: fileNamesRotated,
190-
notRotated: fileNamesNotRotated,
191-
});
192-
}
193-
});
194-
})
195-
.catch(() => {
196-
fileNameIndex += 1;
197-
if (fileNameIndex == fileNameTotal) {
198-
resolve({
199-
rotated: fileNamesRotated,
200-
notRotated: fileNamesNotRotated,
201-
});
202-
}
203-
});
204-
});
205-
});
165+
let fileNamesNotRotated = fileNames;
166+
const fileNamesRotated = [];
167+
for (const fileName of fileNames) {
168+
try {
169+
const plainTextData = await oldKeyFileAdapter.getFileData(fileName);
170+
// Overwrite file with data encrypted with new key
171+
await this.createFile(fileName, plainTextData);
172+
fileNamesRotated.push(fileName);
173+
fileNamesNotRotated = fileNamesNotRotated.filter(function (value) {
174+
return value !== fileName;
175+
});
176+
} catch (err) {
177+
continue;
178+
}
179+
}
180+
return { rotated: fileNamesRotated, notRotated: fileNamesNotRotated };
206181
}
207182

208183
getFileLocation(config, filename) {

src/Adapters/Storage/Postgres/PostgresStorageAdapter.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ const transformAggregateField = fieldName => {
231231
if (fieldName === '$_updated_at') {
232232
return 'updatedAt';
233233
}
234-
return fieldName.substr(1);
234+
return fieldName.substring(1);
235235
};
236236

237237
const validateKeys = object => {
@@ -1921,14 +1921,14 @@ export class PostgresStorageAdapter implements StorageAdapter {
19211921
};
19221922
}
19231923
if (object[fieldName] && schema.fields[fieldName].type === 'Polygon') {
1924-
let coords = object[fieldName];
1925-
coords = coords.substr(2, coords.length - 4).split('),(');
1926-
coords = coords.map(point => {
1924+
let coords = new String(object[fieldName]);
1925+
coords = coords.substring(2, coords.length - 2).split('),(');
1926+
const updatedCoords = coords.map(point => {
19271927
return [parseFloat(point.split(',')[1]), parseFloat(point.split(',')[0])];
19281928
});
19291929
object[fieldName] = {
19301930
__type: 'Polygon',
1931-
coordinates: coords,
1931+
coordinates: updatedCoords,
19321932
};
19331933
}
19341934
if (object[fieldName] && schema.fields[fieldName].type === 'File') {
@@ -2634,7 +2634,7 @@ function literalizeRegexPart(s: string) {
26342634
const result1: any = s.match(matcher1);
26352635
if (result1 && result1.length > 1 && result1.index > -1) {
26362636
// process regex that has a beginning and an end specified for the literal text
2637-
const prefix = s.substr(0, result1.index);
2637+
const prefix = s.substring(0, result1.index);
26382638
const remaining = result1[1];
26392639

26402640
return literalizeRegexPart(prefix) + createLiteralRegex(remaining);
@@ -2644,7 +2644,7 @@ function literalizeRegexPart(s: string) {
26442644
const matcher2 = /\\Q((?!\\E).*)$/;
26452645
const result2: any = s.match(matcher2);
26462646
if (result2 && result2.length > 1 && result2.index > -1) {
2647-
const prefix = s.substr(0, result2.index);
2647+
const prefix = s.substring(0, result2.index);
26482648
const remaining = result2[1];
26492649

26502650
return literalizeRegexPart(prefix) + createLiteralRegex(remaining);

src/Config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ function removeTrailingSlash(str) {
2525
return str;
2626
}
2727
if (str.endsWith('/')) {
28-
str = str.substr(0, str.length - 1);
28+
str = str.substring(0, str.length - 1);
2929
}
3030
return str;
3131
}

0 commit comments

Comments
 (0)