Skip to content

Commit

Permalink
#38: automatically download fixed key dependencies if use agrees
Browse files Browse the repository at this point in the history
  • Loading branch information
JoernBerkefeld committed Aug 2, 2023
1 parent 731fefa commit 08e0a6d
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 5 deletions.
12 changes: 12 additions & 0 deletions docs/dist/documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -6535,6 +6535,7 @@ CLI helper class
* [Cli](#Cli)
* [.initMcdevConfig()](#Cli.initMcdevConfig) ⇒ <code>Promise.&lt;boolean&gt;</code>
* [.addExtraCredential(properties)](#Cli.addExtraCredential) ⇒ <code>Promise.&lt;(boolean\|string)&gt;</code>
* [.postFixKeysReretrieve(type, dependentTypes)](#Cli.postFixKeysReretrieve) ⇒ <code>Promise.&lt;boolean&gt;</code>
* [.logExistingCredentials(properties)](#Cli.logExistingCredentials) ⇒ <code>void</code>
* [.updateCredential(properties, credName)](#Cli.updateCredential) ⇒ <code>Promise.&lt;boolean&gt;</code>
* [.getCredentialObject(properties, target, [isCredentialOnly], [allowAll])](#Cli.getCredentialObject) ⇒ <code>Promise.&lt;TYPE.BuObject&gt;</code>
Expand Down Expand Up @@ -6565,6 +6566,17 @@ Extends template file for properties.json
| --- | --- | --- |
| properties | <code>TYPE.Mcdevrc</code> | config file's json |

<a name="Cli.postFixKeysReretrieve"></a>

### Cli.postFixKeysReretrieve(type, dependentTypes) ⇒ <code>Promise.&lt;boolean&gt;</code>
**Kind**: static method of [<code>Cli</code>](#Cli)
**Returns**: <code>Promise.&lt;boolean&gt;</code> - true if user wants to continue with retrieve

| Param | Type | Description |
| --- | --- | --- |
| type | <code>TYPE.SupportedMetadataTypes</code> | limit execution to given metadata type |
| dependentTypes | <code>Array.&lt;TYPE.SupportedMetadataTypes&gt;</code> | types that depent on type |

<a name="Cli.logExistingCredentials"></a>

### Cli.logExistingCredentials(properties) ⇒ <code>void</code>
Expand Down
26 changes: 21 additions & 5 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -865,6 +865,7 @@ class Mcdev {
}

if (businessUnit === '*') {
Util.OPTIONS._multiBuExecution = true;
Util.logger.info(
`:: ${lang_present} the ${selectedType} on all BUs for all credentials`
);
Expand Down Expand Up @@ -916,6 +917,7 @@ class Mcdev {
}
}
if (bu === '*' && properties.credentials && properties.credentials[cred]) {
Util.OPTIONS._multiBuExecution = true;
Util.logger.info(`:: ${lang_present} ${selectedType} on all BUs for ${cred}`);
for (const bu in properties.credentials[cred].businessUnits) {
resultObj[cred + '/' + bu] = await this.#runOnBU(
Expand Down Expand Up @@ -1123,11 +1125,25 @@ class Mcdev {
actuallyFixedKeys.length === 1 ? '' : 's'
} of type ${type}`
);
Util.logger.warn(
` Please manually re-retrieve the following types as your local copies might now be outdated: ${Util.getGrayMsg(
dependentTypes.join(', ')
)}`
);
if (dependentTypes.length) {
Util.logger.warn(
`Please re-retrieve the following types as your local copies might now be outdated: ${Util.getGrayMsg(
dependentTypes.join(', ')
)}`
);
const reRetrieve = await Cli.postFixKeysReretrieve(type, dependentTypes);
if (reRetrieve) {
Util.logger.info(
`Retrieving latest versions of ${dependentTypes.join(', ')} from server`
);
const retriever = new Retriever(properties, buObject);
await retriever.retrieve(dependentTypes, null, null, false);
}
} else {
Util.logger.info(
`No dependent types found that need to be re-retrieved after fixing keys of type ${type}.`
);
}
} else {
Util.logger.warn(`No keys of type ${type} updated.`);
}
Expand Down
40 changes: 40 additions & 0 deletions lib/util/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,46 @@ const Cli = {
return null;
}
},

/**
*
* @param {TYPE.SupportedMetadataTypes} type limit execution to given metadata type
* @param {TYPE.SupportedMetadataTypes[]} dependentTypes types that depent on type
* @returns {Promise.<boolean>} true if user wants to continue with retrieve
*/
async postFixKeysReretrieve(type, dependentTypes) {
if (Util.skipInteraction?.fixKeysReretrieve === true) {
return true;
} else if (Util.skipInteraction?.fixKeysReretrieve === false) {
return false;
} else {
const now = await inquirer.prompt([
{
type: 'confirm',
name: 'fixKeysReretrieve',
message: `Do you want to re-retrieve dependent types (${dependentTypes.join(
', '
)}) now?`,
default: true,
},
]);
if (Util.OPTIONS._multiBuExecution) {
const remember = await inquirer.prompt([
{
type: 'confirm',
name: 'rememberFixKeysReretrieve',
message: `Remember answer for other BUs?`,
default: true,
},
]);
if (remember.rememberFixKeysReretrieve) {
Util.skipInteraction ||= {};
Util.skipInteraction.fixKeysReretrieve = now.fixKeysReretrieve;
}
}
return now.fixKeysReretrieve;
}
},
/**
* helper that logs to cli which credentials are already existing in our config file
*
Expand Down

0 comments on commit 08e0a6d

Please sign in to comment.