Skip to content

Commit

Permalink
Merge pull request #152 from akamai/develop
Browse files Browse the repository at this point in the history
CLI changes for JsComposition
  • Loading branch information
lperra authored Aug 27, 2024
2 parents c34fbd0 + dbc91ca commit 7cf75d1
Show file tree
Hide file tree
Showing 12 changed files with 1,645 additions and 289 deletions.
823 changes: 552 additions & 271 deletions README.md

Large diffs are not rendered by default.

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.8.1",
"version": "1.9.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.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"name": "akamai-edgeworkers-cli",
"version": "1.8.1",
"version": "1.9.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": {
"build": "npm run build-ts",
"clean": "rm -rf node_modules",
"build-ts": "tsc",
"postinstall": "if test \"$NODE_ENV\" != \"production\" ; then npm run build ; fi",
"postinstall": "node scripts/postinstall.js",
"lint": "eslint . --ext .ts",
"lint:fix": "npm run lint -- --fix",
"test": "npm run lint; npm run test:run",
Expand Down
15 changes: 15 additions & 0 deletions scripts/postinstall.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const { exec } = require('node:child_process');
const nodeEnvironment = process.env.NODE_ENV;

if (nodeEnvironment !== 'production') {
exec('npm run build', (err, stdout, stderr) => {
if (err) {
console.error(err);
return;
}
console.log(stdout);
if (stderr) {
console.error(stderr);
}
});
}
204 changes: 200 additions & 4 deletions src/edgeworkers/ew-cli-main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,13 @@ import {
REPORT_ID,
END_DATE,
STATUS,
EVENT_HANDLERS } from './../utils/constants';
EVENT_HANDLERS,
PINNED_ONLY,
CURRENTLY_PINNED,
NOTE,
ACTIVE_VERSIONS,
CURRENTLY_PINNED_REVISIONS
} from './../utils/constants';
import * as cliHandler from './ew-handler';
import * as httpEdge from '../cli-httpRequest';
import { ewJsonOutput } from './client-manager';
Expand Down Expand Up @@ -367,6 +373,24 @@ program
cliUtils.logAndExit(0, copywrite);
});

program
.command('download-revision <edgeworker-identifier> <revision-identifier>')
.description('Download the combined code bundle that contains the code and the dependencies that the EdgeWorker executes')
.alias('dr')
.option('--downloadPath <downloadPath>', 'Path to store downloaded combined bundle file; defaults to CLI home directory if not provided')
.action(async function (ewId, revisionId, options) {
options['downloadPath'] = options.downloadPath || configUtils.searchProperty(DOWNLOAD_PATH);

try {
await cliHandler.downloadRevisionTarball(ewId, revisionId, options.downloadPath);
} catch (e) {
cliUtils.logAndExit(1, e);
}
})
.on('--help', function () {
cliUtils.logAndExit(0, copywrite);
});

program
.command('status <edgeworker-identifier>')
.description('List Activation status of a given EdgeWorker ID')
Expand Down Expand Up @@ -415,6 +439,174 @@ program
cliUtils.logAndExit(0, copywrite);
});

program
.command('list-revisions <edgeworker-identifier>')
.description('List the revision history for a given EdgeWorker ID')
.option('--versionId <versionId>', 'Version Identifier')
.option('--activationId <activationId>', 'Activation Identifier')
.option(
'--network <network>',
'Limits the results to versions that were activated on a specific network (STAGING or PRODUCTION)',
)
.option(
'--pinnedOnly',
'Limits results to show only currently or previously pinned revisions',
)
.option(
'--currentlyPinned',
'Limits results to show only revisions that are currently pinned',
)
.alias('lr')
.action(async function (ewId, options) {
options['versionId'] =
options.versionId || configUtils.searchProperty(VERSION_ID);
options['activationId'] =
options.activationId || configUtils.searchProperty(ACTIVATION_ID);
options['network'] = options.network || configUtils.searchProperty(NETWORK);
options['pinnedOnly'] =
options.pinnedOnly || configUtils.searchProperty(PINNED_ONLY);
options['currentlyPinned'] =
options.currentlyPinned || configUtils.searchProperty(CURRENTLY_PINNED);

try {
await cliHandler.showEdgeWorkerRevisionOverview(ewId, options);
} catch (e) {
cliUtils.logAndExit(1, e);
}
})
.on('--help', function () {
cliUtils.logAndExit(0, copywrite);
});

program
.command('get-revision <edgeworker-identifier> <revision-identifier>')
.description('Get details for a specific revision')
.alias('gr')
.action(async function (ewId, revId) {
try {
await cliHandler.getRevision(ewId, revId);
} catch (e) {
cliUtils.logAndExit(1, e);
}
})
.on('--help', function () {
cliUtils.logAndExit(0, copywrite);
});

program
.command('compare-revisions <edgeworker-identifier> <revision-identifier> <revision-identifier>')
.description('View dependency differences between two revisions of the same EdgeWorker.')
.alias('cr')
.action(async function (ewId, revId1, revId2) {
try {
await cliHandler.compareRevisions(ewId, revId1, revId2);
} catch (e) {
cliUtils.logAndExit(1, e);
}
})
.on('--help', function () {
cliUtils.logAndExit(0, copywrite);
});

