Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CS-43668 - handled the case when invalid management token alias is passed #1267

Closed
wants to merge 11 commits into from
47 changes: 20 additions & 27 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/contentstack-audit/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ $ npm install -g @contentstack/cli-audit
$ csdx COMMAND
running command...
$ csdx (--version|-v)
@contentstack/cli-audit/1.3.4 darwin-arm64 node-v18.12.1
@contentstack/cli-audit/1.3.4 darwin-arm64 node-v20.8.0
$ csdx --help [COMMAND]
USAGE
$ csdx COMMAND
Expand Down
2 changes: 1 addition & 1 deletion packages/contentstack-branches/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ $ npm install -g @contentstack/cli-cm-branches
$ csdx COMMAND
running command...
$ csdx (--version)
@contentstack/cli-cm-branches/1.0.21 darwin-arm64 node-v20.8.0
@contentstack/cli-cm-branches/1.0.22 darwin-arm64 node-v20.8.0
$ csdx --help [COMMAND]
USAGE
$ csdx COMMAND
Expand Down
2 changes: 1 addition & 1 deletion packages/contentstack-bulk-publish/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ $ npm install -g @contentstack/cli-cm-bulk-publish
$ csdx COMMAND
running command...
$ csdx (--version)
@contentstack/cli-cm-bulk-publish/1.4.0 darwin-arm64 node-v20.10.0
@contentstack/cli-cm-bulk-publish/1.4.0 darwin-arm64 node-v20.8.0
$ csdx --help [COMMAND]
USAGE
$ csdx COMMAND
Expand Down
4 changes: 3 additions & 1 deletion packages/contentstack-clone/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ $ npm install -g @contentstack/cli-cm-clone
$ csdx COMMAND
running command...
$ csdx (--version)
@contentstack/cli-cm-clone/1.9.0 darwin-arm64 node-v20.8.0
@contentstack/cli-cm-clone/1.10.0 darwin-arm64 node-v20.8.0
$ csdx --help [COMMAND]
USAGE
$ csdx COMMAND
Expand Down Expand Up @@ -51,6 +51,7 @@ USAGE
[--destination-stack-api-key <value>] [--import-webhook-status disable|current]

FLAGS
-c, --config=<value> Path for the external configuration
-n, --stack-name=<value> Name for the new stack to store the cloned content.
-y, --yes [Optional] Override marketplace prompts
--destination-management-token-alias=<value> Source API key of the target stack token alias.
Expand Down Expand Up @@ -101,6 +102,7 @@ USAGE
[--destination-stack-api-key <value>] [--import-webhook-status disable|current]

