From accb05c9aa63587f627feac8592696ef0ac5a713 Mon Sep 17 00:00:00 2001 From: rschneider-chwy Date: Thu, 30 May 2024 17:09:14 -0400 Subject: [PATCH 1/9] Adds network option for update-local --- src/pm/devops_property_manager.js | 7 +++++++ src/pm/property_manager_cli.js | 18 ++++++++++++++++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/pm/devops_property_manager.js b/src/pm/devops_property_manager.js index dd5f85f..dcb1c57 100644 --- a/src/pm/devops_property_manager.js +++ b/src/pm/devops_property_manager.js @@ -173,6 +173,13 @@ class DevopsPropertyManager extends Devops { } let propertyInfo = await project.getPropertyInfo(envInfo.propertyId); + if (createPropertyInfo.network === 'STAGING') { + propertyInfo.propertyVersion = envInfo.activeIn_STAGING_Info.propertyVersion + } + + if (createPropertyInfo.network === 'PRODUCTION') { + propertyInfo.propertyVersion = envInfo.activeIn_PRODUCTION_Info.propertyVersion + } ruleTree = await project.getPropertyRuleTree(envInfo.propertyId, propertyInfo.propertyVersion); let projectInfo = project.getProjectInfo(); diff --git a/src/pm/property_manager_cli.js b/src/pm/property_manager_cli.js index 36fdbd1..f78fe30 100644 --- a/src/pm/property_manager_cli.js +++ b/src/pm/property_manager_cli.js @@ -664,6 +664,7 @@ Are you sure you want to DELETE the property '${options.property}'?`, const update = async function(devops, options) { let runPull = options.forceUpdate; let projectName = devops.extractProjectName(options); + let network = commonCli.checkNetworkName(options); if (!runPull) { var questions = [{ @@ -683,9 +684,11 @@ Are you sure you want to DELETE the property '${options.property}'?`, throw new errors.ArgumentError(`Invalid variable mode option selected. Valid modes are ${printAllowedModesUpdateOrImport()}`, "invalid_variable_mode"); } + let createPropertyInfo = { projectName, - variableMode + variableMode, + network }; let dryRun = options.dryRun || false; @@ -696,7 +699,17 @@ Are you sure you want to DELETE the property '${options.property}'?`, } else { consoleLogger.info(`Updating and overwriting local files for ${projectName} from PAPI...`); let project = await devops.updateProperty(createPropertyInfo); - consoleLogger.info(`Updated ${project.getName()} to the latest: v${project.loadEnvironmentInfo().latestVersionInfo.propertyVersion}`); + let envInfo = project.loadEnvironmentInfo() + + if (createPropertyInfo.network === 'STAGING') { + createPropertyInfo.propertyVersion = envInfo.activeIn_STAGING_Info.propertyVersion + } + + if (createPropertyInfo.network === 'PRODUCTION') { + createPropertyInfo.propertyVersion = envInfo.activeIn_PRODUCTION_Info.propertyVersion + } + + consoleLogger.info(`Updated ${project.getName()} to the latest: v${createPropertyInfo.propertyVersion}`); } } @@ -1075,6 +1088,7 @@ Are you sure you want to DELETE the property '${options.property}'?`, .option('-p, --property ', 'Property name. Optional if default property was set using the set-default command.') .option('--dry-run', 'Verify the result of your command syntax before running it. Displays the JSON generated by the command as currently written.') .option('--force-update', 'WARNING: This option bypasses the confirmation prompt and automatically overwrites your local files.') + .option('-n, --network ', "Network, either 'production' or 'staging'. You can shorten 'production' to " + "'prod' or 'p' and 'staging' to 'stage' or 's'.") .option('--variable-mode ', `Choose how this command pulls in variables. Allowed values are ${printAllowedModesUpdateOrImport()}. Default functionality is no-var.`) .alias("ul") .on('--help', () => { From 5774bd74ed915d2c3016286a61c65b9c908a317b Mon Sep 17 00:00:00 2001 From: rschneider-chwy Date: Thu, 30 May 2024 17:09:23 -0400 Subject: [PATCH 2/9] Updates with new command params --- README.md | 2 +- docs/cli_pm_commands_help.md | 3 +++ tests/snippets/snippets_cli_test.js | 32 +++++++++++++++++++++++++++++ 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 8af627e..cc7c3f7 100644 --- a/README.md +++ b/README.md @@ -480,7 +480,7 @@ Here are some ways you can use the Property Manager CLI to meet your business ne If you also use the Property Manager UI, make sure your client side files are in sync with the latest property version on the network. -To retrieve all updates from the latest property version, run this command: `akamai property-manager update-local -p `.
The `update-local` command overrides any locally-saved configuration version with the latest active property version. +To retrieve all updates from the latest, staging or production property version, run this command: `akamai property-manager update-local -p -n `.
The `update-local` command overrides any locally-saved configuration version with the latest or network active property version. ## Retrieve a specific rule from Property Manager diff --git a/docs/cli_pm_commands_help.md b/docs/cli_pm_commands_help.md index 6cb5684..dd9456a 100644 --- a/docs/cli_pm_commands_help.md +++ b/docs/cli_pm_commands_help.md @@ -155,6 +155,9 @@ Update local property with the latest from the Property Manager API (PAPI). Options: -p, --property Property name. Optional if default property was set using the set-default command. + -n, --network Network, either 'production' or 'staging'. You + can shorten 'production' to 'prod' or 'p' and + 'staging' to 'stage' or 's'. --dry-run Verify the result of your command syntax before running it. Displays the JSON generated by the command as currently diff --git a/tests/snippets/snippets_cli_test.js b/tests/snippets/snippets_cli_test.js index b26fce5..b6aeb47 100644 --- a/tests/snippets/snippets_cli_test.js +++ b/tests/snippets/snippets_cli_test.js @@ -645,6 +645,12 @@ describe('Snippets CLI PULL command', function () { td.when(project.loadEnvironmentInfo()).thenReturn({ latestVersionInfo : { propertyVersion : 9 + }, + activeIn_STAGING_Info : { + propertyVersion : 8 + }, + activeIn_PRODUCTION_Info : { + propertyVersion : 5 } }); @@ -701,6 +707,32 @@ describe('Snippets CLI PULL command', function () { assert.equal(errorCatcher.error, 'Error: Can\'t read default property name from snippetsSettings.json and no property name provided per -p option'); }); }); + + it('update local output -with network', function () { + let createDevOpsFun = function (deps) { + let newDeps = { + devopsHome + }; + Object.assign(deps, newDeps); + + let devOps = createDevOps(deps); + devOps.updateProperty = function(){ + return project; + }; + return devOps; + }; + + let cliArgs = createCommand("update-local", "-p", "testproject.com", "--force-update", "-n", "stg"); + let testConsole = new TestConsole(); + return mainTester(errorReporter => { + main(cliArgs, {}, createDevOpsFun, errorReporter, testConsole); + }, errorCatcher => { + assert.equal(errorCatcher, null); + assert.equal(testConsole.logs.length, 2); + let output = testConsole.logs.join("\n"); + assert.equal(output, 'Updating and overwriting local files for testproject.com from PAPI...\nUpdated testproject.com to the latest: v9'); + }); + }); }); describe('Snippets CLI search tests', function () { From b92fbff014f270160b5e0e1794b613126ae6e886 Mon Sep 17 00:00:00 2001 From: rschneider-chwy Date: Thu, 30 May 2024 17:36:33 -0400 Subject: [PATCH 3/9] Adds network option check --- src/pm/property_manager_cli.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/pm/property_manager_cli.js b/src/pm/property_manager_cli.js index f78fe30..949cd33 100644 --- a/src/pm/property_manager_cli.js +++ b/src/pm/property_manager_cli.js @@ -664,7 +664,13 @@ Are you sure you want to DELETE the property '${options.property}'?`, const update = async function(devops, options) { let runPull = options.forceUpdate; let projectName = devops.extractProjectName(options); - let network = commonCli.checkNetworkName(options); + let network; + + if (options.network) { + network = commonCli.checkNetworkName(options); + } else { + network = null + } if (!runPull) { var questions = [{ @@ -701,14 +707,19 @@ Are you sure you want to DELETE the property '${options.property}'?`, let project = await devops.updateProperty(createPropertyInfo); let envInfo = project.loadEnvironmentInfo() + // check and grab the appropriate version if (createPropertyInfo.network === 'STAGING') { createPropertyInfo.propertyVersion = envInfo.activeIn_STAGING_Info.propertyVersion } - + if (createPropertyInfo.network === 'PRODUCTION') { createPropertyInfo.propertyVersion = envInfo.activeIn_PRODUCTION_Info.propertyVersion } + if (!createPropertyInfo.network) { + createPropertyInfo.propertyVersion = envInfo.latestVersionInfo.propertyVersion + } + consoleLogger.info(`Updated ${project.getName()} to the latest: v${createPropertyInfo.propertyVersion}`); } } From f533e9424418b4b4b4a01c6401230004e1ac25ef Mon Sep 17 00:00:00 2001 From: rschneider-chwy Date: Thu, 30 May 2024 18:52:55 -0400 Subject: [PATCH 4/9] Adding option to import --- src/pm/devops_property_manager.js | 16 +++++++++++++--- src/pm/property_manager_cli.js | 28 +++++++++++++++++++--------- src/project.js | 4 +++- 3 files changed, 35 insertions(+), 13 deletions(-) diff --git a/src/pm/devops_property_manager.js b/src/pm/devops_property_manager.js index dcb1c57..6add723 100644 --- a/src/pm/devops_property_manager.js +++ b/src/pm/devops_property_manager.js @@ -129,6 +129,14 @@ class DevopsPropertyManager extends Devops { createPropertyInfo.propertyId = helpers.parsePropertyId(results.versions.items[0].propertyId); let propertyInfo = await project.getPropertyInfo(createPropertyInfo.propertyId); + if (createPropertyInfo.network === 'STAGING') { + propertyInfo.propertyVersion = propertyInfo.productionVersion + } + + if (createPropertyInfo.network === 'PRODUCTION') { + propertyInfo.propertyVersion = propertyInfo.stagingVersion + } + createPropertyInfo.propertyVersion = propertyInfo.propertyVersion; logger.info(`Attempting to load rule tree for property id: ${createPropertyInfo.propertyId} and version: ${createPropertyInfo.propertyVersion}`); let ruleTree = await project.getPropertyRuleTree(createPropertyInfo.propertyId, createPropertyInfo.propertyVersion); @@ -162,7 +170,8 @@ class DevopsPropertyManager extends Devops { throw new errors.ArgumentError(`Property folder '${createPropertyInfo.projectName}' does not exist`, "property_folder_does_not_exist", createPropertyInfo.projectName); } - let envInfo = project.loadEnvironmentInfo(); + + let envInfo = project.loadEnvironmentInfo(); if (_.isString(envInfo.propertyName) && !_.isNumber(envInfo.propertyId)) { let results = await this.getPAPI().findProperty(envInfo.propertyName); @@ -171,14 +180,15 @@ class DevopsPropertyManager extends Devops { } envInfo.propertyId = helpers.parsePropertyId(results.versions.items[0].propertyId); } + let propertyInfo = await project.getPropertyInfo(envInfo.propertyId); if (createPropertyInfo.network === 'STAGING') { - propertyInfo.propertyVersion = envInfo.activeIn_STAGING_Info.propertyVersion + propertyInfo.propertyVersion = propertyInfo.productionVersion } if (createPropertyInfo.network === 'PRODUCTION') { - propertyInfo.propertyVersion = envInfo.activeIn_PRODUCTION_Info.propertyVersion + propertyInfo.propertyVersion = propertyInfo.stagingVersion } ruleTree = await project.getPropertyRuleTree(envInfo.propertyId, propertyInfo.propertyVersion); diff --git a/src/pm/property_manager_cli.js b/src/pm/property_manager_cli.js index 949cd33..cab5f5d 100644 --- a/src/pm/property_manager_cli.js +++ b/src/pm/property_manager_cli.js @@ -613,13 +613,22 @@ Are you sure you want to deactivate the property '${propertyName}' on network '$ const importProperty = async function(devops, options) { let propertyName = options.property; + let network; if (!propertyName || _.isBoolean(propertyName)) { throw new errors.DependencyError("Missing property option! Use akamai property-manager import -p ...", "missing_property_name"); } + + if (options.network) { + network = commonCli.checkNetworkName(options); + } else { + network = null + } + consoleLogger.info(`Importing and creating local files for ${propertyName} from Property Manager...`); let createPropertyInfo = { - propertyName + propertyName, + network }; let variableMode = helpers.allowedModes[1]; @@ -705,22 +714,22 @@ Are you sure you want to DELETE the property '${options.property}'?`, } else { consoleLogger.info(`Updating and overwriting local files for ${projectName} from PAPI...`); let project = await devops.updateProperty(createPropertyInfo); + // work on streamlining to load let envInfo = project.loadEnvironmentInfo() + let propertyInfo = await project.getPropertyInfo(envInfo.propertyId); + let environment = 'latest' - // check and grab the appropriate version if (createPropertyInfo.network === 'STAGING') { - createPropertyInfo.propertyVersion = envInfo.activeIn_STAGING_Info.propertyVersion + propertyInfo.propertyVersion = propertyInfo.productionVersion + environment = 'staging' } if (createPropertyInfo.network === 'PRODUCTION') { - createPropertyInfo.propertyVersion = envInfo.activeIn_PRODUCTION_Info.propertyVersion + propertyInfo.propertyVersion = propertyInfo.stagingVersion + environment = 'production' } - if (!createPropertyInfo.network) { - createPropertyInfo.propertyVersion = envInfo.latestVersionInfo.propertyVersion - } - - consoleLogger.info(`Updated ${project.getName()} to the latest: v${createPropertyInfo.propertyVersion}`); + consoleLogger.info(`Updated ${project.getName()} to ${environment}: v${propertyInfo.propertyVersion}`); } } @@ -1113,6 +1122,7 @@ Are you sure you want to DELETE the property '${options.property}'?`, commander .command("import", "Import an existing property from Property Manager.") .option('-p, --property ', 'Property name. Optional if default property was set using the set-default command.') + .option('-n, --network ', "Network, either 'production' or 'staging'. You can shorten 'production' to " + "'prod' or 'p' and 'staging' to 'stage' or 's'.") .option('--dry-run', 'Verify the result of your command syntax before running it. Displays the JSON generated by the command as currently written.') .option('--variable-mode ', `Choose how to pull in variables. Allowed values are ${printAllowedModesUpdateOrImport()}. By default, variables aren't imported (no-var).`) .alias("i") diff --git a/src/project.js b/src/project.js index e21b21a..0c6c703 100644 --- a/src/project.js +++ b/src/project.js @@ -365,7 +365,9 @@ class Project { contractId: versionInfo.contractId, groupId: versionInfo.groupId, productId: versionInfo.versions.items[0].productId, - propertyVersion: versionInfo.versions.items[0].propertyVersion + propertyVersion: versionInfo.versions.items[0].propertyVersion, + stagingVersion: versionInfo.versions.items[0].stagingVersion, + productionVersion: versionInfo.versions.items[0].productionVersion, } } From 8684bbe0f75f1cbc4f7c56b742f0e99e4063f3a3 Mon Sep 17 00:00:00 2001 From: rschneider-chwy Date: Fri, 31 May 2024 09:44:46 -0400 Subject: [PATCH 5/9] Updates getLatest with network --- src/papi.js | 9 +++++++-- src/pm/devops_property_manager.js | 25 +++++-------------------- src/pm/property_manager_cli.js | 24 ++++++++---------------- src/project.js | 9 ++++----- 4 files changed, 24 insertions(+), 43 deletions(-) diff --git a/src/papi.js b/src/papi.js index 82d6620..114213a 100644 --- a/src/papi.js +++ b/src/papi.js @@ -70,8 +70,13 @@ class PAPI { return this.openClient.post(url, postBody); } - latestPropertyVersion(propertyId) { - let url = `/papi/v1/properties/${propertyId}/versions/latest`; + latestPropertyVersion(propertyId, network) { + let url; + if (network) { + url = `/papi/v1/properties/${propertyId}/versions/latest?activatedOn=${network}`; + } else { + url = `/papi/v1/properties/${propertyId}/versions/latest`; + } return this.openClient.get(url); } diff --git a/src/pm/devops_property_manager.js b/src/pm/devops_property_manager.js index 6add723..3c82932 100644 --- a/src/pm/devops_property_manager.js +++ b/src/pm/devops_property_manager.js @@ -127,16 +127,9 @@ class DevopsPropertyManager extends Devops { "property_does_not_exist_on_server", createPropertyInfo.propertyName); } createPropertyInfo.propertyId = helpers.parsePropertyId(results.versions.items[0].propertyId); - let propertyInfo = await project.getPropertyInfo(createPropertyInfo.propertyId); - - if (createPropertyInfo.network === 'STAGING') { - propertyInfo.propertyVersion = propertyInfo.productionVersion - } - - if (createPropertyInfo.network === 'PRODUCTION') { - propertyInfo.propertyVersion = propertyInfo.stagingVersion - } + let propertyInfo = await project.getPropertyInfo(createPropertyInfo.propertyId, null, createPropertyInfo.network); + project.propertyVersion = propertyInfo.propertyVersion; createPropertyInfo.propertyVersion = propertyInfo.propertyVersion; logger.info(`Attempting to load rule tree for property id: ${createPropertyInfo.propertyId} and version: ${createPropertyInfo.propertyVersion}`); let ruleTree = await project.getPropertyRuleTree(createPropertyInfo.propertyId, createPropertyInfo.propertyVersion); @@ -180,18 +173,10 @@ class DevopsPropertyManager extends Devops { } envInfo.propertyId = helpers.parsePropertyId(results.versions.items[0].propertyId); } + let propertyInfo = await project.getPropertyInfo(envInfo.propertyId, null, createPropertyInfo.network); - let propertyInfo = await project.getPropertyInfo(envInfo.propertyId); - - if (createPropertyInfo.network === 'STAGING') { - propertyInfo.propertyVersion = propertyInfo.productionVersion - } - - if (createPropertyInfo.network === 'PRODUCTION') { - propertyInfo.propertyVersion = propertyInfo.stagingVersion - } - - ruleTree = await project.getPropertyRuleTree(envInfo.propertyId, propertyInfo.propertyVersion); + project.propertyVersion = propertyInfo.propertyVersion + ruleTree = await project.getPropertyRuleTree(envInfo.propertyId, project.propertyVersion); let projectInfo = project.getProjectInfo(); let isSecure = ruleTree.rules.options.is_secure; projectInfo.secureOption = isSecure; diff --git a/src/pm/property_manager_cli.js b/src/pm/property_manager_cli.js index cab5f5d..cc02f28 100644 --- a/src/pm/property_manager_cli.js +++ b/src/pm/property_manager_cli.js @@ -614,6 +614,7 @@ Are you sure you want to deactivate the property '${propertyName}' on network '$ const importProperty = async function(devops, options) { let propertyName = options.property; let network; + let environment; if (!propertyName || _.isBoolean(propertyName)) { throw new errors.DependencyError("Missing property option! Use akamai property-manager import -p ...", "missing_property_name"); @@ -621,8 +622,10 @@ Are you sure you want to deactivate the property '${propertyName}' on network '$ if (options.network) { network = commonCli.checkNetworkName(options); + environment = network } else { network = null + environment = 'LATEST' } consoleLogger.info(`Importing and creating local files for ${propertyName} from Property Manager...`); @@ -644,7 +647,8 @@ Are you sure you want to deactivate the property '${propertyName}' on network '$ consoleLogger.info("update property info: ", helpers.jsonStringify(createPropertyInfo)); } else { let project = await devops.importProperty(createPropertyInfo); - consoleLogger.info(`Imported ${project.getName()}. The latest version is: v${project.loadEnvironmentInfo().latestVersionInfo.propertyVersion}`); + + consoleLogger.info(`Imported ${project.getName()}. The ${environment} version is: v${project.propertyVersion}`); } }; @@ -677,8 +681,10 @@ Are you sure you want to DELETE the property '${options.property}'?`, if (options.network) { network = commonCli.checkNetworkName(options); + environment = network } else { network = null + environment = 'LATEST' } if (!runPull) { @@ -714,22 +720,8 @@ Are you sure you want to DELETE the property '${options.property}'?`, } else { consoleLogger.info(`Updating and overwriting local files for ${projectName} from PAPI...`); let project = await devops.updateProperty(createPropertyInfo); - // work on streamlining to load - let envInfo = project.loadEnvironmentInfo() - let propertyInfo = await project.getPropertyInfo(envInfo.propertyId); - let environment = 'latest' - - if (createPropertyInfo.network === 'STAGING') { - propertyInfo.propertyVersion = propertyInfo.productionVersion - environment = 'staging' - } - - if (createPropertyInfo.network === 'PRODUCTION') { - propertyInfo.propertyVersion = propertyInfo.stagingVersion - environment = 'production' - } - consoleLogger.info(`Updated ${project.getName()} to ${environment}: v${propertyInfo.propertyVersion}`); + consoleLogger.info(`Updated ${project.getName()} to ${environment}: v${project.propertyVersion}`); } } diff --git a/src/project.js b/src/project.js index 0c6c703..2147ab7 100644 --- a/src/project.js +++ b/src/project.js @@ -348,14 +348,15 @@ class Project { /** * @param propertyId * @param version + * @param network * @return {Promise.<*>} */ - async getPropertyInfo(propertyId, version) { + async getPropertyInfo(propertyId, version, network) { let papi = this.dependencies.getPAPI(); let versionInfo; if (!_.isNumber(version)) { - versionInfo = await papi.latestPropertyVersion(propertyId); + versionInfo = await papi.latestPropertyVersion(propertyId, network); } else { versionInfo = await papi.getPropertyVersion(propertyId, version); } @@ -365,9 +366,7 @@ class Project { contractId: versionInfo.contractId, groupId: versionInfo.groupId, productId: versionInfo.versions.items[0].productId, - propertyVersion: versionInfo.versions.items[0].propertyVersion, - stagingVersion: versionInfo.versions.items[0].stagingVersion, - productionVersion: versionInfo.versions.items[0].productionVersion, + propertyVersion: versionInfo.versions.items[0].propertyVersion } } From b97fac0e13f8c9ad5a0516149bfccfaa65b3e583 Mon Sep 17 00:00:00 2001 From: rschneider-chwy Date: Fri, 31 May 2024 09:50:09 -0400 Subject: [PATCH 6/9] Updating docs --- README.md | 4 ++-- docs/cli_pm_commands_help.md | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index cc7c3f7..4d95b5e 100644 --- a/README.md +++ b/README.md @@ -129,7 +129,7 @@ Here’s a typical workflow when you want to break your Property Manager configu * Do you need any new supporting processes? For example, if different teams are involved, how will you manage ownership of the different templates? -1. Import an existing property by running the `akamai property-manager import` command. This creates a local instance of your configuration. You can also create a new property if needed. +1. Import an existing property by running the `akamai property-manager import --network ` command. This creates a local instance of your configuration. You can also create a new property if needed. 1. Verify that the `/config-snippets` folder contains a separate JSON-based configuration snippet for each rule in your property configuration.
In this folder, the `main.json` file ties all the snippets together. It lists the available snippets and contains the local permissions for each snippet. @@ -215,7 +215,7 @@ Create your local client side snippets to let different teams own different part 1. Determine how to handle any [custom user variables](#using-property-manager-user-variables). -1. Run the `akamai property-manager import` command to create a local instance of your Property Manager configuration. +1. Run the `akamai property-manager import --network ` command to create a local instance of your Property Manager configuration. 1. In your project directory structure, navigate to the new `config-snippets` folder.
This folder contains a separate JSON-based configuration snippet for each rule in your property configuration. diff --git a/docs/cli_pm_commands_help.md b/docs/cli_pm_commands_help.md index dd9456a..b67571e 100644 --- a/docs/cli_pm_commands_help.md +++ b/docs/cli_pm_commands_help.md @@ -131,6 +131,9 @@ Creates a local version of an existing property. Options: -p, --property Property name. Optional if default property was set using the set-default command. + -n, --network Network, either 'production' or 'staging'. You + can shorten 'production' to 'prod' or 'p' and + 'staging' to 'stage' or 's'. --dry-run Verify the result of your command syntax before running it. Displays the JSON generated by the command as currently From 8faa373ee6504a4d08a375f3d3277f879323427a Mon Sep 17 00:00:00 2001 From: rschneider-chwy Date: Fri, 31 May 2024 09:52:46 -0400 Subject: [PATCH 7/9] Updates spacing --- src/pm/devops_property_manager.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/pm/devops_property_manager.js b/src/pm/devops_property_manager.js index 3c82932..c274880 100644 --- a/src/pm/devops_property_manager.js +++ b/src/pm/devops_property_manager.js @@ -163,8 +163,7 @@ class DevopsPropertyManager extends Devops { throw new errors.ArgumentError(`Property folder '${createPropertyInfo.projectName}' does not exist`, "property_folder_does_not_exist", createPropertyInfo.projectName); } - - let envInfo = project.loadEnvironmentInfo(); + let envInfo = project.loadEnvironmentInfo(); if (_.isString(envInfo.propertyName) && !_.isNumber(envInfo.propertyId)) { let results = await this.getPAPI().findProperty(envInfo.propertyName); @@ -175,8 +174,8 @@ class DevopsPropertyManager extends Devops { } let propertyInfo = await project.getPropertyInfo(envInfo.propertyId, null, createPropertyInfo.network); - project.propertyVersion = propertyInfo.propertyVersion - ruleTree = await project.getPropertyRuleTree(envInfo.propertyId, project.propertyVersion); + + ruleTree = await project.getPropertyRuleTree(envInfo.propertyId, propertyInfo.propertyVersion); let projectInfo = project.getProjectInfo(); let isSecure = ruleTree.rules.options.is_secure; projectInfo.secureOption = isSecure; From e56396d1d8e60512836a7be9b943a6676cb119a9 Mon Sep 17 00:00:00 2001 From: rschneider-chwy Date: Fri, 31 May 2024 09:54:20 -0400 Subject: [PATCH 8/9] Updates spacing --- src/pm/property_manager_cli.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/pm/property_manager_cli.js b/src/pm/property_manager_cli.js index cc02f28..c333734 100644 --- a/src/pm/property_manager_cli.js +++ b/src/pm/property_manager_cli.js @@ -647,7 +647,6 @@ Are you sure you want to deactivate the property '${propertyName}' on network '$ consoleLogger.info("update property info: ", helpers.jsonStringify(createPropertyInfo)); } else { let project = await devops.importProperty(createPropertyInfo); - consoleLogger.info(`Imported ${project.getName()}. The ${environment} version is: v${project.propertyVersion}`); } @@ -720,7 +719,6 @@ Are you sure you want to DELETE the property '${options.property}'?`, } else { consoleLogger.info(`Updating and overwriting local files for ${projectName} from PAPI...`); let project = await devops.updateProperty(createPropertyInfo); - consoleLogger.info(`Updated ${project.getName()} to ${environment}: v${project.propertyVersion}`); } } From 5d6b8c8d22c5428ddeae7558d1f7d3804ca06ea2 Mon Sep 17 00:00:00 2001 From: rschneider-chwy Date: Fri, 31 May 2024 13:46:17 -0400 Subject: [PATCH 9/9] Adds propver --- README.md | 6 +++--- src/pm/devops_property_manager.js | 6 +++--- src/pm/property_manager_cli.js | 25 +++++++++++-------------- 3 files changed, 17 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 4d95b5e..882b9cc 100644 --- a/README.md +++ b/README.md @@ -129,7 +129,7 @@ Here’s a typical workflow when you want to break your Property Manager configu * Do you need any new supporting processes? For example, if different teams are involved, how will you manage ownership of the different templates? -1. Import an existing property by running the `akamai property-manager import --network ` command. This creates a local instance of your configuration. You can also create a new property if needed. +1. Import an existing property by running the `akamai property-manager import --network --propver ` command. This creates a local instance of your configuration. You can also create a new property if needed. 1. Verify that the `/config-snippets` folder contains a separate JSON-based configuration snippet for each rule in your property configuration.
In this folder, the `main.json` file ties all the snippets together. It lists the available snippets and contains the local permissions for each snippet. @@ -215,7 +215,7 @@ Create your local client side snippets to let different teams own different part 1. Determine how to handle any [custom user variables](#using-property-manager-user-variables). -1. Run the `akamai property-manager import --network ` command to create a local instance of your Property Manager configuration. +1. Run the `akamai property-manager import --network --propver ` command to create a local instance of your Property Manager configuration. 1. In your project directory structure, navigate to the new `config-snippets` folder.
This folder contains a separate JSON-based configuration snippet for each rule in your property configuration. @@ -480,7 +480,7 @@ Here are some ways you can use the Property Manager CLI to meet your business ne If you also use the Property Manager UI, make sure your client side files are in sync with the latest property version on the network. -To retrieve all updates from the latest, staging or production property version, run this command: `akamai property-manager update-local -p -n `.
The `update-local` command overrides any locally-saved configuration version with the latest or network active property version. +To retrieve all updates from the latest or specific property version, run this command: `akamai property-manager update-local -p --network --propver `.
The `update-local` command overrides any locally-saved configuration version with the latest or specified property version. ## Retrieve a specific rule from Property Manager diff --git a/src/pm/devops_property_manager.js b/src/pm/devops_property_manager.js index c274880..ff7514d 100644 --- a/src/pm/devops_property_manager.js +++ b/src/pm/devops_property_manager.js @@ -127,7 +127,7 @@ class DevopsPropertyManager extends Devops { "property_does_not_exist_on_server", createPropertyInfo.propertyName); } createPropertyInfo.propertyId = helpers.parsePropertyId(results.versions.items[0].propertyId); - let propertyInfo = await project.getPropertyInfo(createPropertyInfo.propertyId, null, createPropertyInfo.network); + let propertyInfo = await project.getPropertyInfo(createPropertyInfo.propertyId, createPropertyInfo.propertyVersion, createPropertyInfo.network); project.propertyVersion = propertyInfo.propertyVersion; createPropertyInfo.propertyVersion = propertyInfo.propertyVersion; @@ -172,9 +172,9 @@ class DevopsPropertyManager extends Devops { } envInfo.propertyId = helpers.parsePropertyId(results.versions.items[0].propertyId); } - let propertyInfo = await project.getPropertyInfo(envInfo.propertyId, null, createPropertyInfo.network); - + let propertyInfo = await project.getPropertyInfo(envInfo.propertyId, createPropertyInfo.propertyVersion, createPropertyInfo.network); + project.propertyVersion = propertyInfo.propertyVersion ruleTree = await project.getPropertyRuleTree(envInfo.propertyId, propertyInfo.propertyVersion); let projectInfo = project.getProjectInfo(); let isSecure = ruleTree.rules.options.is_secure; diff --git a/src/pm/property_manager_cli.js b/src/pm/property_manager_cli.js index c333734..0e27720 100644 --- a/src/pm/property_manager_cli.js +++ b/src/pm/property_manager_cli.js @@ -613,8 +613,8 @@ Are you sure you want to deactivate the property '${propertyName}' on network '$ const importProperty = async function(devops, options) { let propertyName = options.property; + let propertyVersion = parseInt(options.propver, 10); let network; - let environment; if (!propertyName || _.isBoolean(propertyName)) { throw new errors.DependencyError("Missing property option! Use akamai property-manager import -p ...", "missing_property_name"); @@ -622,15 +622,12 @@ Are you sure you want to deactivate the property '${propertyName}' on network '$ if (options.network) { network = commonCli.checkNetworkName(options); - environment = network - } else { - network = null - environment = 'LATEST' } consoleLogger.info(`Importing and creating local files for ${propertyName} from Property Manager...`); let createPropertyInfo = { propertyName, + propertyVersion, network }; @@ -647,7 +644,7 @@ Are you sure you want to deactivate the property '${propertyName}' on network '$ consoleLogger.info("update property info: ", helpers.jsonStringify(createPropertyInfo)); } else { let project = await devops.importProperty(createPropertyInfo); - consoleLogger.info(`Imported ${project.getName()}. The ${environment} version is: v${project.propertyVersion}`); + consoleLogger.info(`Imported ${project.getName()}. The local version is: v${project.propertyVersion}`); } }; @@ -676,15 +673,12 @@ Are you sure you want to DELETE the property '${options.property}'?`, const update = async function(devops, options) { let runPull = options.forceUpdate; let projectName = devops.extractProjectName(options); + let propertyVersion = parseInt(options.propver, 10); let network; if (options.network) { network = commonCli.checkNetworkName(options); - environment = network - } else { - network = null - environment = 'LATEST' - } + } if (!runPull) { var questions = [{ @@ -708,6 +702,7 @@ Are you sure you want to DELETE the property '${options.property}'?`, let createPropertyInfo = { projectName, variableMode, + propertyVersion, network }; @@ -719,7 +714,7 @@ Are you sure you want to DELETE the property '${options.property}'?`, } else { consoleLogger.info(`Updating and overwriting local files for ${projectName} from PAPI...`); let project = await devops.updateProperty(createPropertyInfo); - consoleLogger.info(`Updated ${project.getName()} to ${environment}: v${project.propertyVersion}`); + consoleLogger.info(`Updated ${projectName}. The local version is: v${project.propertyVersion}`); } } @@ -1096,9 +1091,10 @@ Are you sure you want to DELETE the property '${options.property}'?`, commander .command("update-local", "Update local property with the latest version from the Property Manager API.") .option('-p, --property ', 'Property name. Optional if default property was set using the set-default command.') + .option('--propver ', "Optional. The property version to activate. Uses latest version if not specified.", helpers.parsePropertyVersion) + .option('-n, --network ', "Optional. Network, either 'production' or 'staging'. You can shorten 'production' to " + "'prod' or 'p' and 'staging' to 'stage' or 's'.") .option('--dry-run', 'Verify the result of your command syntax before running it. Displays the JSON generated by the command as currently written.') .option('--force-update', 'WARNING: This option bypasses the confirmation prompt and automatically overwrites your local files.') - .option('-n, --network ', "Network, either 'production' or 'staging'. You can shorten 'production' to " + "'prod' or 'p' and 'staging' to 'stage' or 's'.") .option('--variable-mode ', `Choose how this command pulls in variables. Allowed values are ${printAllowedModesUpdateOrImport()}. Default functionality is no-var.`) .alias("ul") .on('--help', () => { @@ -1112,7 +1108,8 @@ Are you sure you want to DELETE the property '${options.property}'?`, commander .command("import", "Import an existing property from Property Manager.") .option('-p, --property ', 'Property name. Optional if default property was set using the set-default command.') - .option('-n, --network ', "Network, either 'production' or 'staging'. You can shorten 'production' to " + "'prod' or 'p' and 'staging' to 'stage' or 's'.") + .option('--propver ', "Optional. The property version to activate. Uses latest version if not specified.", helpers.parsePropertyVersion) + .option('-n, --network ', "Optional. Network, either 'production' or 'staging'. You can shorten 'production' to " + "'prod' or 'p' and 'staging' to 'stage' or 's'.") .option('--dry-run', 'Verify the result of your command syntax before running it. Displays the JSON generated by the command as currently written.') .option('--variable-mode ', `Choose how to pull in variables. Allowed values are ${printAllowedModesUpdateOrImport()}. By default, variables aren't imported (no-var).`) .alias("i")