program
.command('activate-revision <edgeworker-identifier> <revision-identifier>')
.description('Activate a revision for a given EdgeWorker Id on Akamai Network')
.option('--note <note>', 'Note to specify why the revision is being reactivated')
.alias('ar')
.action(async function (ewId, revId, options) {
options['note'] = options.note || configUtils.searchProperty(NOTE);

try {
await cliHandler.activateRevision(ewId, revId, options.note);
} catch (e) {
cliUtils.logAndExit(1, e);
}
})
.on('--help', function () {
cliUtils.logAndExit(0, copywrite);
});

program
.command('pin-revision <edgeworker-identifier> <revision-identifier>')
.description('Pin an active revision for a given EdgeWorker ID')
.option('--note <note>', 'Note to specify why the revision is being pinned')
.action(async function (ewId, revId, options) {
options['note'] = options.note || configUtils.searchProperty(NOTE);

try {
await cliHandler.pinRevision(ewId, revId, options.note);
} catch (e) {
cliUtils.logAndExit(1, e);
}
})
.on('--help', function () {
cliUtils.logAndExit(0, copywrite);
});

program
.command('unpin-revision <edgeworker-identifier> <revision-identifier>')
.description('Unpin an active pinned revision for a given EdgeWorker ID')
.option('--note <note>', 'Note to specify why the revision is being unpinned')
.action(async function (ewId, revId, options) {
options['note'] = options.note || configUtils.searchProperty(NOTE);

try {
await cliHandler.unpinRevision(ewId, revId, options.note);
} catch (e) {
cliUtils.logAndExit(1, e);
}
})
.on('--help', function () {
cliUtils.logAndExit(0, copywrite);
});

program
.command('get-revision-bom <edgeworker-identifier> <revision-identifier>')
.description('View details for a specific revision of a composite bundle')
.alias('gb')
.option('--activeVersions', 'Limit results to show only active versions')
.option('--currentlyPinnedRevisions', 'Shows additional information about the revision that\'s currently pinned')
.action(async function (ewId, revisionId, options) {
options['activeVersions'] = options.activeVersions || configUtils.searchProperty(ACTIVE_VERSIONS);
options['currentlyPinnedRevisions'] = options.currentlyPinnedRevisions || configUtils.searchProperty(CURRENTLY_PINNED_REVISIONS);

try {
await cliHandler.showRevisionBOM(ewId, revisionId, options);
} catch (e) {
cliUtils.logAndExit(1, e);
}
})
.on('--help', function () {
cliUtils.logAndExit(0, copywrite);
});

program
.command('list-revision-activations <edgeworker-identifier>')
.description('List Revision Activation status of a given EdgeWorker ID')
.alias('lra')
.option('--versionId <versionId>', 'Version Identifier')
.option('--activationId <activationId>', 'Activation Identifier')
.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);
options['network'] = options.network || configUtils.searchProperty(NETWORK);

// Do not provide both versionId and activationId
if (options.activationId && (options.versionId || options.network) ) {
cliUtils.logAndExit(1, 'ERROR: You may not provide the Activation identifier with versionId or network options.');
}

try {
await cliHandler.showEdgeWorkerRevisionActivationOverview(ewId, options);
} catch (e) {
cliUtils.logAndExit(1, e);
}
})
.on('--help', function () {
cliUtils.logAndExit(0, copywrite);
});

program
.command('clone <edgeworker-identifier> <resourceTierId>')
.description('Clone the given EdgeWorker ID on an Akamai network')
Expand Down Expand Up @@ -619,16 +811,20 @@ const log_level = program
log_level
.command('set')
.argument('<edgeworker-identifier>')
.addArgument(new Argument('<network>').choices(['production', 'staging']))
.addArgument(new Argument('<level>').choices(cliUtils.LOG_LEVELS.map((level: string) => level.toLowerCase())))
.addArgument(new Argument('<network>', `(choices: ${cliUtils.staging}, ${cliUtils.production})`))
.addArgument(new Argument('<level>', `(choices: ${cliUtils.LOG_LEVELS.join(', ')})`))
.option('--expires <time>', `Expire time for logging level change. Supports natural language input
like: '+1h', 'Next Saturday', as well as ISO Timestamps. Use '${cliUtils.LL_NEVER_EXPIRE_STR}'
for the change to never expire.`, cliUtils.LL_NEVER_EXPIRE_STR)
.option('--ds2Id <id>', 'Datastream 2 ID to use alongside the default specified in bundle.json')
.description('Set logging level for an Edgeworker.')
.action(async function (ewId: number, network: string, level: string, options) {
if (network.toUpperCase() !== cliUtils.staging && network.toUpperCase() !== cliUtils.production)
cliUtils.logAndExit(1, `ERROR: Network parameter must be either ${cliUtils.staging} or ${cliUtils.production} - was: ${network}`);
if (!cliUtils.LOG_LEVELS.includes(level.toUpperCase()))
cliUtils.logAndExit(1, `ERROR: Level parameter must be one of: ${cliUtils.LOG_LEVELS.join(', ')} - was: ${level}`);
try {
await cliHandler.setLogLevel(ewId, network, level, options);
await cliHandler.setLogLevel(ewId, network.toUpperCase(), level.toUpperCase(), options);
} catch (e) {
cliUtils.logAndExit(1, e);
}
Expand Down
Loading

0 comments on commit 7cf75d1

Please sign in to comment.