Skip to content

Commit

Permalink
Merge pull request #672 from auth0/DXCDT-252-enable-delete-email-prov…
Browse files Browse the repository at this point in the history
…ider--warning-only

DXCDT-252: Adding email provider deletion warning (1/2)
  • Loading branch information
willvedd authored Oct 19, 2022
2 parents 79686dd + 49f402b commit b5e1675
Showing 1 changed file with 29 additions and 24 deletions.
53 changes: 29 additions & 24 deletions src/tools/auth0/handlers/emailProvider.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import DefaultHandler from './default';
import { Asset, Assets, CalculatedChanges } from '../../../types';
import { Asset, Assets } from '../../../types';
import logger from '../../../logger';

export const schema = { type: 'object' };

Expand Down Expand Up @@ -30,34 +31,38 @@ export default class EmailProviderHandler extends DefaultHandler {
async processChanges(assets: Assets): Promise<void> {
const { emailProvider } = assets;

// Do nothing if not set
if (!emailProvider) return;

if (Object.keys(emailProvider).length > 0) {
let existing = await this.getType();

// Check for existing Email Provider
if (existing.name) {
if (existing.name !== emailProvider.name) {
// Delete the current provider as it's different
await this.client.emailProvider.delete();
this.didDelete(existing);
existing = {};
}
let existing = await this.getType();

if (Object.keys(emailProvider).length === 0) {
if (this.config('AUTH0_ALLOW_DELETE') === true) {
logger.warn(
'Setting email provider to empty object will delete the provider in future versions. The current inability to delete is considered a bug. For more details see: https://github.com/auth0/auth0-deploy-cli/issues/653'
);
}
return;
}

// Now configure or update depending if it is configured already
if (existing.name) {
const provider = { name: emailProvider.name, enabled: emailProvider.enabled };
const updated = await this.client.emailProvider.update(provider, emailProvider);
this.updated += 1;
this.didUpdate(updated);
} else {
const provider = { name: emailProvider.name, enabled: emailProvider.enabled };
const created = await this.client.emailProvider.configure(provider, emailProvider);
this.created += 1;
this.didCreate(created);
if (existing.name) {
if (existing.name !== emailProvider.name) {
// Delete the current provider as it's different
await this.client.emailProvider.delete();
this.didDelete(existing);
existing = {};
}
}

if (existing.name) {
const provider = { name: emailProvider.name, enabled: emailProvider.enabled };
const updated = await this.client.emailProvider.update(provider, emailProvider);
this.updated += 1;
this.didUpdate(updated);
} else {
const provider = { name: emailProvider.name, enabled: emailProvider.enabled };
const created = await this.client.emailProvider.configure(provider, emailProvider);
this.created += 1;
this.didCreate(created);
}
}
}

0 comments on commit b5e1675

Please sign in to comment.