Skip to content

Commit

Permalink
#984: move updateNotifications under runMethod
Browse files Browse the repository at this point in the history
  • Loading branch information
phjulia committed Aug 7, 2023
1 parent 000778e commit 76dda3e
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 100 deletions.
31 changes: 11 additions & 20 deletions docs/dist/documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,6 @@ Provides default functionality that can be overwritten by child metadata type cl
<dt><a href="#Mcdev.">Mcdev.(selectedType, buObject)</a> ⇒ <code>Array.&lt;string&gt;</code></dt>
<dd><p>helper for <a href="Mcdev.#runOnBU">Mcdev.#runOnBU</a></p>
</dd>
<dt><a href="#Mcdev.">Mcdev.(cred, bu, type, [keys])</a> ⇒ <code>Promise.&lt;Array.&lt;string&gt;&gt;</code></dt>
<dd></dd>
<dt><a href="#Automation.">Automation.(metadata)</a> ⇒ <code>boolean</code></dt>
<dd><p>helper for <a href="#Automation.postRetrieveTasks">postRetrieveTasks</a> and <a href="#Automation.execute">execute</a></p>
</dd>
Expand All @@ -215,6 +213,8 @@ Provides default functionality that can be overwritten by child metadata type cl
<dt><a href="#Automation.">Automation.(metadataMap, key)</a> ⇒ <code>Promise.&lt;void&gt;</code></dt>
<dd><p>helper for <a href="#Automation.postDeployTasks">postDeployTasks</a></p>
</dd>
<dt><a href="#Automation.">Automation.()</a> ⇒ <code>string</code></dt>
<dd></dd>
<dt><a href="#Automation.">Automation.(metadataMap, originalMetadataMap, key)</a> ⇒ <code>Promise.&lt;{key:string, response:object}&gt;</code></dt>
<dd><p>helper for <a href="#Automation.postDeployTasks">postDeployTasks</a></p>
</dd>
Expand Down Expand Up @@ -525,7 +525,7 @@ main class
* [.execute(businessUnit, [selectedType], [keys])](#Mcdev.execute) ⇒ <code>Promise.&lt;Object.&lt;string, Array.&lt;string&gt;&gt;&gt;</code>
* [.pause(businessUnit, [selectedType], [keys])](#Mcdev.pause) ⇒ <code>Promise.&lt;Object.&lt;string, Array.&lt;string&gt;&gt;&gt;</code>
* [.fixKeys(businessUnit, type, [keys])](#Mcdev.fixKeys) ⇒ <code>Promise.&lt;Object.&lt;string, Array.&lt;string&gt;&gt;&gt;</code>
* [.updateNotifications(businessUnit, type, [keys])](#Mcdev.updateNotifications) ⇒ <code>Promise.&lt;Object.&lt;string, Array.&lt;string&gt;&gt;&gt;</code>
* [.updateNotifications(businessUnit, selectedType, [keys])](#Mcdev.updateNotifications) ⇒ <code>Promise.&lt;Object.&lt;string, Array.&lt;string&gt;&gt;&gt;</code>

<a name="Mcdev.setSkipInteraction"></a>

Expand Down Expand Up @@ -835,7 +835,7 @@ Updates the key to match the name field

<a name="Mcdev.updateNotifications"></a>

### Mcdev.updateNotifications(businessUnit, type, [keys]) ⇒ <code>Promise.&lt;Object.&lt;string, Array.&lt;string&gt;&gt;&gt;</code>
### Mcdev.updateNotifications(businessUnit, selectedType, [keys]) ⇒ <code>Promise.&lt;Object.&lt;string, Array.&lt;string&gt;&gt;&gt;</code>
Updates notification email address field

**Kind**: static method of [<code>Mcdev</code>](#Mcdev)
Expand All @@ -844,7 +844,7 @@ Updates notification email address field
| Param | Type | Description |
| --- | --- | --- |
| businessUnit | <code>string</code> | name of BU |
| type | <code>TYPE.SupportedMetadataTypes</code> | limit execution to given metadata type |
| selectedType | <code>TYPE.SupportedMetadataTypes</code> | limit execution to given metadata type |
| [keys] | <code>Array.&lt;string&gt;</code> | customerkey of the metadata |

<a name="Asset"></a>
Expand Down Expand Up @@ -8476,7 +8476,7 @@ run a method across BUs

| Param | Type | Description |
| --- | --- | --- |
| methodName | <code>&#x27;execute&#x27;</code> \| <code>&#x27;pause&#x27;</code> | what to run |
| methodName | <code>&#x27;execute&#x27;</code> \| <code>&#x27;pause&#x27;</code> \| <code>&#x27;updateNotifications&#x27;</code> | what to run |
| businessUnit | <code>string</code> | name of BU |
| [selectedType] | <code>TYPE.SupportedMetadataTypes</code> | limit to given metadata types |
| [keys] | <code>Array.&lt;string&gt;</code> | customerkey of the metadata |
Expand All @@ -8491,7 +8491,7 @@ helper for [Mcdev.#runMethod](Mcdev.#runMethod)

| Param | Type | Description |
| --- | --- | --- |
| methodName | <code>&#x27;execute&#x27;</code> \| <code>&#x27;pause&#x27;</code> | what to run |
| methodName | <code>&#x27;execute&#x27;</code> \| <code>&#x27;pause&#x27;</code> \| <code>&#x27;updateNotifications&#x27;</code> | what to run |
| cred | <code>string</code> | name of Credential |
| bu | <code>string</code> | name of BU |
| [type] | <code>TYPE.SupportedMetadataTypes</code> | limit execution to given metadata type |
Expand All @@ -8510,19 +8510,6 @@ helper for [Mcdev.#runOnBU](Mcdev.#runOnBU)
| selectedType | <code>TYPE.SupportedMetadataTypes</code> | limit execution to given metadata type |
| buObject | <code>TYPE.BuObject</code> | properties for auth |

<a name="Mcdev."></a>

## Mcdev.(cred, bu, type, [keys]) ⇒ <code>Promise.&lt;Array.&lt;string&gt;&gt;</code>
**Kind**: global function
**Returns**: <code>Promise.&lt;Array.&lt;string&gt;&gt;</code> - keys of the automations where notifications were updated

| Param | Type | Description |
| --- | --- | --- |
| cred | <code>string</code> | name of Credential |
| bu | <code>string</code> | name of BU |
| type | <code>string</code> | metadata type |
| [keys] | <code>Array.&lt;string&gt;</code> | limit retrieval to given metadata keys |

<a name="Automation."></a>

## Automation.(metadata) ⇒ <code>boolean</code>
Expand Down Expand Up @@ -8598,6 +8585,10 @@ helper for [postDeployTasks](#Automation.postDeployTasks)

<a name="Automation."></a>

## Automation.() ⇒ <code>string</code>
**Kind**: global function
<a name="Automation."></a>

## Automation.(metadataMap, originalMetadataMap, key) ⇒ <code>Promise.&lt;{key:string, response:object}&gt;</code>
helper for [postDeployTasks](#Automation.postDeployTasks)

Expand Down
15 changes: 8 additions & 7 deletions lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -544,8 +544,9 @@ yargs
},
})
.command({
command: 'updateNotifications <BU> <TYPE> [KEY]',
aliases: ['updNotif'],
command:
'updateNotifications <BU> <TYPE> [KEY] [emailError] [emailComplete] [errorNote] [completionNote]',
aliases: ['un'],
desc: 'bulk updates notification email addresses',
builder: (yargs) => {
yargs
Expand All @@ -561,25 +562,25 @@ yargs
type: 'string',
describe: 'key(s) of the metadata component(s)',
})
.positional('emailError', {
.option('errorEmail', {
type: 'string',
describe: 'email to notify that an error occured during execution',
})
.positional('emailComplete', {
.option('completionEmail', {
type: 'string',
describe: 'email to notify about successfull completion',
})
.positional('errorNote', {
.option('errorNote', {
type: 'string',
describe: 'run error note',
})
.positional('completionNote', {
.option('completionNote', {
type: 'string',
describe: 'run completion note',
})
.option('like', {
type: 'string',
group: 'Options for update notification email address:',
group: 'Options for updateNotifications:',
describe:
'filter metadata components (can include % as wildcard or _ for a single character)',
});
Expand Down
94 changes: 21 additions & 73 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ class Mcdev {
'refresh',
'schedule',
'skipInteraction',
'emailError',
'emailComplete',
'errorEmail',
'completionEmail',
'errorNote',
'completionNote',
];
Expand Down Expand Up @@ -781,7 +781,7 @@ class Mcdev {
/**
* run a method across BUs
*
* @param {'execute'|'pause'} methodName what to run
* @param {'execute'|'pause'|'updateNotifications'} methodName what to run
* @param {string} businessUnit name of BU
* @param {TYPE.SupportedMetadataTypes} [selectedType] limit to given metadata types
* @param {string[]} [keys] customerkey of the metadata
Expand All @@ -807,6 +807,12 @@ class Mcdev {
requireKeyOrLike = true;
break;
}
case 'updateNotifications': {
lang_past = 'updated';
lang_present = 'updating notifications for';
requireKeyOrLike = true;
break;
}
}

Util.logger.info(`mcdev:: ${methodName} ${selectedType}`);
Expand Down Expand Up @@ -925,7 +931,7 @@ class Mcdev {
/**
* helper for {@link Mcdev.#runMethod}
*
* @param {'execute'|'pause'} methodName what to run
* @param {'execute'|'pause'|'updateNotifications'} methodName what to run
* @param {string} cred name of Credential
* @param {string} bu name of BU
* @param {TYPE.SupportedMetadataTypes} [type] limit execution to given metadata type
Expand Down Expand Up @@ -1134,80 +1140,22 @@ class Mcdev {
* Updates notification email address field
*
* @param {string} businessUnit name of BU
* @param {TYPE.SupportedMetadataTypes} type limit execution to given metadata type
* @param {TYPE.SupportedMetadataTypes} selectedType limit execution to given metadata type
* @param {string[]} [keys] customerkey of the metadata
* @returns {Promise.<Object.<string, string[]>>} key: business unit name, value: list of affected item keys
*/
static async updateNotifications(businessUnit, type, keys) {
const [cred, bu] = businessUnit ? businessUnit.split('/') : [null, null];
if (Util.OPTIONS.emailComplete == null && Util.OPTIONS.emailError == null) {
Util.logger.error(`No email addresses were provided`);
return null;
}
const properties = await config.getProperties();
const resultsObj = {};
if (bu === '*') {
Util.logger.info(':: Updating notifications on all BUs for all credentials');
let counter_credTotal = 0;
for (const cred in properties.credentials) {
Util.logger.info(`:: Updating notifications on BUs for ${cred}`);
let counter_credBu = 0;
for (const bu in properties.credentials[cred].businessUnits) {
resultsObj[`${cred}/${bu}`] = await this.#updateNotificationsBU(
cred,
bu,
type,
keys
);
counter_credBu++;
Util.startLogger(true);
}
counter_credTotal += counter_credBu;
Util.logger.info(`:: ${counter_credBu} BUs of ${cred}\n`);
}
Util.logger.info(`:: Updated notifications on ${counter_credTotal} BUs of ${cred}\n`);
} else {
resultsObj[`${cred}/${bu}`] = await this.#updateNotificationsBU(cred, bu, type, keys);
}

return resultsObj;
}
/**
*
* @param {string} cred name of Credential
* @param {string} bu name of BU
* @param {string} type metadata type
* @param {string[]} [keys] limit retrieval to given metadata keys
* @returns {Promise.<string[]>} keys of the automations where notifications were updated
*/
static async #updateNotificationsBU(cred, bu, type, keys) {
const properties = await config.getProperties();
if (!(await config.checkProperties(properties))) {
return null;
}
const buObject = await Cli.getCredentialObject(
properties,
cred === null ? null : cred + '/' + bu,
null,
true
);
if (buObject !== null) {
cache.initCache(buObject);
cred = buObject.credential;
bu = buObject.businessUnit;
}
try {
MetadataTypeInfo[type].client = auth.getSDK(buObject);
} catch (ex) {
Util.logger.error(ex.message);
static async updateNotifications(businessUnit, selectedType, keys) {
if (
Util.OPTIONS.completionEmail === undefined &&
Util.OPTIONS.errorEmail === undefined &&
Util.OPTIONS.completionNote === undefined &&
Util.OPTIONS.errorNote === undefined
) {
// if no options were provided there is nothing to update
Util.logger.error(`No email addresses or run notes were provided`);
return null;
}
Util.logger.info(
`Setting notification email address of type ${type} on ${cred}/${bu}` +
(keys ? Util.getKeysString(keys) : '') +
`\n`
);
return await MetadataTypeInfo[type].updateNotifications(keys);
return this.#runMethod('updateNotifications', businessUnit, selectedType, keys);
}
}

Expand Down

0 comments on commit 76dda3e

Please sign in to comment.