Skip to content

Commit

Permalink
Pull request #29: EW-25227 Implement CLI changes for initial revision…
Browse files Browse the repository at this point in the history
… auto-pin (#166)

Merge in EDGEWORKERS/cli-edgeworkers from feature/EW-25227 to develop

Squashed commit of the following:

commit 95485b70c2f77e04c5f4ebec0e965225ea83af90
Author: Kyle Li <[email protected]>
Date:   Tue Jan 7 13:17:10 2025 -0500

    EW-25227 Fixed comments

commit e853146f45fd2eaa01a183cff4d8b6c6e1171bfc
Author: Kyle Li <[email protected]>
Date:   Fri Dec 27 14:30:52 2024 -0500

    EW-25227 Implement CLI changes for initial revision auto-pin
  • Loading branch information
kyleli-akamai authored Jan 29, 2025
1 parent bf9ea09 commit d8ac809
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 16 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -545,9 +545,10 @@ Activate a Version for a given EdgeWorker Id on an Akamai Network.

Usage: `akamai edgeworkers activate [options] <edgeworker-identifier> <network> <version-identifier>`

| Option | Description |
|------------|--------------------------|
| -h, --help | output usage information |
| Option | Description |
|------------|-------------------------------------------------------------------------------------------------|
| -h, --help | output usage information |
| --auto-pin | An option that pins the initial revision when activating the parent EdgeWorker, true by default |

| Argument | Existence | Description |
|-----------------------|-----------|-------------------------------------------------------------------------------------|
Expand Down
2 changes: 1 addition & 1 deletion cli.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"commands": [
{
"name": "edgeworkers",
"version": "1.9.0",
"version": "1.10.0",
"aliases": ["ew", "edgeworkers"],
"description": "Manage Akamai EdgeWorkers code bundles."
},
Expand Down
4 changes: 2 additions & 2 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 package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "akamai-edgeworkers-cli",
"version": "1.9.0",
"version": "1.10.0",
"description": "A tool that makes it easier to manage Akamai EdgeWorkers code bundles and EdgeKV databases. Call the EdgeWorkers and EdgeKV API from the command line.",
"repository": "https://github.com/akamai/cli-edgeworkers",
"scripts": {
Expand Down
10 changes: 7 additions & 3 deletions src/edgeworkers/ew-cli-main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ program
.option('--versionId <versionId>', 'Version Identifier')
.option('--activationId <activationId>', 'Activation Identifier')
.option('--activeOnNetwork', 'Limits results to show only currently activate versions')
.option('--network <network>', 'Limits the results to versions that were activated on a specific network (STAGING or PRODUCTION)')
.option('--network <network>', 'Limits the results to versions that were activated on a specific network (STAGING or PRODUCTION)')
.action(async function (ewId, options) {
options['versionId'] = options.versionId || configUtils.searchProperty(VERSION_ID);
options['activationId'] = options.activationId || configUtils.searchProperty(ACTIVATION_ID);
Expand All @@ -424,13 +424,17 @@ program
.command('activate <edgeworker-identifier> <network> <version-identifier>')
.description('Activate a Version for a given EdgeWorker ID on an Akamai Network')
.alias('av')
.action(async function (ewId, network, versionId) {
.option('--auto-pin <autoPin>', 'Indicator to tell initial revision is pinned or not, true by default.')
.action(async function (ewId, network, versionId, options) {
if (options.autoPin != undefined) {
options.autoPin = (options.autoPin.toLowerCase() === 'true' ? true : false);
}

// Network must use correct keyword STAGING|PRODUCTION
if (network.toUpperCase() !== cliUtils.staging && network.toUpperCase() !== cliUtils.production)
cliUtils.logAndExit(1, `ERROR: Network parameter must be either staging or production - was: ${network}`);
try {
await cliHandler.createNewActivation(ewId, network.toUpperCase(), versionId);
await cliHandler.createNewActivation(ewId, network.toUpperCase(), versionId, options.autoPin);
} catch (e) {
cliUtils.logAndExit(1, e);
}
Expand Down
13 changes: 8 additions & 5 deletions src/edgeworkers/ew-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1287,11 +1287,14 @@ export async function showEdgeWorkerActivationOverview(
export async function createNewActivation(
ewId: string,
network: string,
versionId: string
versionId: string,
autoPin?: boolean
) {
// autoPin is set to true by default
const autoPinParam = autoPin != undefined ? autoPin : true;
let activations = await cliUtils.spinner(
edgeWorkersSvc.createActivationId(ewId, network, versionId),
`Creating Activation record for EdgeWorker Id ${ewId}, version: ${versionId} on network: ${network}`
edgeWorkersSvc.createActivationId(ewId, network, versionId, autoPin),
`Creating Activation record with auto pin status [${autoPinParam}] for EdgeWorker Id ${ewId}, version: ${versionId} on network: ${network}`
);

if (activations) {
Expand All @@ -1302,7 +1305,7 @@ export async function createNewActivation(
filterJsonData(activations[key], activationColumnsToKeep)
);
});
const msg = `New Activation record created for EdgeWorker Id: ${ewId}, version: ${versionId}, on network: ${network}`;
const msg = `New Activation record with auto pin status [${autoPinParam}] created for EdgeWorker Id: ${ewId}, version: ${versionId}, on network: ${network}`;
if (ewJsonOutput.isJSONOutputMode()) {
ewJsonOutput.writeJSONOutput(0, msg, activation);
} else {
Expand All @@ -1312,7 +1315,7 @@ export async function createNewActivation(
} else {
cliUtils.logAndExit(
1,
`ERROR: Activation record was not able to be created for EdgeWorker Id ${ewId}, version: ${versionId} on network: ${network}!`
`ERROR: Activation record with auto pin status [${autoPinParam}] was not able to be created for EdgeWorker Id ${ewId}, version: ${versionId} on network: ${network}!`
);
}
}
Expand Down
7 changes: 6 additions & 1 deletion src/edgeworkers/ew-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -322,9 +322,14 @@ export function getActivationID(ewId: string, activationId: string) {
export function createActivationId(
ewId: string,
network: string,
versionId: string
versionId: string,
autoPin?: boolean
) {
const body = {network: network, version: versionId};
if (autoPin != undefined) {
body['autoPin'] = autoPin;
}

return httpEdge
.postJson(
`${EDGEWORKERS_API_BASE}/ids/${ewId}/activations`,
Expand Down

0 comments on commit d8ac809

Please sign in to comment.