Skip to content

Commit 700d002

Browse files
Split Azure Cosmos compatible options into three and move into DatabaseOptions config node
1 parent 35f54a2 commit 700d002

File tree

5 files changed

+54
-22
lines changed

5 files changed

+54
-22
lines changed

src/Config.js

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ export class Config {
8585
allowExpiredAuthDataToken,
8686
logLevels,
8787
rateLimit,
88-
azureCosmosMongoDbCompatibleMode,
8988
databaseOptions,
9089
}) {
9190
if (masterKey === readOnlyMasterKey) {
@@ -121,7 +120,6 @@ export class Config {
121120
this.validateSchemaOptions(schema);
122121
this.validateEnforcePrivateUsers(enforcePrivateUsers);
123122
this.validateAllowExpiredAuthDataToken(allowExpiredAuthDataToken);
124-
this.validateAzureCosmosMongoDbCompatibleMode(azureCosmosMongoDbCompatibleMode);
125123
this.validateRequestKeywordDenylist(requestKeywordDenylist);
126124
this.validateRateLimit(rateLimit);
127125
this.validateLogLevels(logLevels);
@@ -168,12 +166,6 @@ export class Config {
168166
}
169167
}
170168

171-
static validateAzureCosmosMongoDbCompatibleMode(azureCosmosMongoDbCompatibleMode) {
172-
if (typeof azureCosmosMongoDbCompatibleMode !== 'boolean') {
173-
throw 'Parse Server option azureCosmosMongoDbCompatibleMode must be a boolean.';
174-
}
175-
}
176-
177169
static validateSecurityOptions(security) {
178170
if (Object.prototype.toString.call(security) !== '[object Object]') {
179171
throw 'Parse Server option security must be an object.';
@@ -566,6 +558,24 @@ export class Config {
566558
} else if (typeof databaseOptions.schemaCacheTtl !== 'number') {
567559
throw `databaseOptions.schemaCacheTtl must be a number`;
568560
}
561+
if (databaseOptions.disableEnsureUsernameCaseInsensitiveIndex === undefined) {
562+
databaseOptions.disableEnsureUsernameCaseInsensitiveIndex =
563+
DatabaseOptions.disableEnsureUsernameCaseInsensitiveIndex.default;
564+
} else if (typeof databaseOptions.disableEnsureUsernameCaseInsensitiveIndex !== 'boolean') {
565+
throw `databaseOptions.disableEnsureUsernameCaseInsensitiveIndex must be a boolean`;
566+
}
567+
if (databaseOptions.disableEnsureEmailCaseInsensitiveIndex === undefined) {
568+
databaseOptions.disableEnsureEmailCaseInsensitiveIndex =
569+
DatabaseOptions.disableEnsureEmailCaseInsensitiveIndex.default;
570+
} else if (typeof databaseOptions.disableEnsureEmailCaseInsensitiveIndex !== 'boolean') {
571+
throw `databaseOptions.disableEnsureEmailCaseInsensitiveIndex must be a boolean`;
572+
}
573+
if (databaseOptions.disableEnsureIdempotencyExpireIndex === undefined) {
574+
databaseOptions.disableEnsureIdempotencyExpireIndex =
575+
DatabaseOptions.disableEnsureIdempotencyExpireIndex.default;
576+
} else if (typeof databaseOptions.disableEnsureIdempotencyExpireIndex !== 'boolean') {
577+
throw `databaseOptions.disableEnsureIdempotencyExpireIndex must be a boolean`;
578+
}
569579
}
570580

571581
static validateRateLimit(rateLimit) {

src/Controllers/DatabaseController.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1706,7 +1706,7 @@ class DatabaseController {
17061706
throw error;
17071707
});
17081708

1709-
if (!this.options.azureCosmosMongoDbCompatibleMode) {
1709+
if (!this.options.databaseOptions?.disableEnsureUsernameCaseInsensitiveIndex) {
17101710
await this.adapter
17111711
.ensureIndex('_User', requiredUserFields, ['username'], 'case_insensitive_username', true)
17121712
.catch(error => {
@@ -1725,7 +1725,7 @@ class DatabaseController {
17251725
throw error;
17261726
});
17271727

1728-
if (!this.options.azureCosmosMongoDbCompatibleMode) {
1728+
if (!this.options.databaseOptions?.disableEnsureEmailCaseInsensitiveIndex) {
17291729
await this.adapter
17301730
.ensureIndex('_User', requiredUserFields, ['email'], 'case_insensitive_email', true)
17311731
.catch(error => {
@@ -1758,7 +1758,7 @@ class DatabaseController {
17581758
options = this.idempotencyOptions;
17591759
options.setIdempotencyFunction = true;
17601760
}
1761-
if (!this.options.azureCosmosMongoDbCompatibleMode) {
1761+
if (!this.options.databaseOptions.disableEnsureIdempotencyExpireIndex) {
17621762
await this.adapter
17631763
.ensureIndex('_Idempotency', requiredIdempotencyFields, ['expire'], 'ttl', false, options)
17641764
.catch(error => {

src/Options/Definitions.js

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -103,13 +103,6 @@ module.exports.ParseServerOptions = {
103103
'Configuration for your authentication providers, as stringified JSON. See http://docs.parseplatform.org/parse-server/guide/#oauth-and-3rd-party-authentication',
104104
action: parsers.arrayParser,
105105
},
106-
azureCosmosMongoDbCompatibleMode: {
107-
env: 'PARSE_SERVER_AZURE_COSMOS_MONGO_DB_COMPATIBLE_MODE',
108-
help:
109-
'Set to true for running against Azure Cosmos for Mongo DB. This can bring some performance loss.',
110-
action: parsers.booleanParser,
111-
default: false,
112-
},
113106
cacheAdapter: {
114107
env: 'PARSE_SERVER_CACHE_ADAPTER',
115108
help: 'Adapter module for the cache',
@@ -976,6 +969,27 @@ module.exports.FileUploadOptions = {
976969
},
977970
};
978971
module.exports.DatabaseOptions = {
972+
disableEnsureEmailCaseInsensitiveIndex: {
973+
env: 'PARSE_SERVER_DATABASE_DISABLE_ENSURE_EMAIL_CASE_INSENSITIVE_INDEX',
974+
help:
975+
'Disables behavior to ensure case-insensitive index on field email on _User collection. Set to `true` if using a database not supporting case-insensitive indexes.',
976+
action: parsers.booleanParser,
977+
default: false,
978+
},
979+
disableEnsureIdempotencyExpireIndex: {
980+
env: 'PARSE_SERVER_DATABASE_DISABLE_ENSURE_IDEMPOTENCY_EXPIRE_INDEX',
981+
help:
982+
'Disables behavior to ensure time to live index on field expire on _Idempotency collection. Set to `true` if using a database not supporting TTL index on this field.',
983+
action: parsers.booleanParser,
984+
default: false,
985+
},
986+
disableEnsureUsernameCaseInsensitiveIndex: {
987+
env: 'PARSE_SERVER_DATABASE_DISABLE_ENSURE_USERNAME_CASE_INSENSITIVE_INDEX',
988+
help:
989+
'Disables behavior to ensure case-insensitive index on field username on _User collection. Set to `true` if using a database not supporting case-insensitive indexes.',
990+
action: parsers.booleanParser,
991+
default: false,
992+
},
979993
enableSchemaHooks: {
980994
env: 'PARSE_SERVER_DATABASE_ENABLE_SCHEMA_HOOKS',
981995
help:

src/Options/docs.js

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Options/index.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -300,9 +300,6 @@ export interface ParseServerOptions {
300300
/* Options to limit repeated requests to Parse Server APIs. This can be used to protect sensitive endpoints such as `/requestPasswordReset` from brute-force attacks or Parse Server as a whole from denial-of-service (DoS) attacks.<br><br>ℹ️ Mind the following limitations:<br>- rate limits applied per IP address; this limits protection against distributed denial-of-service (DDoS) attacks where many requests are coming from various IP addresses<br>- if multiple Parse Server instances are behind a load balancer or ran in a cluster, each instance will calculate it's own request rates, independent from other instances; this limits the applicability of this feature when using a load balancer and another rate limiting solution that takes requests across all instances into account may be more suitable<br>- this feature provides basic protection against denial-of-service attacks, but a more sophisticated solution works earlier in the request flow and prevents a malicious requests to even reach a server instance; it's therefore recommended to implement a solution according to architecture and user case.
301301
:DEFAULT: [] */
302302
rateLimit: ?(RateLimitOptions[]);
303-
/* Set to true for running against Azure Cosmos for Mongo DB. This can bring some performance loss.
304-
:DEFAULT: false */
305-
azureCosmosMongoDbCompatibleMode: ?boolean;
306303
}
307304

308305
export interface RateLimitOptions {
@@ -556,6 +553,15 @@ export interface DatabaseOptions {
556553
enableSchemaHooks: ?boolean;
557554
/* The duration in seconds after which the schema cache expires and will be refetched from the database. Use this option if using multiple Parse Servers instances connected to the same database. A low duration will cause the schema cache to be updated too often, causing unnecessary database reads. A high duration will cause the schema to be updated too rarely, increasing the time required until schema changes propagate to all server instances. This feature can be used as an alternative or in conjunction with the option `enableSchemaHooks`. Default is infinite which means the schema cache never expires. */
558555
schemaCacheTtl: ?number;
556+
/* Disables behavior to ensure case-insensitive index on field username on _User collection. Set to `true` if using a database not supporting case-insensitive indexes.
557+
:DEFAULT: false */
558+
disableEnsureUsernameCaseInsensitiveIndex: ?boolean;
559+
/* Disables behavior to ensure case-insensitive index on field email on _User collection. Set to `true` if using a database not supporting case-insensitive indexes.
560+
:DEFAULT: false */
561+
disableEnsureEmailCaseInsensitiveIndex: ?boolean;
562+
/* Disables behavior to ensure time to live index on field expire on _Idempotency collection. Set to `true` if using a database not supporting TTL index on this field.
563+
:DEFAULT: false */
564+
disableEnsureIdempotencyExpireIndex: ?boolean;
559565
}
560566

561567
export interface AuthAdapter {

0 commit comments

Comments
 (0)