Skip to content

Commit 90ffb48

Browse files
Merge branch 'fix/dx-7312-marketplace-config-decrypt-resilience' into fix/dx-7312-entry-data-extension-uid-remap
2 parents 09ace55 + 555a73f commit 90ffb48

1 file changed

Lines changed: 74 additions & 36 deletions

File tree

packages/contentstack-import/src/import/modules/marketplace-apps.ts

Lines changed: 74 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -697,46 +697,84 @@ export default class ImportMarketplaceApps extends BaseClass {
697697

698698
if (!isEmpty(configuration)) {
699699
log.debug(`Updating app configuration for: ${appName}`, this.importConfig.context);
700-
await this.appSdk
701-
.marketplace(this.importConfig.org_uid)
702-
.installation(installation_uid)
703-
.setConfiguration(this.nodeCrypto.decrypt(configuration))
704-
.then(({ data }: any) => {
705-
if (data?.message) {
706-
log.debug(data, this.importConfig.context);
707-
log.info(formatError(data.message), this.importConfig.context);
708-
} else {
709-
log.success(`${appName} app config updated successfully.!`, this.importConfig.context);
710-
log.debug(`Configuration update successful for: ${appName}`, this.importConfig.context);
711-
}
712-
})
713-
.catch((error: any) => {
714-
log.debug(error, this.importConfig.context);
715-
log.error(formatError(error), this.importConfig.context);
716-
log.debug(`Configuration update failed for: ${appName}`, this.importConfig.context);
717-
});
700+
// NOTE: decrypt synchronously in a guard. A bad-decrypt (e.g. ERR_OSSL_BAD_DECRYPT when the
701+
// export was encrypted with a different key) would otherwise throw here — outside the promise
702+
// chain's .catch — abort the whole marketplace-apps module, and skip writing the
703+
// marketplace_apps uid-mapping, which starves the downstream GF/CT/entry extension remap.
704+
// Instead: warn and skip only this app's configuration; the app stays installed and its
705+
// extension mappings are still recorded.
706+
let decryptedConfiguration: any;
707+
try {
708+
decryptedConfiguration = this.nodeCrypto.decrypt(configuration);
709+
} catch (error: any) {
710+
log.warn(
711+
`Failed to decrypt configuration for '${appName}'; skipping its configuration update. The app is installed and its extension mappings are preserved. (${
712+
error?.message || error
713+
})`,
714+
this.importConfig.context,
715+
);
716+
decryptedConfiguration = undefined;
717+
}
718+
719+
if (decryptedConfiguration !== undefined) {
720+
await this.appSdk
721+
.marketplace(this.importConfig.org_uid)
722+
.installation(installation_uid)
723+
.setConfiguration(decryptedConfiguration)
724+
.then(({ data }: any) => {
725+
if (data?.message) {
726+
log.debug(data, this.importConfig.context);
727+
log.info(formatError(data.message), this.importConfig.context);
728+
} else {
729+
log.success(`${appName} app config updated successfully.!`, this.importConfig.context);
730+
log.debug(`Configuration update successful for: ${appName}`, this.importConfig.context);
731+
}
732+
})
733+
.catch((error: any) => {
734+
log.debug(error, this.importConfig.context);
735+
log.error(formatError(error), this.importConfig.context);
736+
log.debug(`Configuration update failed for: ${appName}`, this.importConfig.context);
737+
});
738+
}
718739
}
719740

720741
if (!isEmpty(server_configuration)) {
721742
log.debug(`Updating server configuration for: ${appName}`, this.importConfig.context);
722-
await this.appSdk
723-
.marketplace(this.importConfig.org_uid)
724-
.installation(installation_uid)
725-
.setServerConfig(this.nodeCrypto.decrypt(server_configuration))
726-
.then(({ data }: any) => {
727-
if (data?.message) {
728-
log.debug(data, this.importConfig.context);
729-
log.error(formatError(data.message), this.importConfig.context);
730-
} else {
731-
log.success(`${appName} app server config updated successfully.!`, this.importConfig.context);
732-
log.debug(`Server configuration update successful for: ${appName}`, this.importConfig.context);
733-
}
734-
})
735-
.catch((error: any) => {
736-
log.debug(error, this.importConfig.context);
737-
log.error(formatError(error), this.importConfig.context);
738-
log.debug(`Server configuration update failed for: ${appName}`, this.importConfig.context);
739-
});
743+
// NOTE: guard the decrypt for the same reason as `configuration` above — a bad-decrypt must
744+
// not abort the module or skip the uid-mapping write.
745+
let decryptedServerConfiguration: any;
746+
try {
747+
decryptedServerConfiguration = this.nodeCrypto.decrypt(server_configuration);
748+
} catch (error: any) {
749+
log.warn(
750+
`Failed to decrypt server configuration for '${appName}'; skipping its server configuration update. The app is installed and its extension mappings are preserved. (${
751+
error?.message || error
752+
})`,
753+
this.importConfig.context,
754+
);
755+
decryptedServerConfiguration = undefined;
756+
}
757+
758+
if (decryptedServerConfiguration !== undefined) {
759+
await this.appSdk
760+
.marketplace(this.importConfig.org_uid)
761+
.installation(installation_uid)
762+
.setServerConfig(decryptedServerConfiguration)
763+
.then(({ data }: any) => {
764+
if (data?.message) {
765+
log.debug(data, this.importConfig.context);
766+
log.error(formatError(data.message), this.importConfig.context);
767+
} else {
768+
log.success(`${appName} app server config updated successfully.!`, this.importConfig.context);
769+
log.debug(`Server configuration update successful for: ${appName}`, this.importConfig.context);
770+
}
771+
})
772+
.catch((error: any) => {
773+
log.debug(error, this.importConfig.context);
774+
log.error(formatError(error), this.importConfig.context);
775+
log.debug(`Server configuration update failed for: ${appName}`, this.importConfig.context);
776+
});
777+
}
740778
}
741779
}
742780

0 commit comments

Comments
 (0)