Skip to content

Commit 26efb40

Browse files
authored
Merge pull request #100 from akamai/develop
Release CLI version 1.15.0
2 parents b3e493d + 5edbba5 commit 26efb40

8 files changed

Lines changed: 63 additions & 47 deletions

File tree

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,8 @@ You can use this example "recipe" to quickly customize the sandbox to your devel
129129
"property":"123456:2",
130130
"requestHostnames":[
131131
"localhost2"
132-
]
132+
],
133+
"cpcode": 1234
133134
},
134135
{
135136
"hostname":"www.example.com",

cli.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"commands": [
66
{
77
"name": "sandbox",
8-
"version": "1.4.0",
8+
"version": "1.5.0",
99
"description": "Manage Akamai Sandbox environments.",
1010
"bin": "https://github.com/akamai/cli-sandbox/releases/download/{{.Version}}/akamai-{{.Name}}-{{.Version}}-{{.OS}}-{{.Arch}}{{.BinSuffix}}"
1111
}

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "akamai-sandbox-cli",
3-
"version": "1.4.0",
3+
"version": "1.5.0",
44
"description": "A tool that makes it easier to manage Akamai Sandboxes. Call the Sandbox API from the command line.",
55
"repository": "https://github.com/akamai/cli-sandbox",
66
"license": "Apache-2.0",

schemas/recipe.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@
3939
},
4040
"minItems": 1
4141
},
42+
"cpcode": {
43+
"type": "number"
44+
},
4245
"hostname": {
4346
"type": "string"
4447
},

src/cli-main.ts

Lines changed: 47 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,9 @@ async function showSandboxOverview(sandboxId: string) {
153153
console.log(`default: ${localSandbox.isCurrent}\n`);
154154
}
155155
const sandbox = await cliUtils.spinner(sandboxSvc.getSandbox(sandboxId));
156+
const properties = await cliUtils.spinner(Promise.all(
157+
sandbox.properties.map(p => sandboxSvc.getProperty(sandboxId, p.sandboxPropertyId)))
158+
);
156159

157160
cliUtils.logWithBorder('Detailed information for the sandbox');
158161

