Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <Optional: network> --propver <Optional: 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. <br> 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.

Expand Down Expand Up @@ -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 <Optional: network> --propver <Optional: 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. <br> This folder contains a separate JSON-based configuration snippet for each rule in your property configuration.

Expand Down Expand Up @@ -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 <property_name>`. <br> The `update-local` command overrides any locally-saved configuration version with the latest active property version.
To retrieve all updates from the latest or specific property version, run this command: `akamai property-manager update-local -p <property_name> --network <Optional: network> --propver <Optional: propver>`. <br> The `update-local` command overrides any locally-saved configuration version with the latest or specified property version.

## Retrieve a specific rule from Property Manager

Expand Down
6 changes: 6 additions & 0 deletions docs/cli_pm_commands_help.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,9 @@ Creates a local version of an existing property.
Options:
-p, --property <propertyName> Property name. Optional if default property
was set using the set-default command.
-n, --network <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
Expand All @@ -155,6 +158,9 @@ Update local property with the latest from the Property Manager API (PAPI).
Options:
-p, --property <propertyName> Property name. Optional if default property
was set using the set-default command.
-n, --network <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
Expand Down
9 changes: 7 additions & 2 deletions src/papi.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
7 changes: 4 additions & 3 deletions src/pm/devops_property_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +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);
let propertyInfo = await project.getPropertyInfo(createPropertyInfo.propertyId, createPropertyInfo.propertyVersion, 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);
Expand Down Expand Up @@ -171,9 +172,9 @@ class DevopsPropertyManager extends Devops {
}
envInfo.propertyId = helpers.parsePropertyId(results.versions.items[0].propertyId);
}
let propertyInfo = await project.getPropertyInfo(envInfo.propertyId);

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;
Expand Down
30 changes: 26 additions & 4 deletions src/pm/property_manager_cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 propertyVersion = parseInt(options.propver, 10);
let network;
if (!propertyName || _.isBoolean(propertyName)) {
throw new errors.DependencyError("Missing property option! Use akamai property-manager import -p <property name> ...",
"missing_property_name");
}

if (options.network) {
network = commonCli.checkNetworkName(options);
}

consoleLogger.info(`Importing and creating local files for ${propertyName} from Property Manager...`);
let createPropertyInfo = {
propertyName
propertyName,
propertyVersion,
network
};

let variableMode = helpers.allowedModes[1];
Expand All @@ -635,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 latest version is: v${project.loadEnvironmentInfo().latestVersionInfo.propertyVersion}`);
consoleLogger.info(`Imported ${project.getName()}. The local version is: v${project.propertyVersion}`);

}
};
Expand Down Expand Up @@ -664,6 +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);
}

if (!runPull) {
var questions = [{
Expand All @@ -683,9 +698,12 @@ 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,
propertyVersion,
network
};

let dryRun = options.dryRun || false;
Expand All @@ -696,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 the latest: v${project.loadEnvironmentInfo().latestVersionInfo.propertyVersion}`);
consoleLogger.info(`Updated ${projectName}. The local version is: v${project.propertyVersion}`);
}
}

Expand Down Expand Up @@ -1073,6 +1091,8 @@ 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 <propertyName>', 'Property name. Optional if default property was set using the set-default command.')
.option('--propver <propver>', "Optional. The property version to activate. Uses latest version if not specified.", helpers.parsePropertyVersion)
.option('-n, --network <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('--variable-mode <variableMode>', `Choose how this command pulls in variables. Allowed values are ${printAllowedModesUpdateOrImport()}. Default functionality is no-var.`)
Expand All @@ -1088,6 +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 <propertyName>', 'Property name. Optional if default property was set using the set-default command.')
.option('--propver <propver>', "Optional. The property version to activate. Uses latest version if not specified.", helpers.parsePropertyVersion)
.option('-n, --network <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 <variableMode>', `Choose how to pull in variables. Allowed values are ${printAllowedModesUpdateOrImport()}. By default, variables aren't imported (no-var).`)
.alias("i")
Expand Down
5 changes: 3 additions & 2 deletions src/project.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
32 changes: 32 additions & 0 deletions tests/snippets/snippets_cli_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
});

Expand Down Expand Up @@ -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 <property name> 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 () {
Expand Down