@@ -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
264276async 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
317329async function createFromProperty ( propertySpecifier : string , hostnames : Array < string > , isClonable : boolean , name : string , cpcode : number ) {
@@ -344,8 +356,9 @@ function resolveRulesPath(recipeFilePath, rulesPath) {
344356}
345357
346358async 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
506520function 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 }
0 commit comments