@@ -163,8 +166,9 @@ async function showSandboxOverview(sandboxId: string) {
163166

164167
cliUtils.logWithBorder('Sandbox Properties');
165168

166-
sandbox.properties.forEach(p => {
169+
properties.forEach(p => {
167170
console.log('sandbox-property-id: ' + p.sandboxPropertyId);
171+
console.log('cpcode: ' + p.cpcode);
168172
console.log(`request hostname(s): ${p.requestHostnames.join(', ')}\n`);
169173
});
170174
}
@@ -226,12 +230,20 @@ function parseToBoolean(str: string) {
226230
}
227231
}
228232

229-
async function updateHostnamesAndRules(requestHostnames, rulesFilePath, sandboxId, sandboxPropertyId) {
230-
if (requestHostnames) {
233+
async function updateProperty(sandboxId, sandboxPropertyId, requestHostnames, cpCode, rulesFilePath) {
234+
if (requestHostnames || cpCode) {
231235
const property = await cliUtils.spinner(sandboxSvc.getProperty(sandboxId, sandboxPropertyId), `Loading a property with id: ${sandboxPropertyId}`);
232-
property.requestHostnames = parseHostnameCsv(requestHostnames);
236+
237+
if (requestHostnames) {
238+
property.requestHostnames = parseHostnameCsv(requestHostnames);
239+
}
240+
if (cpCode) {
241+
property.cpcode = cpCode;
242+
}
243+
233244
await cliUtils.spinner(sandboxSvc.updateProperty(sandboxId, property), `Updating sandbox-property-id: ${sandboxPropertyId}`);
234245
}
246+
235247
if (rulesFilePath) {
236248
const rules = getJsonFromFile(rulesFilePath);
237249
await cliUtils.spinner(sandboxSvc.updateRules(sandboxId, sandboxPropertyId, rules), 'Updating rules.');
@@ -253,12 +265,12 @@ function parseHostnameCsv(csv) {
253265
.filter(hn => hn.length > 0);
254266
}
255267

256-
async function addPropertyFromRules(sandboxId: string, papiFilePath: string, hostnames: Array<string>) {
268+
async function addPropertyFromRules(sandboxId: string, papiFilePath: string, hostnames: Array<string>, cpCode: number) {
257269
if (!fs.existsSync(papiFilePath)) {
258270
cliUtils.logAndExit(1, `File: ${papiFilePath} does not exist.`);
259271
}
260272
const papiJson = getJsonFromFile(papiFilePath);
261-
return await cliUtils.spinner(sandboxSvc.addPropertyFromRules(sandboxId, hostnames, papiJson), `adding sandbox property to ${sandboxId}`);
273+
return await cliUtils.spinner(sandboxSvc.addPropertyFromRules(sandboxId, hostnames, cpCode, papiJson), `adding sandbox property to ${sandboxId}`);
262274
}
263275

264276
async function createFromRules(papiFilePath: string, propForRules: string, hostnames: Array<string>, isClonable: boolean, name: string, cpcode: number) {
@@ -303,15 +315,15 @@ function parseHostnameSpecifier(hostnameSpecifier) {
303315
return {hostname: hostnameSpecifier};
304316
}
305317

306-
async function addPropertyToSandboxFromProperty(sandboxId: string, hostnames: Array<string>, propertySpecifier: string) {
318+
async function addPropertyToSandboxFromProperty(sandboxId: string, hostnames: Array<string>, cpCode: number, propertySpecifier: string) {
307319
const propertySpecObj = parsePropertySpecifier(propertySpecifier);
308320
const msg = `Adding property from: ${JSON.stringify(propertySpecObj)}`;
309-
return await cliUtils.spinner(sandboxSvc.addPropertyFromProperty(sandboxId, hostnames, propertySpecObj), msg);
321+
return await cliUtils.spinner(sandboxSvc.addPropertyFromProperty(sandboxId, hostnames, cpCode, propertySpecObj), msg);
310322
}
311323

312-
async function addPropertyToSandboxFromHostname(sandboxId: string, hostnames: Array<string>, hostname: string) {
324+
async function addPropertyToSandboxFromHostname(sandboxId: string, hostnames: Array<string>, cpCode: number, hostname: string) {
313325
const msg = `Adding property based on: ${hostname}`;
314-
return await cliUtils.spinner(sandboxSvc.addPropertyFromProperty(sandboxId, hostnames, {hostname}), msg);
326+
return await cliUtils.spinner(sandboxSvc.addPropertyFromProperty(sandboxId, hostnames, cpCode, {hostname}), msg);
315327
}
316328

317329
async function createFromProperty(propertySpecifier: string, hostnames: Array<string>, isClonable: boolean, name: string, cpcode: number) {
@@ -344,8 +356,9 @@ function resolveRulesPath(recipeFilePath, rulesPath) {
344356
}
345357

346358
async function createFromPropertiesRecipe(recipe, cpcode) {
347-
const sandboxRecipe = recipe.sandbox;
348-
const properties = sandboxRecipe.properties;
359+
const cloneable = recipe.sandbox.clonable
360+
const sandboxName = recipe.sandbox.name
361+
const properties = recipe.sandbox.properties;
349362

350363
const firstProp = properties[0];
351364
let propForRules;
@@ -360,7 +373,8 @@ async function createFromPropertiesRecipe(recipe, cpcode) {
360373
}
361374

362375
console.log(`Creating sandbox and property 1 from recipe.`);
363-
const r = await cliUtils.spinner(createRecipeSandboxAndProperty(firstProp, propForRules, sandboxRecipe, cpcode));
376+
const r = await cliUtils.spinner(createRecipeSandboxAndProperty(firstProp, propForRules, cloneable, sandboxName,
377+
cpcode || firstProp.cpcode));
364378

365379
for (let i = 1; i < properties.length; i++) {
366380
try {
@@ -505,23 +519,23 @@ async function createFromRecipe(recipeFilePath, name, clonable, cpcode, originFr
505519

506520
function createRecipeProperty(rp, sandboxId) {
507521
if (rp.property) {
508-
return addPropertyToSandboxFromProperty(sandboxId, rp.requestHostnames, rp.property);
522+
return addPropertyToSandboxFromProperty(sandboxId, rp.requestHostnames, rp.cpcode, rp.property);
509523
} else if (rp.rulesPath) {
510-
return addPropertyFromRules(sandboxId, rp.rulesPath, rp.requestHostnames);
524+
return addPropertyFromRules(sandboxId, rp.rulesPath, rp.requestHostnames, rp.cpcode);
511525
} else if (rp.hostname) {
512-
return addPropertyToSandboxFromHostname(sandboxId, rp.requestHostnames, rp.hostname);
526+
return addPropertyToSandboxFromHostname(sandboxId, rp.requestHostnames, rp.cpcode, rp.hostname);
513527
} else {
514528
cliUtils.logAndExit(1, 'Critical error with recipe property. Define the rulesPath or property.');
515529
}
516530
}
517531

518-
function createRecipeSandboxAndProperty(rp, propertyForRules, recipe, cpcode) {
532+
function createRecipeSandboxAndProperty(rp, propertyForRules, isCloneable, sandboxName, cpcode) {
519533
if (rp.property) {
520-
return createFromProperty(rp.property, rp.requestHostnames, recipe.clonable, recipe.name, cpcode);
534+
return createFromProperty(rp.property, rp.requestHostnames, isCloneable, sandboxName, cpcode);
521535
} else if (rp.hostname) {
522-
return createFromHostname(rp.hostname, rp.requestHostnames, recipe.clonable, recipe.name, cpcode);
536+
return createFromHostname(rp.hostname, rp.requestHostnames, isCloneable, sandboxName, cpcode);
523537
} else if (rp.rulesPath) {
524-
return createFromRules(rp.rulesPath, propertyForRules, rp.requestHostnames, recipe.clonable, recipe.name, cpcode);
538+
return createFromRules(rp.rulesPath, propertyForRules, rp.requestHostnames, isCloneable, sandboxName, cpcode);
525539
} else {
526540
cliUtils.logAndExit(1, 'Critical error with recipe property. Define the rulesPath or property.');
527541
}
@@ -596,13 +610,13 @@ async function downloadClientIfNecessary() {
596610
}
597611
}
598612

599-
function addPropertyToSandbox(sandboxId, property, rulesPath, hostname, requestHostnames) {
613+
function addPropertyToSandbox(sandboxId, property, rulesPath, hostname, requestHostnames, cpCode) {
600614
if (property) {
601-
return addPropertyToSandboxFromProperty(sandboxId, requestHostnames, property);
615+
return addPropertyToSandboxFromProperty(sandboxId, requestHostnames, cpCode, property);
602616
} else if (rulesPath) {
603-
return addPropertyFromRules(sandboxId, rulesPath, requestHostnames);
617+
return addPropertyFromRules(sandboxId, rulesPath, requestHostnames, cpCode);
604618
} else if (hostname) {
605-
return addPropertyToSandboxFromHostname(sandboxId, requestHostnames, hostname);
619+
return addPropertyToSandboxFromHostname(sandboxId, requestHostnames, cpCode, hostname);
606620
} else {
607621
cliUtils.logAndExit(1, `Critical error while adding property to the sandbox : ${sandboxId} You need to define the rulesPath or property.`);
608622
}
@@ -837,11 +851,13 @@ program
837851
.description('Updates the sandbox’s property.')
838852
.option('-r, --rules <file>', 'JSON file containing a PAPI rule tree.')
839853
.option('-H, --requesthostnames <string>', 'Comma-delimited list of request hostnames within the sandbox.')
854+
.option('-C, --cpcode <cpcode>', 'Specify an existing cpcode instead of letting the system generate a new one.')
840855
.action(async function(sandboxId, sandboxPropertyId, options) {
841856
const rules = options.rules;
842857
const requestHostnames = options.requesthostnames;
858+
const cpCode = options.cpcode;
843859
try {
844-
await updateHostnamesAndRules(requestHostnames, rules, sandboxId, sandboxPropertyId);
860+
await updateProperty(sandboxId, sandboxPropertyId, requestHostnames, cpCode, rules);
845861
console.log(`Successfully updated sandbox-id: ${sandboxId} sandbox-property-id: ${sandboxPropertyId}`);
846862
} catch (e) {
847863
handleException(e);
@@ -854,6 +870,7 @@ program
854870
.option('-r, --rules <file>', 'JSON file containing a PAPI rule tree.')
855871
.option('-c, --clonable <boolean>', 'Make this sandbox clonable? (Y/N)')
856872
.option('-n, --name <string>', 'Name of sandbox.')
873+
.option('-C, --cpcode <cpcode>', 'Specify an existing cpcode instead of letting the system generate a new one.')
857874
.option('-H, --requesthostnames <string>', 'Comma-delimited list of request hostnames within the sandbox.')
858875
.option('--recipe <file>', 'Path to `recipe.json` file.')
859876
.action(async function(arg, options) {
@@ -876,12 +893,12 @@ program
876893

877894
await cliUtils.spinner(sandboxSvc.updateSandbox(sandbox), `updating sandbox-id: ${sandbox.sandboxId}`);
878895

879-
const propertyChange: boolean = !!options.requesthostnames || !!options.rules;
896+
const propertyChange: boolean = !!options.cpcode || !!options.requesthostnames || !!options.rules;
880897
if (propertyChange && sandbox.properties.length > 1) {
881898
cliUtils.logAndExit(1, `Unable to update property as multiple were found (${sandbox.properties.length}). Use update-property to add additional properties to the sandbox.`);
882899
}
883900
const sandboxPropertyId = sandbox.properties[0].sandboxPropertyId;
884-
await updateHostnamesAndRules(options.requesthostnames, options.rules, sandboxId, sandboxPropertyId);
901+
await updateProperty(sandboxId, sandboxPropertyId, options.requesthostnames, options.cpcode, options.rules);
885902
console.log(`Successfully updated sandbox-id: ${sandboxId}`)
886903
} catch (e) {
887904
handleException(e);
@@ -1003,13 +1020,15 @@ program
10031020
.option('-r, --rules <file>', 'JSON file containing a PAPI rule tree.')
10041021
.option('-p, --property <property-id | property-name:version>', 'Property to use. If you do not specify a version, the most recent version is used.')
10051022
.option('-o, --hostname <hostname>', 'The hostname of your Akamai property, such as www.example.com.')
1023+
.option('-C, --cpcode <cpcode>', 'Specify an existing cpcode instead of letting the system generate a new one.')
10061024
.option('-H, --requesthostnames <string>', 'Comma separated list of request hostnames.')
10071025
.action(async function(arg, options) {
10081026
helpExitOnNoArgs(options);
10091027
try {
10101028
const papiFilePath = options.rules;
10111029
const propertySpecifier = options.property;
10121030
const hostnameSpecifier = options.hostname;
1031+
const cpCode = options.cpcode;
10131032
const hostnamesCsv = options.requesthostnames;
10141033

10151034
let sandboxId;
@@ -1031,7 +1050,7 @@ program
10311050
}
10321051
const hostnames = hostnamesCsv ? parseHostnameCsv(hostnamesCsv) : undefined;
10331052

1034-
await addPropertyToSandbox(sandboxId, propertySpecifier, papiFilePath, hostnameSpecifier, hostnames);
1053+
await addPropertyToSandbox(sandboxId, propertySpecifier, papiFilePath, hostnameSpecifier, hostnames, cpCode);
10351054
} catch (e) {
10361055
handleException(e);
10371056
}

src/service/sandbox-client-manager.ts

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -180,11 +180,6 @@ export async function hasSandboxFolder(sandboxName) {
180180
return files.some(fileItem => fileItem.toLowerCase() === sandboxName.toLowerCase());
181181
}
182182

183-
184-
function versionToNumber(version) {
185-
return version.split('.').map(s => parseInt(s)).reduce((acc, value) => 100 * acc + value);
186-
}
187-
188183
export async function executeSandboxClient(printLogs) {
189184
const loggingPath = getLogPath();
190185
const loggingFilePath = path.join(loggingPath, 'sandbox-client.log');
@@ -199,14 +194,8 @@ export async function executeSandboxClient(printLogs) {
199194
`"${await envUtils.getJavaExecutablePath()}"`
200195
];
201196

202-
if (versionToNumber(CONNECTOR_VERSION) >= versionToNumber('1.3.1')) {
203-
args.push(`-DLOG_PATH="${loggingPath}"`);
204-
args.push(`-DLOGGING_CONFIG_FILE="${LOG_CONFIG_FILE}"`);
205-
} else {
206-
args.push(`-Dlogging.file.path="${loggingPath}"`);
207-
args.push(`-Dlogging.config="${LOG_CONFIG_FILE}"`);
208-
}
209-
197+
args.push(`-DLOG_PATH="${loggingPath}"`);
198+
args.push(`-DLOGGING_CONFIG_FILE="${LOG_CONFIG_FILE}"`);
210199
args.push(`-jar "${JAR_FILE_PATH}"`);
211200
args.push(`--config="${configPath}"`);
212201

src/service/sandbox-svc.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,21 +178,25 @@ export function createFromRules(papiRules, fromPropertyObj, requestHostnames, na
178178
return postJson(`${SANDBOX_API_BASE}/sandboxes`, bodyObj).then(r => r.body);
179179
}
180180

181-
export function addPropertyFromRules(sandboxId: string, requestHostnames, papiRules) {
181+
export function addPropertyFromRules(sandboxId: string, requestHostnames, cpCode: number, papiRules) {
182182
const bodyObj = {
183+
cpCode: cpCode,
183184
requestHostnames: requestHostnames,
184185
createFromRules: papiRules
185186
};
186187
return postJson(`${SANDBOX_API_BASE}/sandboxes/${sandboxId}/properties`, bodyObj).then(r => r.body);
187188
}
188189

189-
export function addPropertyFromProperty(sandboxId: string, requestHostnames, fromPropertyObj) {
190+
export function addPropertyFromProperty(sandboxId: string, requestHostnames, cpCode: number, fromPropertyObj) {
190191
const bodyObj = {
191192
createFromProperty: fromPropertyObj,
192193
};
193194
if (requestHostnames) {
194195
bodyObj['requestHostnames'] = requestHostnames;
195196
}
197+
if (cpCode) {
198+
bodyObj['cpcode'] = cpCode;
199+
}
196200
return postJson(`${SANDBOX_API_BASE}/sandboxes/${sandboxId}/properties`, bodyObj).then(r => r.body);
197201
}
198202

0 commit comments

Comments
 (0)