feat: Add dynamic master key by setting Parse Server option masterKey to a function (#9582)

This commit is contained in:
Daniel
2025-02-13 08:23:18 +11:00
committed by GitHub
parent 415373708a
commit 6f1d161a2f
8 changed files with 102 additions and 25 deletions

View File

@@ -724,6 +724,28 @@ export class Config {
return `${this.publicServerURL}/${this.pagesEndpoint}/${this.applicationId}/verify_email`;
}
async loadMasterKey() {
if (typeof this.masterKey === 'function') {
const ttlIsEmpty = !this.masterKeyTtl;
const isExpired = this.masterKeyCache?.expiresAt && this.masterKeyCache.expiresAt < new Date();
if ((!isExpired || ttlIsEmpty) && this.masterKeyCache?.masterKey) {
return this.masterKeyCache.masterKey;
}
const masterKey = await this.masterKey();
const expiresAt = this.masterKeyTtl ? new Date(Date.now() + 1000 * this.masterKeyTtl) : null
this.masterKeyCache = { masterKey, expiresAt };
Config.put(this);
return this.masterKeyCache.masterKey;
}
return this.masterKey;
}
// TODO: Remove this function once PagesRouter replaces the PublicAPIRouter;
// the (default) endpoint has to be defined in PagesRouter only.
get pagesEndpoint() {