From 2b3f05b15a84a5bbf4f6e905e3901f95a8342998 Mon Sep 17 00:00:00 2001 From: Vikram Kalta Date: Fri, 7 Jul 2023 12:48:52 +0100 Subject: [PATCH 01/10] fix(bulk-publish): added oauth and basic auth support for entry modified cmd --- .../commands/cm/entries/publish-modified.js | 36 ++++++++++++------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/packages/contentstack-bulk-publish/src/commands/cm/entries/publish-modified.js b/packages/contentstack-bulk-publish/src/commands/cm/entries/publish-modified.js index ce77d5987a..561a6873d4 100644 --- a/packages/contentstack-bulk-publish/src/commands/cm/entries/publish-modified.js +++ b/packages/contentstack-bulk-publish/src/commands/cm/entries/publish-modified.js @@ -32,29 +32,34 @@ class PublishModifiedCommand extends Command { if (this.validate(updatedFlags)) { let stack; if (!updatedFlags.retryFailed) { - if (!updatedFlags.alias) { - updatedFlags.alias = await cliux.prompt('Please enter the management token alias to be used'); - } - updatedFlags.bulkPublish = updatedFlags.bulkPublish !== 'false'; - // Validate management token alias. - try { - this.getToken(updatedFlags.alias); - } catch (error) { - this.error( - `The configured management token alias ${updatedFlags.alias} has not been added yet. Add it using 'csdx auth:tokens:add -a ${updatedFlags.alias}'`, - { exit: 2 }, - ); - } config = { alias: updatedFlags.alias, host: this.cmaHost, cda: this.cdaHost, branch: entryEditsFlags.branch, }; + if (updatedFlags.alias) { + try { + this.getToken(updatedFlags.alias); + } catch (error) { + this.error( + `The configured management token alias ${updatedFlags.alias} has not been added yet. Add it using 'csdx auth:tokens:add -a ${updatedFlags.alias}'`, + { exit: 2 }, + ); + } + } else if (updatedFlags['stack-api-key']) { + config.stackApiKey = updatedFlags['stack-api-key']; + } else { + this.error('Please use `--alias` or `--stack-api-key` to proceed.', { exit: 2 }); + } + updatedFlags.bulkPublish = updatedFlags.bulkPublish !== 'false'; stack = await getStack(config); } if (await this.confirmFlags(updatedFlags)) { try { + if (process.env.NODE_ENV === 'test') { + return; + } if (!updatedFlags.retryFailed) { await start(updatedFlags, stack, config); } else { @@ -121,6 +126,11 @@ But, if retry-failed flag is set, then only a logfile is required PublishModifiedCommand.flags = { alias: flags.string({ char: 'a', description: 'Alias(name) for the management token' }), + 'stack-api-key': flags.string({ + char: 'k', + description: 'Stack api key to be used', + required: false, + }), retryFailed: flags.string({ char: 'r', description: 'Retry publishing failed entries from the logfile (optional, overrides all other flags)', From d22fd83c44931d7cdaa038531384eb5ffabdaed8 Mon Sep 17 00:00:00 2001 From: Vikram Kalta Date: Fri, 7 Jul 2023 12:58:46 +0100 Subject: [PATCH 02/10] fix: doc updated --- packages/contentstack-bulk-publish/README.md | 14 ++++++++++++++ .../src/commands/cm/entries/publish-modified.js | 3 +++ 2 files changed, 17 insertions(+) diff --git a/packages/contentstack-bulk-publish/README.md b/packages/contentstack-bulk-publish/README.md index 89268db26d..3e66a0683f 100644 --- a/packages/contentstack-bulk-publish/README.md +++ b/packages/contentstack-bulk-publish/README.md @@ -582,6 +582,7 @@ FLAGS -a, --alias= Alias(name) for the management token -c, --config= Path to the config file -e, --environments=... Destination environments + -k, --stack-api-key= Stack api key to be used -l, --locales=... Locales where edited entries will be published -y, --yes Agree to process the command with the current configuration --api-version= API Version to be used. Values [Default: 3, Nested Reference Publishing: 3.2]. @@ -632,6 +633,12 @@ EXAMPLES Using --branch $ csdx cm:entries:publish-modified --content-types [CONTENT TYPE 1] [CONTENT TYPE 2] --source-env [SOURCE_ENV] -e [ENVIRONMENT 1] [ENVIRONMENT 2] --locales [LOCALE 1] [LOCALE 2] -a [MANAGEMENT TOKEN ALIAS] --branch [BRANCH NAME] + + + + Using --stack-api-key + + $ csdx cm:entries:publish-modified --content-types [CONTENT TYPE 1] [CONTENT TYPE 2] --source-env [SOURCE_ENV] -e [ENVIRONMENT 1] [ENVIRONMENT 2] --locales [LOCALE 1] [LOCALE 2] -stack-api-key [STACK API KEY] ``` ## `csdx cm:entries:publish-non-localized-fields [-a ] [--retry-failed ] [--bulk-publish ] [--source-env ] [--content-types ] [-e ] [-c ] [-y] [--branch ]` @@ -981,6 +988,7 @@ FLAGS -a, --alias= Alias(name) for the management token -c, --config= Path to the config file -e, --environments=... Destination environments + -k, --stack-api-key= Stack api key to be used -l, --locales=... Locales where edited entries will be published -y, --yes Agree to process the command with the current configuration --api-version= API Version to be used. Values [Default: 3, Nested Reference Publishing: 3.2]. @@ -1031,6 +1039,12 @@ EXAMPLES Using --branch $ csdx cm:entries:publish-modified --content-types [CONTENT TYPE 1] [CONTENT TYPE 2] --source-env [SOURCE_ENV] -e [ENVIRONMENT 1] [ENVIRONMENT 2] --locales [LOCALE 1] [LOCALE 2] -a [MANAGEMENT TOKEN ALIAS] --branch [BRANCH NAME] + + + + Using --stack-api-key + + $ csdx cm:entries:publish-modified --content-types [CONTENT TYPE 1] [CONTENT TYPE 2] --source-env [SOURCE_ENV] -e [ENVIRONMENT 1] [ENVIRONMENT 2] --locales [LOCALE 1] [LOCALE 2] -stack-api-key [STACK API KEY] ``` _See code: [src/commands/cm/entries/publish-modified.js](https://github.com/contentstack/cli/blob/main/packages/contentstack-bulk-publish/src/commands/cm/entries/publish-modified.js)_ diff --git a/packages/contentstack-bulk-publish/src/commands/cm/entries/publish-modified.js b/packages/contentstack-bulk-publish/src/commands/cm/entries/publish-modified.js index 561a6873d4..1b1bf24130 100644 --- a/packages/contentstack-bulk-publish/src/commands/cm/entries/publish-modified.js +++ b/packages/contentstack-bulk-publish/src/commands/cm/entries/publish-modified.js @@ -207,6 +207,9 @@ PublishModifiedCommand.examples = [ '', 'Using --branch', 'csdx cm:entries:publish-modified --content-types [CONTENT TYPE 1] [CONTENT TYPE 2] --source-env [SOURCE_ENV] -e [ENVIRONMENT 1] [ENVIRONMENT 2] --locales [LOCALE 1] [LOCALE 2] -a [MANAGEMENT TOKEN ALIAS] --branch [BRANCH NAME]', + '', + 'Using --stack-api-key', + 'csdx cm:entries:publish-modified --content-types [CONTENT TYPE 1] [CONTENT TYPE 2] --source-env [SOURCE_ENV] -e [ENVIRONMENT 1] [ENVIRONMENT 2] --locales [LOCALE 1] [LOCALE 2] -stack-api-key [STACK API KEY]', ]; PublishModifiedCommand.aliases = ['cm:bulk-publish:entry-edits']; From 74dbcc7470a4500c37e3b69c961820b0adaa6a84 Mon Sep 17 00:00:00 2001 From: Vikram Kalta Date: Mon, 10 Jul 2023 15:01:51 +0100 Subject: [PATCH 03/10] feat(bulk-publish): added support for basic and oauth auth --- packages/contentstack-bulk-publish/README.md | 14 ++++++++ .../entries/publish-non-localized-fields.js | 35 ++++++++++++++----- 2 files changed, 40 insertions(+), 9 deletions(-) diff --git a/packages/contentstack-bulk-publish/README.md b/packages/contentstack-bulk-publish/README.md index 89268db26d..00e824447b 100644 --- a/packages/contentstack-bulk-publish/README.md +++ b/packages/contentstack-bulk-publish/README.md @@ -649,6 +649,7 @@ FLAGS -a, --alias= Alias(name) for the management token -c, --config= Path to the config file -e, --environments=... Destination environments + -k, --stack-api-key= Stack api key to be used -y, --yes Agree to process the command with the current configuration --api-version= API Version to be used. Values [Default: 3, Nested Reference Publishing: 3.2]. --bulk-publish= [default: true] This flag is set to true by default. It indicates that contentstack's @@ -695,6 +696,12 @@ EXAMPLES Using --branch flag $ csdx cm:entries:publish-non-localized-fields --content-types [CONTENT TYPE 1] [CONTENT TYPE 2] --environments [ENVIRONMENT 1] [ENVIRONMENT 2] --alias [MANAGEMENT TOKEN ALIAS] --source-env [SOURCE ENV] --branch [BRANCH NAME] + + + + Using --stack-api-key flag + + $ csdx cm:entries:publish-non-localized-fields --content-types [CONTENT TYPE 1] [CONTENT TYPE 2] --environments [ENVIRONMENT 1] [ENVIRONMENT 2] --stack-api-key [STACK API KEY] --source-env [SOURCE ENV] ``` ## `csdx cm:bulk-publish:revert` @@ -1050,6 +1057,7 @@ FLAGS -a, --alias= Alias(name) for the management token -c, --config= Path to the config file -e, --environments=... Destination environments + -k, --stack-api-key= Stack api key to be used -y, --yes Agree to process the command with the current configuration --api-version= API Version to be used. Values [Default: 3, Nested Reference Publishing: 3.2]. --bulk-publish= [default: true] This flag is set to true by default. It indicates that contentstack's @@ -1096,6 +1104,12 @@ EXAMPLES Using --branch flag $ csdx cm:entries:publish-non-localized-fields --content-types [CONTENT TYPE 1] [CONTENT TYPE 2] --environments [ENVIRONMENT 1] [ENVIRONMENT 2] --alias [MANAGEMENT TOKEN ALIAS] --source-env [SOURCE ENV] --branch [BRANCH NAME] + + + + Using --stack-api-key flag + + $ csdx cm:entries:publish-non-localized-fields --content-types [CONTENT TYPE 1] [CONTENT TYPE 2] --environments [ENVIRONMENT 1] [ENVIRONMENT 2] --stack-api-key [STACK API KEY] --source-env [SOURCE ENV] ``` _See code: [src/commands/cm/entries/publish-non-localized-fields.js](https://github.com/contentstack/cli/blob/main/packages/contentstack-bulk-publish/src/commands/cm/entries/publish-non-localized-fields.js)_ diff --git a/packages/contentstack-bulk-publish/src/commands/cm/entries/publish-non-localized-fields.js b/packages/contentstack-bulk-publish/src/commands/cm/entries/publish-non-localized-fields.js index 3fa6fe71c6..e3e219a511 100644 --- a/packages/contentstack-bulk-publish/src/commands/cm/entries/publish-non-localized-fields.js +++ b/packages/contentstack-bulk-publish/src/commands/cm/entries/publish-non-localized-fields.js @@ -40,25 +40,34 @@ class NonlocalizedFieldChangesCommand extends Command { let stack; if (!updatedFlags.retryFailed) { updatedFlags.bulkPublish = updatedFlags.bulkPublish === 'false' ? false : true; - // Validate management token alias. - try { - this.getToken(updatedFlags.alias); - } catch (error) { - this.error( - `The configured management token alias ${updatedFlags.alias} has not been added yet. Add it using 'csdx auth:tokens:add -a ${updatedFlags.alias}'`, - { exit: 2 }, - ); - } config = { alias: updatedFlags.alias, host: this.cmaHost, cda: this.cdaHost, branch: nonlocalizedFieldChangesFlags.branch, }; + if (updatedFlags.alias) { + try { + this.getToken(updatedFlags.alias); + config.alias = updatedFlags.alias; + } catch (error) { + this.error( + `The configured management token alias ${updatedFlags.alias} has not been added yet. Add it using 'csdx auth:tokens:add -a ${updatedFlags.alias}'`, + { exit: 2 }, + ); + } + } else if (updatedFlags['stack-api-key']) { + config.stackApiKey = updatedFlags['stack-api-key']; + } else { + this.error('Please use `--alias` or `--stack-api-key` to proceed.', { exit: 2 }); + } stack = await getStack(config); } if (await this.confirmFlags(updatedFlags)) { try { + if (process.env.NODE_ENV === 'test') { + return; + } if (!updatedFlags.retryFailed) { await start(updatedFlags, stack, config); } else { @@ -122,6 +131,11 @@ NonlocalizedFieldChangesCommand.flags = { char: 'a', description: 'Alias(name) for the management token', }), + 'stack-api-key': flags.string({ + char: 'k', + description: 'Stack api key to be used', + required: false, + }), 'retry-failed': flags.string({ description: 'Retry publishing failed entries from the logfile', }), @@ -204,6 +218,9 @@ NonlocalizedFieldChangesCommand.examples = [ '', 'Using --branch flag', 'csdx cm:entries:publish-non-localized-fields --content-types [CONTENT TYPE 1] [CONTENT TYPE 2] --environments [ENVIRONMENT 1] [ENVIRONMENT 2] --alias [MANAGEMENT TOKEN ALIAS] --source-env [SOURCE ENV] --branch [BRANCH NAME]', + '', + 'Using --stack-api-key flag', + 'csdx cm:entries:publish-non-localized-fields --content-types [CONTENT TYPE 1] [CONTENT TYPE 2] --environments [ENVIRONMENT 1] [ENVIRONMENT 2] --stack-api-key [STACK API KEY] --source-env [SOURCE ENV]', ]; NonlocalizedFieldChangesCommand.aliases = ['cm:bulk-publish:nonlocalized-field-changes']; From deba0998cecd359edbcf1ceefc1a0b46e6f757df Mon Sep 17 00:00:00 2001 From: Vikram Kalta Date: Tue, 11 Jul 2023 11:59:06 +0100 Subject: [PATCH 04/10] feat(bulk-publish): added oauth support for unpublished entries cmd --- packages/contentstack-bulk-publish/README.md | 14 +++++++++ .../cm/entries/publish-only-unpublished.js | 7 +++++ .../src/services/publish-only-unpublished.js | 30 ++++++++++--------- 3 files changed, 37 insertions(+), 14 deletions(-) diff --git a/packages/contentstack-bulk-publish/README.md b/packages/contentstack-bulk-publish/README.md index 89268db26d..0bfea30070 100644 --- a/packages/contentstack-bulk-publish/README.md +++ b/packages/contentstack-bulk-publish/README.md @@ -838,6 +838,7 @@ FLAGS bulkpublish API will be used to publish the entries -c, --config= Path to the config file -e, --environments=... Destination environments + -k, --stack-api-key= Stack api key to be used -y, --yes Agree to process the command with the current configuration --api-version= API Version to be used. Values [Default: 3, Nested Reference Publishing: 3.2]. --content-types=... The Contenttypes from which entries will be published @@ -884,6 +885,12 @@ EXAMPLES Using --branch $ csdx cm:entries:publish-only-unpublished -b --content-types [CONTENT TYPES] -e [ENVIRONMENTS] --locales LOCALE -a [MANAGEMENT TOKEN ALIAS] --branch [BRANCH NAME] -source-env [SOURCE ENV] + + + + Using --stack-api-key + + $ csdx cm:entries:publish-only-unpublished -b --content-types [CONTENT TYPES] -e [ENVIRONMENTS] --locales LOCALE -a [MANAGEMENT TOKEN ALIAS] --stack-api-key [STACK API KEY] -source-env [SOURCE ENV] ``` ## `csdx cm:entries:publish [-a ] [--retry-failed ] [--bulk-publish ] [--publish-all-content-types] [--content-types ] [--locales ] [-e ] [-c ] [-y] [--branch ] [--delivery-token ] [--source-env ]` @@ -1118,6 +1125,7 @@ FLAGS bulkpublish API will be used to publish the entries -c, --config= Path to the config file -e, --environments=... Destination environments + -k, --stack-api-key= Stack api key to be used -y, --yes Agree to process the command with the current configuration --api-version= API Version to be used. Values [Default: 3, Nested Reference Publishing: 3.2]. --content-types=... The Contenttypes from which entries will be published @@ -1164,6 +1172,12 @@ EXAMPLES Using --branch $ csdx cm:entries:publish-only-unpublished -b --content-types [CONTENT TYPES] -e [ENVIRONMENTS] --locales LOCALE -a [MANAGEMENT TOKEN ALIAS] --branch [BRANCH NAME] -source-env [SOURCE ENV] + + + + Using --stack-api-key + + $ csdx cm:entries:publish-only-unpublished -b --content-types [CONTENT TYPES] -e [ENVIRONMENTS] --locales LOCALE -a [MANAGEMENT TOKEN ALIAS] --stack-api-key [STACK API KEY] -source-env [SOURCE ENV] ``` _See code: [src/commands/cm/entries/publish-only-unpublished.js](https://github.com/contentstack/cli/blob/main/packages/contentstack-bulk-publish/src/commands/cm/entries/publish-only-unpublished.js)_ diff --git a/packages/contentstack-bulk-publish/src/commands/cm/entries/publish-only-unpublished.js b/packages/contentstack-bulk-publish/src/commands/cm/entries/publish-only-unpublished.js index f7f47b4794..8fddb670c7 100644 --- a/packages/contentstack-bulk-publish/src/commands/cm/entries/publish-only-unpublished.js +++ b/packages/contentstack-bulk-publish/src/commands/cm/entries/publish-only-unpublished.js @@ -22,6 +22,10 @@ But, if retry-failed flag is set, then only a logfile is required PublishOnlyUnpublished.flags = { alias: flags.string({ char: 'a', description: 'Alias(name) for the management token' }), + 'stack-api-key': flags.string({ + char: 'k', + description: 'Stack api key to be used', + }), retryFailed: flags.string({ char: 'r', hidden: true, @@ -102,6 +106,9 @@ PublishOnlyUnpublished.examples = [ '', 'Using --branch', 'csdx cm:entries:publish-only-unpublished -b --content-types [CONTENT TYPES] -e [ENVIRONMENTS] --locales LOCALE -a [MANAGEMENT TOKEN ALIAS] --branch [BRANCH NAME] -source-env [SOURCE ENV]', + '', + 'Using --stack-api-key', + 'csdx cm:entries:publish-only-unpublished -b --content-types [CONTENT TYPES] -e [ENVIRONMENTS] --locales LOCALE -a [MANAGEMENT TOKEN ALIAS] --stack-api-key [STACK API KEY] -source-env [SOURCE ENV]', ]; PublishOnlyUnpublished.aliases = ['cm:bulk-publish:unpublished-entries']; diff --git a/packages/contentstack-bulk-publish/src/services/publish-only-unpublished.js b/packages/contentstack-bulk-publish/src/services/publish-only-unpublished.js index 9ceb714b89..356ed47356 100644 --- a/packages/contentstack-bulk-publish/src/services/publish-only-unpublished.js +++ b/packages/contentstack-bulk-publish/src/services/publish-only-unpublished.js @@ -24,27 +24,29 @@ async function publishOnlyUnpublishedService(UnpublishedEntriesCommand) { if (validate.apply(this, [updatedFlags])) { let stack; if (!updatedFlags.retryFailed) { - if (!updatedFlags.alias) { - updatedFlags.alias = await cliux.prompt('Please enter the management token alias to be used'); - } - updatedFlags.bulkPublish = updatedFlags.bulkPublish === 'false' ? false : true; - // Validate management token alias. - try { - this.getToken(updatedFlags.alias); - } catch (error) { - this.error( - `The configured management token alias ${updatedFlags.alias} has not been added yet. Add it using 'csdx auth:tokens:add -a ${updatedFlags.alias}'`, - { exit: 2 }, - ); - } config = { alias: updatedFlags.alias, host: this.cmaHost, cda: this.cdaHost, branch: unpublishedEntriesFlags.branch, }; - stack = await getStack(config); + if (updatedFlags.alias) { + try { + this.getToken(updatedFlags.alias); + } catch (error) { + this.error( + `The configured management token alias ${updatedFlags.alias} has not been added yet. Add it using 'csdx auth:tokens:add -a ${updatedFlags.alias}'`, + { exit: 2 }, + ); + } + } else if (updatedFlags['stack-api-key']) { + config.stackApiKey = updatedFlags['stack-api-key']; + } else { + this.error('Please use `--alias` or `--stack-api-key` to proceed.', { exit: 2 }); + } } + updatedFlags.bulkPublish = updatedFlags.bulkPublish === 'false' ? false : true; + stack = await getStack(config); if (await confirmFlags(updatedFlags)) { try { if (!updatedFlags.retryFailed) { From 3080644fa3330fed19e31b08244f541693cd9011 Mon Sep 17 00:00:00 2001 From: Vikram Kalta Date: Tue, 11 Jul 2023 12:41:27 +0100 Subject: [PATCH 05/10] feat(bulk-publish): added oauth support for entries published cmd --- packages/contentstack-bulk-publish/README.md | 14 ++++++++ .../src/commands/cm/entries/publish.js | 35 ++++++++++++------- 2 files changed, 36 insertions(+), 13 deletions(-) diff --git a/packages/contentstack-bulk-publish/README.md b/packages/contentstack-bulk-publish/README.md index 89268db26d..4d69cdf8f6 100644 --- a/packages/contentstack-bulk-publish/README.md +++ b/packages/contentstack-bulk-publish/README.md @@ -506,6 +506,7 @@ FLAGS -c, --config= Path for the external config file (A new config file can be generated at the current working directory using `csdx cm:bulk-publish:configure -a [ALIAS]`) -e, --environments=... Environments where entries will be published + -k, --stack-api-key= Stack api key to be used -l, --locales=... Locales where entries will be published -y, --yes Agree to process the command with the current configuration --api-version= API Version to be used. Values [Default: 3, Nested Reference Publishing: 3.2]. @@ -565,6 +566,12 @@ EXAMPLES Using --source-env $ csdx cm:entries:publish --content-types [CONTENT TYPE 1] [CONTENT TYPE 2] -e [ENVIRONMENT 1] [ENVIRONMENT 2] --locales [LOCALE 1] [LOCALE 2] -a [MANAGEMENT TOKEN ALIAS] --source-env [SOURCE ENVIRONMENT] --delivery-token [DELIVERY TOKEN] + + + + Using --stack-api-key + + $ csdx cm:entries:publish -e [ENVIRONMENT 1] [ENVIRONMENT 2] --locales [LOCALE 1] [LOCALE 2] --stack-api-key [STACK API KEY] --source-env [SOURCE ENVIRONMENT] --delivery-token [DELIVERY TOKEN] ``` ## `csdx cm:entries:publish-modified [-a ] [--retry-failed ] [--bulk-publish ] [--source-env ] [--content-types ] [--locales ] [-e ] [-c ] [-y] [--branch ]` @@ -903,6 +910,7 @@ FLAGS -c, --config= Path for the external config file (A new config file can be generated at the current working directory using `csdx cm:bulk-publish:configure -a [ALIAS]`) -e, --environments=... Environments where entries will be published + -k, --stack-api-key= Stack api key to be used -l, --locales=... Locales where entries will be published -y, --yes Agree to process the command with the current configuration --api-version= API Version to be used. Values [Default: 3, Nested Reference Publishing: 3.2]. @@ -962,6 +970,12 @@ EXAMPLES Using --source-env $ csdx cm:entries:publish --content-types [CONTENT TYPE 1] [CONTENT TYPE 2] -e [ENVIRONMENT 1] [ENVIRONMENT 2] --locales [LOCALE 1] [LOCALE 2] -a [MANAGEMENT TOKEN ALIAS] --source-env [SOURCE ENVIRONMENT] --delivery-token [DELIVERY TOKEN] + + + + Using --stack-api-key + + $ csdx cm:entries:publish -e [ENVIRONMENT 1] [ENVIRONMENT 2] --locales [LOCALE 1] [LOCALE 2] --stack-api-key [STACK API KEY] --source-env [SOURCE ENVIRONMENT] --delivery-token [DELIVERY TOKEN] ``` _See code: [src/commands/cm/entries/publish.js](https://github.com/contentstack/cli/blob/main/packages/contentstack-bulk-publish/src/commands/cm/entries/publish.js)_ diff --git a/packages/contentstack-bulk-publish/src/commands/cm/entries/publish.js b/packages/contentstack-bulk-publish/src/commands/cm/entries/publish.js index 74cec57b1d..8b50c8b1ee 100644 --- a/packages/contentstack-bulk-publish/src/commands/cm/entries/publish.js +++ b/packages/contentstack-bulk-publish/src/commands/cm/entries/publish.js @@ -37,25 +37,27 @@ class PublishEntriesCommand extends Command { if (this.validate(updatedFlags)) { let stack; if (!updatedFlags.retryFailed) { - if (!updatedFlags.alias) { - updatedFlags.alias = await cliux.prompt('Provide the alias of the management token to use'); - } - updatedFlags.bulkPublish = updatedFlags.bulkPublish !== 'false'; - // Validate management token alias. - try { - this.getToken(updatedFlags.alias); - } catch (error) { - this.error( - `The configured management token alias ${updatedFlags.alias} has not been added yet. Add it using 'csdx auth:tokens:add -a ${updatedFlags.alias}'`, - { exit: 2 }, - ); - } config = { alias: updatedFlags.alias, host: this.cmaHost, cda: this.cdaHost, branch: entriesFlags.branch, }; + if (updatedFlags.alias) { + try { + this.getToken(updatedFlags.alias); + } catch (error) { + this.error( + `The configured management token alias ${updatedFlags.alias} has not been added yet. Add it using 'csdx auth:tokens:add -a ${updatedFlags.alias}'`, + { exit: 2 }, + ); + } + } else if (updatedFlags['stack-api-key']) { + config.stackApiKey = updatedFlags['stack-api-key']; + } else { + this.error('Please use `--alias` or `--stack-api-key` to proceed.', { exit: 2 }); + } + updatedFlags.bulkPublish = updatedFlags.bulkPublish !== 'false'; stack = await getStack(config); } if (await this.confirmFlags(updatedFlags)) { @@ -167,6 +169,10 @@ But, if retry-failed flag is set, then only a logfile is required PublishEntriesCommand.flags = { alias: flags.string({ char: 'a', description: 'Alias(name) for the management token' }), + 'stack-api-key': flags.string({ + char: 'k', + description: 'Stack api key to be used', + }), retryFailed: flags.string({ char: 'r', description: @@ -258,6 +264,9 @@ PublishEntriesCommand.examples = [ '', 'Using --source-env', 'csdx cm:entries:publish --content-types [CONTENT TYPE 1] [CONTENT TYPE 2] -e [ENVIRONMENT 1] [ENVIRONMENT 2] --locales [LOCALE 1] [LOCALE 2] -a [MANAGEMENT TOKEN ALIAS] --source-env [SOURCE ENVIRONMENT] --delivery-token [DELIVERY TOKEN]', + '', + 'Using --stack-api-key', + 'csdx cm:entries:publish -e [ENVIRONMENT 1] [ENVIRONMENT 2] --locales [LOCALE 1] [LOCALE 2] --stack-api-key [STACK API KEY] --source-env [SOURCE ENVIRONMENT] --delivery-token [DELIVERY TOKEN]', ]; PublishEntriesCommand.aliases = ['cm:bulk-publish:entries']; From a10a0b5b09bba256b8149e9079a5597acff08554 Mon Sep 17 00:00:00 2001 From: Vikram Kalta Date: Wed, 12 Jul 2023 11:31:57 +0100 Subject: [PATCH 06/10] feat(bulk-publish): added oauth support for unpublish cmd --- packages/contentstack-bulk-publish/README.md | 39 +++++++++-------- .../src/commands/cm/entries/unpublish.js | 43 +++++++++++-------- 2 files changed, 48 insertions(+), 34 deletions(-) diff --git a/packages/contentstack-bulk-publish/README.md b/packages/contentstack-bulk-publish/README.md index 89268db26d..a2c44e5e0c 100644 --- a/packages/contentstack-bulk-publish/README.md +++ b/packages/contentstack-bulk-publish/README.md @@ -1174,24 +1174,25 @@ Unpublish entries from the given environment ``` USAGE - $ csdx cm:entries:unpublish [-a ] [-e ] [-c ] [-y] [--locale ] [--branch ] - [--retry-failed ] [--bulk-unpublish ] [--api-version ] [--content-type ] + $ csdx cm:entries:unpublish [-a ] [-k ] [-e ] [-c ] [-y] [--locale ] [--branch + ] [--retry-failed ] [--bulk-unpublish ] [--api-version ] [--content-type ] [--delivery-token ] FLAGS - -a, --alias= Alias(name) for the management token - -c, --config= Path to the config file - -e, --environment= Source Environment - -y, --yes Agree to process the command with the current configuration - --api-version= API Version to be used. Values [Default: 3, Nested Reference Publishing: 3.2]. - --branch= [default: main] Specify the branch to fetch the content (by default the main branch is - selected) - --bulk-unpublish= [default: true] This flag is set to true by default. It indicates that contentstack's - bulkpublish API will be used to unpublish the entries - --content-type= Content type filter - --delivery-token= Delivery token for source environment - --locale= Locale filter - --retry-failed= Retry publishing failed entries from the logfile + -a, --alias= Alias(name) for the management token + -c, --config= Path to the config file + -e, --environment= Source Environment + -k, --stack-api-key= Stack api key to be used + -y, --yes Agree to process the command with the current configuration + --api-version= API Version to be used. Values [Default: 3, Nested Reference Publishing: 3.2]. + --branch= [default: main] Specify the branch to fetch the content (by default the main branch is + selected) + --bulk-unpublish= [default: true] This flag is set to true by default. It indicates that contentstack's + bulkpublish API will be used to unpublish the entries + --content-type= Content type filter + --delivery-token= Delivery token for source environment + --locale= Locale filter + --retry-failed= Retry publishing failed entries from the logfile DESCRIPTION Unpublish entries from the given environment @@ -1223,11 +1224,15 @@ EXAMPLES - - Using --branch flag $ csdx cm:stacks:unpublish --bulk-unpublish --content-type [CONTENT TYPE] --environment [SOURCE ENV] --locale [LOCALE] --alias [MANAGEMENT TOKEN ALIAS] --delivery-token [DELIVERY TOKEN] --branch [BRANCH NAME] + + + + Using --stack-api-key flag + + $ csdx cm:stacks:unpublish --bulk-unpublish --content-type [CONTENT TYPE] --environment [SOURCE ENV] --locale [LOCALE] --stack-api-key [STACK API KEY] --delivery-token [DELIVERY TOKEN] ``` _See code: [src/commands/cm/entries/unpublish.js](https://github.com/contentstack/cli/blob/main/packages/contentstack-bulk-publish/src/commands/cm/entries/unpublish.js)_ diff --git a/packages/contentstack-bulk-publish/src/commands/cm/entries/unpublish.js b/packages/contentstack-bulk-publish/src/commands/cm/entries/unpublish.js index 48f9569aa5..605f19caa6 100644 --- a/packages/contentstack-bulk-publish/src/commands/cm/entries/unpublish.js +++ b/packages/contentstack-bulk-publish/src/commands/cm/entries/unpublish.js @@ -35,28 +35,31 @@ class UnpublishCommand extends Command { if (this.validate(updatedFlags)) { let stack; if (!updatedFlags.retryFailed) { - if (!updatedFlags.alias) { - updatedFlags.alias = await cliux.prompt('Please enter the management token alias to be used'); - } - if (!updatedFlags.deliveryToken) { - updatedFlags.deliveryToken = await cliux.prompt('Enter delivery token of your source environment'); - } - updatedFlags.bulkUnpublish = updatedFlags.bulkUnpublish === 'false' ? false : true; - // Validate management token alias. - try { - this.getToken(updatedFlags.alias); - } catch (error) { - this.error( - `The configured management token alias ${updatedFlags.alias} has not been added yet. Add it using 'csdx auth:tokens:add --alias ${updatedFlags.alias}'`, - { exit: 2 }, - ); - } config = { alias: updatedFlags.alias, host: this.cmaHost, cda: this.cdaHost, branch: unpublishFlags.branch, }; + if (updatedFlags.alias) { + try { + this.getToken(updatedFlags.alias); + } catch (error) { + this.error( + `The configured management token alias ${updatedFlags.alias} has not been added yet. Add it using 'csdx auth:tokens:add --alias ${updatedFlags.alias}'`, + { exit: 2 }, + ); + } + } else if (updatedFlags['stack-api-key']) { + config.stackApiKey = updatedFlags['stack-api-key']; + } else { + this.error('Please use `--alias` or `--stack-api-key` to proceed.', { exit: 2 }); + } + if (!updatedFlags.deliveryToken) { + updatedFlags.deliveryToken = await cliux.prompt('Enter delivery token of your source environment'); + } + updatedFlags.bulkUnpublish = updatedFlags.bulkUnpublish === 'false' ? false : true; + stack = await getStack(config); } if (!updatedFlags.deliveryToken && updatedFlags.deliveryToken.length === 0) { @@ -134,6 +137,10 @@ UnpublishCommand.flags = { char: 'a', description: 'Alias(name) for the management token', }), + 'stack-api-key': flags.string({ + char: 'k', + description: 'Stack api key to be used', + }), environment: flags.string({ char: 'e', description: 'Source Environment', @@ -184,9 +191,11 @@ UnpublishCommand.examples = [ 'Using --retry-failed flag', 'csdx cm:stacks:unpublish --retry-failed [LOG FILE NAME]', '', - '', 'Using --branch flag', 'csdx cm:stacks:unpublish --bulk-unpublish --content-type [CONTENT TYPE] --environment [SOURCE ENV] --locale [LOCALE] --alias [MANAGEMENT TOKEN ALIAS] --delivery-token [DELIVERY TOKEN] --branch [BRANCH NAME]', + '', + 'Using --stack-api-key flag', + 'csdx cm:stacks:unpublish --bulk-unpublish --content-type [CONTENT TYPE] --environment [SOURCE ENV] --locale [LOCALE] --stack-api-key [STACK API KEY] --delivery-token [DELIVERY TOKEN]', ]; module.exports = UnpublishCommand; From 8810de9a8eec661d984d55b6dd0598b5487f53ce Mon Sep 17 00:00:00 2001 From: Vikram Kalta Date: Wed, 12 Jul 2023 12:33:04 +0100 Subject: [PATCH 07/10] feat(bulk-publish): added oauth support for update and publish cmd --- packages/contentstack-bulk-publish/README.md | 22 ++++++++-- .../commands/cm/entries/update-and-publish.js | 41 ++++++++++++------- 2 files changed, 44 insertions(+), 19 deletions(-) diff --git a/packages/contentstack-bulk-publish/README.md b/packages/contentstack-bulk-publish/README.md index 89268db26d..1f0334bd67 100644 --- a/packages/contentstack-bulk-publish/README.md +++ b/packages/contentstack-bulk-publish/README.md @@ -231,6 +231,7 @@ FLAGS -a, --alias= Alias(name) for the management token -c, --config= Path to the config file -e, --environments=... Environments where entries will be published + -k, --stack-api-key= Stack api key to be used -l, --locales=... Locales where entries will be published -t, --contentTypes=... The Contenttypes from which entries will be published -y, --yes Agree to process the command with the current configuration @@ -256,7 +257,7 @@ ALIASES EXAMPLES General Usage - $ csdx cm:entries:update-and-publish --content-types [CONTENT TYPE 1] [CONTENT TYPE 2] -e [ENVIRONMENT 1] [ENVIRONMENT 2] --locale [LOCALE 1] [LOCALE 2] -a [MANAGEMENT TOKEN ALIAS] + $ csdx cm:entries:update-and-publish --content-types [CONTENT TYPE 1] [CONTENT TYPE 2] -e [ENVIRONMENT 1] [ENVIRONMENT 2] --locales [LOCALE 1] [LOCALE 2] -a [MANAGEMENT TOKEN ALIAS] @@ -278,7 +279,13 @@ EXAMPLES Using --branch - $ csdx cm:entries:update-and-publish --content-types [CONTENT TYPE 1] [CONTENT TYPE 2] -e [ENVIRONMENT 1] [ENVIRONMENT 2] --locale [LOCALE 1] [LOCALE 2] -a [MANAGEMENT TOKEN ALIAS] --branch [BRANCH NAME] + $ csdx cm:entries:update-and-publish --content-types [CONTENT TYPE 1] [CONTENT TYPE 2] -e [ENVIRONMENT 1] [ENVIRONMENT 2] --locales [LOCALE 1] [LOCALE 2] -a [MANAGEMENT TOKEN ALIAS] --branch [BRANCH NAME] + + + + Using --stack-api-key + + $ csdx cm:entries:update-and-publish --content-types [CONTENT TYPE 1] [CONTENT TYPE 2] -e [ENVIRONMENT 1] [ENVIRONMENT 2] --locales [LOCALE 1] [LOCALE 2] --stack-api-key [STACK API KEY] ``` ## `csdx cm:assets:publish [-a ] [--retry-failed ] [-e ] [--folder-uid ] [--bulk-publish ] [-c ] [-y] [--locales ] [--branch ] [--delivery-token ] [--source-env ]` @@ -1247,6 +1254,7 @@ FLAGS -a, --alias= Alias(name) for the management token -c, --config= Path to the config file -e, --environments=... Environments where entries will be published + -k, --stack-api-key= Stack api key to be used -l, --locales=... Locales where entries will be published -t, --contentTypes=... The Contenttypes from which entries will be published -y, --yes Agree to process the command with the current configuration @@ -1272,7 +1280,7 @@ ALIASES EXAMPLES General Usage - $ csdx cm:entries:update-and-publish --content-types [CONTENT TYPE 1] [CONTENT TYPE 2] -e [ENVIRONMENT 1] [ENVIRONMENT 2] --locale [LOCALE 1] [LOCALE 2] -a [MANAGEMENT TOKEN ALIAS] + $ csdx cm:entries:update-and-publish --content-types [CONTENT TYPE 1] [CONTENT TYPE 2] -e [ENVIRONMENT 1] [ENVIRONMENT 2] --locales [LOCALE 1] [LOCALE 2] -a [MANAGEMENT TOKEN ALIAS] @@ -1294,7 +1302,13 @@ EXAMPLES Using --branch - $ csdx cm:entries:update-and-publish --content-types [CONTENT TYPE 1] [CONTENT TYPE 2] -e [ENVIRONMENT 1] [ENVIRONMENT 2] --locale [LOCALE 1] [LOCALE 2] -a [MANAGEMENT TOKEN ALIAS] --branch [BRANCH NAME] + $ csdx cm:entries:update-and-publish --content-types [CONTENT TYPE 1] [CONTENT TYPE 2] -e [ENVIRONMENT 1] [ENVIRONMENT 2] --locales [LOCALE 1] [LOCALE 2] -a [MANAGEMENT TOKEN ALIAS] --branch [BRANCH NAME] + + + + Using --stack-api-key + + $ csdx cm:entries:update-and-publish --content-types [CONTENT TYPE 1] [CONTENT TYPE 2] -e [ENVIRONMENT 1] [ENVIRONMENT 2] --locales [LOCALE 1] [LOCALE 2] --stack-api-key [STACK API KEY] ``` _See code: [src/commands/cm/entries/update-and-publish.js](https://github.com/contentstack/cli/blob/main/packages/contentstack-bulk-publish/src/commands/cm/entries/update-and-publish.js)_ diff --git a/packages/contentstack-bulk-publish/src/commands/cm/entries/update-and-publish.js b/packages/contentstack-bulk-publish/src/commands/cm/entries/update-and-publish.js index 20a6631f74..8c08408ad2 100644 --- a/packages/contentstack-bulk-publish/src/commands/cm/entries/update-and-publish.js +++ b/packages/contentstack-bulk-publish/src/commands/cm/entries/update-and-publish.js @@ -30,25 +30,29 @@ class UpdateAndPublishCommand extends Command { if (this.validate(updatedFlags)) { let stack; if (!updatedFlags.retryFailed) { - if (!updatedFlags.alias) { - updatedFlags.alias = await cliux.prompt('Please enter the management token alias to be used'); - } - updatedFlags.bulkPublish = updatedFlags.bulkPublish === 'false' ? false : true; - // Validate management token alias. - try { - this.getToken(updatedFlags.alias); - } catch (error) { - this.error( - `The configured management token alias ${updatedFlags.alias} has not been added yet. Add it using 'csdx auth:tokens:add -a ${updatedFlags.alias}'`, - { exit: 2 }, - ); - } config = { alias: updatedFlags.alias, host: this.cmaHost, cda: this.cdaHost, branch: addFieldsFlags.branch, }; + if (updatedFlags.alias) { + try { + this.getToken(updatedFlags.alias); + config.alias = updatedFlags.alias; + } catch (error) { + this.error( + `The configured management token alias ${updatedFlags.alias} has not been added yet. Add it using 'csdx auth:tokens:add -a ${updatedFlags.alias}'`, + { exit: 2 }, + ); + } + } else if (updatedFlags['stack-api-key']) { + config.stackApiKey = updatedFlags['stack-api-key']; + } else { + this.error('Please use `--alias` or `--stack-api-key` to proceed.', { exit: 2 }); + } + updatedFlags.bulkPublish = updatedFlags.bulkPublish === 'false' ? false : true; + stack = await getStack(config); } if (await this.confirmFlags(updatedFlags)) { @@ -114,6 +118,10 @@ But, if retry-failed flag is set, then only a logfile is required UpdateAndPublishCommand.flags = { alias: flags.string({ char: 'a', description: 'Alias(name) for the management token' }), + 'stack-api-key': flags.string({ + char: 'k', + description: 'Stack api key to be used', + }), 'retry-failed': flags.string({ description: 'Retry publishing failed entries from the logfile (optional, overrides all other flags)', }), @@ -177,7 +185,7 @@ UpdateAndPublishCommand.flags = { UpdateAndPublishCommand.examples = [ 'General Usage', - 'csdx cm:entries:update-and-publish --content-types [CONTENT TYPE 1] [CONTENT TYPE 2] -e [ENVIRONMENT 1] [ENVIRONMENT 2] --locale [LOCALE 1] [LOCALE 2] -a [MANAGEMENT TOKEN ALIAS]', + 'csdx cm:entries:update-and-publish --content-types [CONTENT TYPE 1] [CONTENT TYPE 2] -e [ENVIRONMENT 1] [ENVIRONMENT 2] --locales [LOCALE 1] [LOCALE 2] -a [MANAGEMENT TOKEN ALIAS]', '', 'Using --config or -c flag', 'Generate a config file at the current working directory using `csdx cm:stacks:publish-configure -a [ALIAS]`', @@ -188,7 +196,10 @@ UpdateAndPublishCommand.examples = [ 'csdx cm:entries:update-and-publish --retry-failed [LOG FILE NAME]', '', 'Using --branch', - 'csdx cm:entries:update-and-publish --content-types [CONTENT TYPE 1] [CONTENT TYPE 2] -e [ENVIRONMENT 1] [ENVIRONMENT 2] --locale [LOCALE 1] [LOCALE 2] -a [MANAGEMENT TOKEN ALIAS] --branch [BRANCH NAME]', + 'csdx cm:entries:update-and-publish --content-types [CONTENT TYPE 1] [CONTENT TYPE 2] -e [ENVIRONMENT 1] [ENVIRONMENT 2] --locales [LOCALE 1] [LOCALE 2] -a [MANAGEMENT TOKEN ALIAS] --branch [BRANCH NAME]', + '', + 'Using --stack-api-key', + 'csdx cm:entries:update-and-publish --content-types [CONTENT TYPE 1] [CONTENT TYPE 2] -e [ENVIRONMENT 1] [ENVIRONMENT 2] --locales [LOCALE 1] [LOCALE 2] --stack-api-key [STACK API KEY]', ]; UpdateAndPublishCommand.aliases = ['cm:bulk-publish:add-fields']; From 3eeed33d06327b2f9c2198b56fe05fba311264e2 Mon Sep 17 00:00:00 2001 From: Vikram Kalta Date: Wed, 12 Jul 2023 13:02:59 +0100 Subject: [PATCH 08/10] feat(bulk-publish): added oauth support for configure cmd --- packages/contentstack-bulk-publish/README.md | 14 +++++++---- .../commands/cm/stacks/publish-configure.js | 23 +++++++++++-------- 2 files changed, 24 insertions(+), 13 deletions(-) diff --git a/packages/contentstack-bulk-publish/README.md b/packages/contentstack-bulk-publish/README.md index 89268db26d..eaa1a20a48 100644 --- a/packages/contentstack-bulk-publish/README.md +++ b/packages/contentstack-bulk-publish/README.md @@ -393,10 +393,11 @@ The configure command is used to generate a configuration file for publish scrip ``` USAGE - $ csdx cm:bulk-publish:configure [-a ] + $ csdx cm:bulk-publish:configure [-a ] [-k ] FLAGS - -a, --alias= Alias(name) for the management token + -a, --alias= Alias(name) for the management token + -k, --stack-api-key= Stack api key to be used DESCRIPTION The configure command is used to generate a configuration file for publish scripts. @@ -410,6 +411,8 @@ EXAMPLES $ csdx cm:stacks:publish-configure -a $ csdx cm:stacks:publish-configure --alias + + $ csdx cm:stacks:publish-configure --stack-api-key ``` ## `csdx cm:bulk-publish:cross-publish [-a ] [--retry-failed ] [--bulk-publish ] [--content-type ] [--locales ] [--source-env ] [--environments ] [--delivery-token ] [-c ] [-y] [--branch ] [--onlyAssets] [--onlyEntries]` @@ -1387,10 +1390,11 @@ The configure command is used to generate a configuration file for publish scrip ``` USAGE - $ csdx cm:stacks:publish-configure [-a ] + $ csdx cm:stacks:publish-configure [-a ] [-k ] FLAGS - -a, --alias= Alias(name) for the management token + -a, --alias= Alias(name) for the management token + -k, --stack-api-key= Stack api key to be used DESCRIPTION The configure command is used to generate a configuration file for publish scripts. @@ -1404,6 +1408,8 @@ EXAMPLES $ csdx cm:stacks:publish-configure -a $ csdx cm:stacks:publish-configure --alias + + $ csdx cm:stacks:publish-configure --stack-api-key ``` _See code: [src/commands/cm/stacks/publish-configure.js](https://github.com/contentstack/cli/blob/main/packages/contentstack-bulk-publish/src/commands/cm/stacks/publish-configure.js)_ diff --git a/packages/contentstack-bulk-publish/src/commands/cm/stacks/publish-configure.js b/packages/contentstack-bulk-publish/src/commands/cm/stacks/publish-configure.js index 83c2fcf9b0..9fe10f5aa6 100644 --- a/packages/contentstack-bulk-publish/src/commands/cm/stacks/publish-configure.js +++ b/packages/contentstack-bulk-publish/src/commands/cm/stacks/publish-configure.js @@ -9,22 +9,25 @@ class ConfigureCommand extends Command { async run() { const { flags: configureFlags } = await this.parse(ConfigureCommand); - if (!configureFlags.alias) { - configureFlags.alias = await cliux.prompt('Please enter the management token alias to be used'); - } - - try { - this.getToken(configureFlags.alias); - } catch (error) { - this.error(`The configured management token alias ${configureFlags.alias} has not been added yet. Add it using 'csdx auth:tokens:add -a ${configureFlags.alias}'`, { exit: 2 }) + if (configureFlags.alias) { + try { + this.getToken(configureFlags.alias); + } catch (error) { + this.error(`The configured management token alias ${configureFlags.alias} has not been added yet. Add it using 'csdx auth:tokens:add -a ${configureFlags.alias}'`, { exit: 2 }) + } + } else if (configureFlags['stack-api-key']) { + configureFlags.stackApiKey = configureFlags['stack-api-key']; + } else { + this.error('Please use `--alias` or `--stack-api-key` to proceed.', { exit: 2 }); } this.setConfig(configureFlags); this.log('The configuration has been saved successfully.'); } - setConfig({ alias }) { + setConfig({ alias, stackApiKey }) { if (alias) config.alias = alias; + else if (stackApiKey) config.stackApiKey = stackApiKey; fs.writeFileSync(path.join(process.cwd(), 'config.js'), `module.exports = ${JSON.stringify(config, null, 2)}`); } } @@ -33,12 +36,14 @@ ConfigureCommand.description = `The configure command is used to generate a conf ConfigureCommand.flags = { alias: flags.string({ char: 'a', description: 'Alias(name) for the management token' }), + 'stack-api-key': flags.string({ char: 'k', description: 'Stack api key to be used' }), }; ConfigureCommand.examples = [ 'csdx cm:stacks:publish-configure', 'csdx cm:stacks:publish-configure -a ', 'csdx cm:stacks:publish-configure --alias ', + 'csdx cm:stacks:publish-configure --stack-api-key ', ]; ConfigureCommand.aliases = ['cm:bulk-publish:configure']; From 2c0d40a69f5ad426dffe76c060242b7075ecfed8 Mon Sep 17 00:00:00 2001 From: Vikram Kalta Date: Fri, 14 Jul 2023 09:19:13 +0100 Subject: [PATCH 09/10] fix(bulk-publish): fixed config issue with stacks publish cmd --- .../src/commands/cm/stacks/publish.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/packages/contentstack-bulk-publish/src/commands/cm/stacks/publish.js b/packages/contentstack-bulk-publish/src/commands/cm/stacks/publish.js index 1c87e790dc..e1cae290e0 100644 --- a/packages/contentstack-bulk-publish/src/commands/cm/stacks/publish.js +++ b/packages/contentstack-bulk-publish/src/commands/cm/stacks/publish.js @@ -9,9 +9,8 @@ class StackPublishCommand extends Command { async run() { try { this.optionController = new OptionController(); - - this.entriesPublishReceiver = new EntriesPublishReceiverCommand(this.argv); - this.assetsPublishReceiver = new AssetsPublishReceiverCommand(this.argv); + this.entriesPublishReceiver = new EntriesPublishReceiverCommand(this.argv, this.config); + this.assetsPublishReceiver = new AssetsPublishReceiverCommand(this.argv, this.config); this.entriesAndAssetsPublishReceiver = new PublishEntriesAndAssetsCommand(); this.publishEntriesCommand = new PublishEntriesCommand(this.entriesPublishReceiver); From 230e18e2453bb037737c5158b3fc4ea83fa87574 Mon Sep 17 00:00:00 2001 From: Vikram Kalta Date: Mon, 17 Jul 2023 12:29:06 +0100 Subject: [PATCH 10/10] feat(bulk-publish): added oauth support for stacks unpublish cmd --- packages/contentstack-bulk-publish/README.md | 62 ++++++++++++------- .../src/commands/cm/stacks/unpublish.js | 42 ++++++++----- 2 files changed, 64 insertions(+), 40 deletions(-) diff --git a/packages/contentstack-bulk-publish/README.md b/packages/contentstack-bulk-publish/README.md index 89268db26d..5980fc2347 100644 --- a/packages/contentstack-bulk-publish/README.md +++ b/packages/contentstack-bulk-publish/README.md @@ -741,18 +741,19 @@ USAGE [--only-assets] [--only-entries] FLAGS - -B, --branch= [default: main] Specify the branch to fetch the content from (default is main branch) - -a, --alias= Alias(name) for the management token - -c, --config= Path to the config file - -e, --environment= Source Environment - -l, --locale= Locale filter - -y, --yes Agree to process the command with the current configuration - --api-version= API Version to be used. Values [Default: 3, Nested Reference Publishing: 3.2]. - --bulk-unpublish= [default: true] This flag is set to true by default. It indicates that contentstack's - bulkpublish API will be used to unpublish the entries and assets - --content-type= Content type filter - --delivery-token= Delivery token for source environment - --retry-failed= Retry publishing failed entries from the logfile (optional, overrides all other flags) + -B, --branch= [default: main] Specify the branch to fetch the content from (default is main branch) + -a, --alias= Alias(name) for the management token + -c, --config= Path to the config file + -e, --environment= Source Environment + -k, --stack-api-key= Stack api key to be used + -l, --locale= Locale filter + -y, --yes Agree to process the command with the current configuration + --api-version= API Version to be used. Values [Default: 3, Nested Reference Publishing: 3.2]. + --bulk-unpublish= [default: true] This flag is set to true by default. It indicates that contentstack's + bulkpublish API will be used to unpublish the entries and assets + --content-type= Content type filter + --delivery-token= Delivery token for source environment + --retry-failed= Retry publishing failed entries from the logfile (optional, overrides all other flags) DESCRIPTION Unpublish entries or assets of given content types from the specified environment @@ -818,6 +819,12 @@ EXAMPLES Using --branch flag $ csdx cm:stacks:unpublish --bulk-unpublish --content-type [CONTENT TYPE] --environment [SOURCE ENV] --locale [LOCALE] --alias [MANAGEMENT TOKEN ALIAS] --delivery-token [DELIVERY TOKEN] --branch [BRANCH NAME] + + + + Using --stack-api-key flag + + $ csdx cm:stacks:unpublish --bulk-unpublish --content-type [CONTENT TYPE] --environment [SOURCE ENV] --locale [LOCALE] --stack-api-key [STACK API KEY] --delivery-token [DELIVERY TOKEN] ``` ## `csdx cm:entries:publish-only-unpublished [-a ] [--retry-failed ] [--bulk-publish ] [--source-env ] [--content-types ] [--locales ] [-e ] [-c ] [-y] [--branch ]` @@ -1454,18 +1461,19 @@ USAGE [--only-assets] [--only-entries] FLAGS - -B, --branch= [default: main] Specify the branch to fetch the content from (default is main branch) - -a, --alias= Alias(name) for the management token - -c, --config= Path to the config file - -e, --environment= Source Environment - -l, --locale= Locale filter - -y, --yes Agree to process the command with the current configuration - --api-version= API Version to be used. Values [Default: 3, Nested Reference Publishing: 3.2]. - --bulk-unpublish= [default: true] This flag is set to true by default. It indicates that contentstack's - bulkpublish API will be used to unpublish the entries and assets - --content-type= Content type filter - --delivery-token= Delivery token for source environment - --retry-failed= Retry publishing failed entries from the logfile (optional, overrides all other flags) + -B, --branch= [default: main] Specify the branch to fetch the content from (default is main branch) + -a, --alias= Alias(name) for the management token + -c, --config= Path to the config file + -e, --environment= Source Environment + -k, --stack-api-key= Stack api key to be used + -l, --locale= Locale filter + -y, --yes Agree to process the command with the current configuration + --api-version= API Version to be used. Values [Default: 3, Nested Reference Publishing: 3.2]. + --bulk-unpublish= [default: true] This flag is set to true by default. It indicates that contentstack's + bulkpublish API will be used to unpublish the entries and assets + --content-type= Content type filter + --delivery-token= Delivery token for source environment + --retry-failed= Retry publishing failed entries from the logfile (optional, overrides all other flags) DESCRIPTION Unpublish entries or assets of given content types from the specified environment @@ -1531,6 +1539,12 @@ EXAMPLES Using --branch flag $ csdx cm:stacks:unpublish --bulk-unpublish --content-type [CONTENT TYPE] --environment [SOURCE ENV] --locale [LOCALE] --alias [MANAGEMENT TOKEN ALIAS] --delivery-token [DELIVERY TOKEN] --branch [BRANCH NAME] + + + + Using --stack-api-key flag + + $ csdx cm:stacks:unpublish --bulk-unpublish --content-type [CONTENT TYPE] --environment [SOURCE ENV] --locale [LOCALE] --stack-api-key [STACK API KEY] --delivery-token [DELIVERY TOKEN] ``` _See code: [src/commands/cm/stacks/unpublish.js](https://github.com/contentstack/cli/blob/main/packages/contentstack-bulk-publish/src/commands/cm/stacks/unpublish.js)_ diff --git a/packages/contentstack-bulk-publish/src/commands/cm/stacks/unpublish.js b/packages/contentstack-bulk-publish/src/commands/cm/stacks/unpublish.js index d01794885e..959b40755a 100644 --- a/packages/contentstack-bulk-publish/src/commands/cm/stacks/unpublish.js +++ b/packages/contentstack-bulk-publish/src/commands/cm/stacks/unpublish.js @@ -37,28 +37,31 @@ class UnpublishCommand extends Command { if (this.validate(updatedFlags)) { let stack; if (!updatedFlags.retryFailed) { - if (!updatedFlags.alias) { - updatedFlags.alias = await cliux.prompt('Please enter the management token alias to be used'); - } - if (!updatedFlags.deliveryToken) { - updatedFlags.deliveryToken = await cliux.prompt('Enter delivery token of your source environment'); - } - updatedFlags.bulkUnpublish = updatedFlags.bulkUnpublish === 'false' ? false : true; - // Validate management token alias. - try { - this.getToken(updatedFlags.alias); - } catch (error) { - this.error( - `The configured management token alias ${updatedFlags.alias} has not been added yet. Add it using 'csdx auth:tokens:add --alias ${updatedFlags.alias}'`, - { exit: 2 }, - ); - } config = { alias: updatedFlags.alias, host: this.cmaHost, cda: this.cdaHost, branch: unpublishFlags.branch, }; + if (updatedFlags.alias) { + try { + this.getToken(updatedFlags.alias); + config.alias = updatedFlags.alias; + } catch (error) { + this.error( + `The configured management token alias ${updatedFlags.alias} has not been added yet. Add it using 'csdx auth:tokens:add -a ${updatedFlags.alias}'`, + { exit: 2 }, + ); + } + } else if (updatedFlags['stack-api-key']) { + config.stackApiKey = updatedFlags['stack-api-key']; + } else { + this.error('Please use `--alias` or `--stack-api-key` to proceed.', { exit: 2 }); + } + if (!updatedFlags.deliveryToken) { + updatedFlags.deliveryToken = await cliux.prompt('Enter delivery token of your source environment'); + } + updatedFlags.bulkUnpublish = updatedFlags.bulkUnpublish === 'false' ? false : true; stack = await getStack(config); } if (!updatedFlags.deliveryToken && updatedFlags.deliveryToken.length === 0) { @@ -161,6 +164,10 @@ UnpublishCommand.flags = { char: 'a', description: 'Alias(name) for the management token', }), + 'stack-api-key': flags.string({ + char: 'k', + description: 'Stack api key to be used', + }), environment: flags.string({ char: 'e', description: 'Source Environment', @@ -277,6 +284,9 @@ UnpublishCommand.examples = [ '', 'Using --branch flag', 'csdx cm:stacks:unpublish --bulk-unpublish --content-type [CONTENT TYPE] --environment [SOURCE ENV] --locale [LOCALE] --alias [MANAGEMENT TOKEN ALIAS] --delivery-token [DELIVERY TOKEN] --branch [BRANCH NAME]', + '', + 'Using --stack-api-key flag', + 'csdx cm:stacks:unpublish --bulk-unpublish --content-type [CONTENT TYPE] --environment [SOURCE ENV] --locale [LOCALE] --stack-api-key [STACK API KEY] --delivery-token [DELIVERY TOKEN]', ]; UnpublishCommand.aliases = ['cm:bulk-publish:unpublish'];