FLAGS
-c, --config=<value> Path for the external configuration
-n, --stack-name=<value> Name for the new stack to store the cloned content.
-y, --yes [Optional] Override marketplace prompts
--destination-management-token-alias=<value> Source API key of the target stack token alias.
Expand Down
8 changes: 5 additions & 3 deletions packages/contentstack-clone/package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"name": "@contentstack/cli-cm-clone",
"description": "Contentstack stack clone plugin",
"version": "1.9.0",
"version": "1.10.0",
"author": "Contentstack",
"bugs": "https://github.com/rohitmishra209/cli-cm-clone/issues",
"dependencies": {
"@contentstack/cli-cm-export": "~1.10.4",
"@contentstack/cli-cm-import": "~1.13.2",
"@contentstack/cli-cm-import": "~1.13.3",
"@contentstack/cli-command": "~1.2.16",
"@contentstack/cli-utilities": "~1.5.11",
"@colors/colors": "^1.5.0",
Expand All @@ -18,7 +18,9 @@
"ora": "^5.1.0",
"prompt": "^1.3.0",
"rimraf": "^3.0.2",
"winston": "^3.7.2"
"winston": "^3.7.2",
"merge": "^2.1.1",
"lodash": "^4.17.20"
},
"devDependencies": {
"@oclif/test": "^1.2.7",
Expand Down
14 changes: 13 additions & 1 deletion packages/contentstack-clone/src/commands/cm/stacks/clone.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ const { configHandler, flags, isAuthenticated, managementSDKClient } = require('
const { CloneHandler } = require('../../../lib/util/clone-handler');
const path = require('path');
const rimraf = require('rimraf');
const merge = require("merge")
let pathdir = path.join(__dirname.split('src')[0], 'contents');
const { readdirSync } = require('fs');
const { readdirSync, readFileSync } = require('fs');
let config = {};

class StackCloneCommand extends Command {
Expand All @@ -23,11 +24,17 @@ class StackCloneCommand extends Command {
'source-management-token-alias': sourceManagementTokenAlias,
'destination-management-token-alias': destinationManagementTokenAlias,
'import-webhook-status': importWebhookStatus,
'config': externalConfigPath
} = cloneCommandFlags;

const handleClone = async () => {
const listOfTokens = configHandler.get('tokens');

if (externalConfigPath) {
let externalConfig = readFileSync(externalConfigPath, 'utf-8')
externalConfig = JSON.parse(externalConfig);
config = merge.recursive(config, externalConfig);
}
config.forceStopMarketplaceAppsPrompt = yes;
config.skipAudit = cloneCommandFlags['skip-audit'];

Expand Down Expand Up @@ -249,6 +256,11 @@ b) Structure with content (all modules including entries & assets)
'skip-audit': flags.boolean({
description: 'Skips the audit fix.',
}),
'config': flags.string({
char: 'c',
required: false,
description: 'Path for the external configuration',
}),
};

StackCloneCommand.usage =
Expand Down
57 changes: 35 additions & 22 deletions packages/contentstack-clone/src/lib/util/clone-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ let { default: importCmd } = require('@contentstack/cli-cm-import');
const { CustomAbortController } = require('./abort-controller');
const prompt = require('prompt');
const colors = require('@colors/colors/safe');
const cloneDeep = require("lodash/cloneDeep")

const {
HandleOrgCommand,
Expand Down Expand Up @@ -616,51 +617,63 @@ class CloneHandler {

async cmdExport() {
return new Promise((resolve, reject) => {
const cmd = ['-k', config.source_stack, '-d', __dirname.split('src')[0] + 'contents'];
if (config.cloneType === 'a') {
config.filteredModules = ['stack'].concat(structureList);
cmd.push('-c');
cmd.push(path.join(__dirname, 'dummyConfig.json'));
// Creating export specific config by merging external configurations
let exportConfig = Object.assign({}, cloneDeep(config), {...config?.export});
delete exportConfig.import;
delete exportConfig.export;

const cmd = ['-k', exportConfig.source_stack, '-d', __dirname.split('src')[0] + 'contents'];
if (exportConfig.cloneType === 'a') {
exportConfig.filteredModules = ['stack'].concat(structureList);
}

if (config.source_alias) {
cmd.push('-a', config.source_alias);
if (exportConfig.source_alias) {
cmd.push('-a', exportConfig.source_alias);
}
if (config.sourceStackBranch) {
cmd.push('--branch', config.sourceStackBranch);
if (exportConfig.sourceStackBranch) {
cmd.push('--branch', exportConfig.sourceStackBranch);
}

if (config.forceStopMarketplaceAppsPrompt) cmd.push('-y');
if (exportConfig.forceStopMarketplaceAppsPrompt) cmd.push('-y');

fs.writeFileSync(path.join(__dirname, 'dummyConfig.json'), JSON.stringify(config));
cmd.push('-c');
cmd.push(path.join(__dirname, 'dummyConfig.json'));

fs.writeFileSync(path.join(__dirname, 'dummyConfig.json'), JSON.stringify(exportConfig));
let exportData = exportCmd.run(cmd);
exportData.then(() => resolve(true)).catch(reject);
});
}

async cmdImport() {
return new Promise(async (resolve, _reject) => {
// Creating export specific config by merging external configurations
let importConfig = Object.assign({}, cloneDeep(config), {...config?.import});
delete importConfig.import;
delete importConfig.export;

const cmd = ['-c', path.join(__dirname, 'dummyConfig.json')];

if (config.destination_alias) {
cmd.push('-a', config.destination_alias);
if (importConfig.destination_alias) {
cmd.push('-a', importConfig.destination_alias);
}
if (!config.data && config.sourceStackBranch) {
cmd.push('-d', path.join(config.pathDir, config.sourceStackBranch));
if (!importConfig.data && importConfig.sourceStackBranch) {
cmd.push('-d', path.join(importConfig.pathDir, importConfig.sourceStackBranch));
}
if (config.targetStackBranch) {
cmd.push('--branch', config.targetStackBranch);
if (importConfig.targetStackBranch) {
cmd.push('--branch', importConfig.targetStackBranch);
}
if (config.importWebhookStatus) {
cmd.push('--import-webhook-status', config.importWebhookStatus);
if (importConfig.importWebhookStatus) {
cmd.push('--import-webhook-status', importConfig.importWebhookStatus);
}

if (config.skipAudit) cmd.push('--skip-audit');
if (importConfig.skipAudit) cmd.push('--skip-audit');

if (config.forceStopMarketplaceAppsPrompt) cmd.push('-y');
if (importConfig.forceStopMarketplaceAppsPrompt) cmd.push('-y');

fs.writeFileSync(path.join(__dirname, 'dummyConfig.json'), JSON.stringify(config));
fs.writeFileSync(path.join(__dirname, 'dummyConfig.json'), JSON.stringify(importConfig));
await importCmd.run(cmd);
fs.writeFileSync(path.join(__dirname, 'dummyConfig.json'), JSON.stringify({}))
return resolve();
});
}
Expand Down
2 changes: 1 addition & 1 deletion packages/contentstack-config/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ $ npm install -g @contentstack/cli-config
$ csdx COMMAND
running command...
$ csdx (--version)
@contentstack/cli-config/1.5.1 darwin-arm64 node-v20.8.0
@contentstack/cli-config/1.6.0 darwin-arm64 node-v20.8.0
$ csdx --help [COMMAND]
USAGE
$ csdx COMMAND
Expand Down
2 changes: 1 addition & 1 deletion packages/contentstack-export/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ $ npm install -g @contentstack/cli-cm-export
$ csdx COMMAND
running command...
$ csdx (--version)
@contentstack/cli-cm-export/1.10.3 darwin-arm64 node-v20.8.0
@contentstack/cli-cm-export/1.10.4 darwin-arm64 node-v20.8.0
$ csdx --help [COMMAND]
USAGE
$ csdx COMMAND
Expand Down
2 changes: 1 addition & 1 deletion packages/contentstack-import/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ $ npm install -g @contentstack/cli-cm-import
$ csdx COMMAND
running command...
$ csdx (--version)
@contentstack/cli-cm-import/1.13.0 darwin-arm64 node-v20.8.0
@contentstack/cli-cm-import/1.13.2 darwin-arm64 node-v20.8.0
$ csdx --help [COMMAND]
USAGE
$ csdx COMMAND
Expand Down
2 changes: 1 addition & 1 deletion packages/contentstack-import/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@contentstack/cli-cm-import",
"description": "Contentstack CLI plugin to import content into stack",
"version": "1.13.2",
"version": "1.13.3",
"author": "Contentstack",
"bugs": "https://github.com/contentstack/cli/issues",
"dependencies": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ export default class ImportCommand extends Command {
'success',
);
} catch (error) {
log({ data: backupDir } as ImportConfig, `Failed to import stack content - ${formatError(error)}`, 'error');
log({ data: backupDir ?? path.join(backupDir || __dirname, 'logs', 'import') } as ImportConfig, `Failed to import stack content - ${formatError(error)}`, 'error');
log(
{ data: backupDir } as ImportConfig,
`The log has been stored at ${
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const setupConfig = async (importCmdFlags: any): Promise<ImportConfig> => {
const managementTokenAlias = importCmdFlags['management-token-alias'] || importCmdFlags['alias'];

if (managementTokenAlias) {
const { token, apiKey } = configHandler.get(`tokens.${managementTokenAlias}`);
const { token, apiKey } = configHandler.get(`tokens.${managementTokenAlias}`) ?? {};
config.management_token = token;
config.apiKey = apiKey;
if (!config.management_token) {
Expand Down
2 changes: 1 addition & 1 deletion packages/contentstack-seed/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"author": "Contentstack",
"bugs": "https://github.com/contentstack/cli/issues",
"dependencies": {
"@contentstack/cli-cm-import": "~1.13.2",
"@contentstack/cli-cm-import": "~1.13.3",
"@contentstack/cli-command": "~1.2.16",
"@contentstack/cli-utilities": "~1.5.11",
"inquirer": "8.2.4",
Expand Down
2 changes: 2 additions & 0 deletions packages/contentstack/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2332,6 +2332,7 @@ USAGE
[--destination-stack-api-key <value>] [--import-webhook-status disable|current]

FLAGS
-c, --config=<value> Path for the external configuration
-n, --stack-name=<value> Name for the new stack to store the cloned content.
-y, --yes [Optional] Override marketplace prompts
--destination-management-token-alias=<value> Source API key of the target stack token alias.
Expand Down Expand Up @@ -2483,6 +2484,7 @@ USAGE
[--destination-stack-api-key <value>] [--import-webhook-status disable|current]

FLAGS
-c, --config=<value> Path for the external configuration
-n, --stack-name=<value> Name for the new stack to store the cloned content.
-y, --yes [Optional] Override marketplace prompts
--destination-management-token-alias=<value> Source API key of the target stack token alias.
Expand Down
Loading
Loading