Add config for objectId size (#3950)
* Add objectId config property, default to 10 * Update Config constructor * Add test for backwards compatibility when changing objectId size
This commit is contained in:
committed by
Natan Rolnik
parent
bd6816c14c
commit
51d2dd92cb
@@ -73,6 +73,7 @@ export class Config {
|
||||
this.generateSessionExpiresAt = this.generateSessionExpiresAt.bind(this);
|
||||
this.generateEmailVerifyTokenExpiresAt = this.generateEmailVerifyTokenExpiresAt.bind(this);
|
||||
this.revokeSessionOnPasswordReset = cacheInfo.revokeSessionOnPasswordReset;
|
||||
this.objectIdSize = cacheInfo.objectIdSize;
|
||||
}
|
||||
|
||||
static validate({
|
||||
|
||||
@@ -141,6 +141,7 @@ class ParseServer {
|
||||
revokeSessionOnPasswordReset = defaults.revokeSessionOnPasswordReset,
|
||||
schemaCacheTTL = defaults.schemaCacheTTL, // cache for 5s
|
||||
enableSingleSchemaCache = false,
|
||||
objectIdSize = defaults.objectIdSize,
|
||||
__indexBuildCompletionCallbackForTests = () => {},
|
||||
}) {
|
||||
// Initialize the node client SDK automatically
|
||||
@@ -262,7 +263,8 @@ class ParseServer {
|
||||
pushWorker,
|
||||
pushControllerQueue,
|
||||
hasPushSupport,
|
||||
hasPushScheduledSupport
|
||||
hasPushScheduledSupport,
|
||||
objectIdSize
|
||||
});
|
||||
|
||||
Config.validate(AppCache.get(appId));
|
||||
|
||||
@@ -187,7 +187,7 @@ RestWrite.prototype.setRequiredFieldsIfNeeded = function() {
|
||||
|
||||
// Only assign new objectId if we are creating new object
|
||||
if (!this.data.objectId) {
|
||||
this.data.objectId = cryptoUtils.newObjectId();
|
||||
this.data.objectId = cryptoUtils.newObjectId(this.config.objectIdSize);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ function statusHandler(className, database) {
|
||||
|
||||
export function jobStatusHandler(config) {
|
||||
let jobStatus;
|
||||
const objectId = newObjectId();
|
||||
const objectId = newObjectId(config.objectIdSize);
|
||||
const database = config.database;
|
||||
const handler = statusHandler(JOB_STATUS_COLLECTION, database);
|
||||
const setRunning = function(jobName, params) {
|
||||
@@ -103,7 +103,7 @@ export function jobStatusHandler(config) {
|
||||
});
|
||||
}
|
||||
|
||||
export function pushStatusHandler(config, objectId = newObjectId()) {
|
||||
export function pushStatusHandler(config, objectId = newObjectId(config.objectIdSize)) {
|
||||
|
||||
let pushStatus;
|
||||
const database = config.database;
|
||||
|
||||
@@ -256,5 +256,10 @@ export default {
|
||||
},
|
||||
"middleware": {
|
||||
help: "middleware for express server, can be string or function"
|
||||
},
|
||||
"objectIdSize": {
|
||||
env: "PARSE_SERVER_OBJECT_ID_SIZE",
|
||||
help: "Sets the number of characters in generated object id's, default 10",
|
||||
action: numberParser("objectIdSize")
|
||||
}
|
||||
};
|
||||
|
||||
@@ -35,9 +35,8 @@ export function randomString(size: number): string {
|
||||
}
|
||||
|
||||
// Returns a new random alphanumeric string suitable for object ID.
|
||||
export function newObjectId(): string {
|
||||
//TODO: increase length to better protect against collisions.
|
||||
return randomString(10);
|
||||
export function newObjectId(size: number = 10): string {
|
||||
return randomString(size);
|
||||
}
|
||||
|
||||
// Returns a new random hex string suitable for secure tokens.
|
||||
|
||||
@@ -32,5 +32,6 @@ export default {
|
||||
expireInactiveSessions: true,
|
||||
revokeSessionOnPasswordReset: true,
|
||||
schemaCacheTTL: 5000, // in ms
|
||||
userSensitiveFields: ['email']
|
||||
userSensitiveFields: ['email'],
|
||||
objectIdSize: 10
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user