Skip to content

Commit

Permalink
Merge pull request #127 from akamai/develop
Browse files Browse the repository at this point in the history
Merge develop branch into develop for release 1.7.2
  • Loading branch information
bmatthew authored Mar 6, 2023
2 parents ecb2df5 + d3fe486 commit ab585b9
Show file tree
Hide file tree
Showing 12 changed files with 214 additions and 62 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,8 @@ Usage: `akamai edgeworkers status [options] <edgeworker-identifier>`
| -h, --help | output usage information |
| --versionId `<versionId>` | Version identifier |
| --activationId `<activationId>` | Activation identifier |
| --activeOnNetwork | Limits results to show only currently activate versions
| --network `<network>`| Limits the results to versions that were activated on a specific network (STAGING or PRODUCTION)

| Argument | Existence | Description |
| - | - | - |
Expand Down
4 changes: 2 additions & 2 deletions cli.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
"commands": [
{
"name": "edgeworkers",
"version": "1.7.1",
"version": "1.7.2",
"aliases": ["ew", "edgeworkers"],
"description": "Manage Akamai EdgeWorkers code bundles."
},
{
"name": "edgekv",
"version": "1.7.1",
"version": "1.7.2",
"aliases": ["ekv", "edgekv"],
"description": "Manage Akamai EdgeKV database."
}
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.7.1",
"version": "1.7.2",
"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
6 changes: 3 additions & 3 deletions src/cli-httpRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ export function sendEdgeRequest(
const edge = envUtils.getEdgeGrid();

let path = pth;
let qs = '&';
let queryString = '&';
if (accountKey) {
// Check if query string already included in path, if not use ? otherwise use &
if (path.indexOf('?') == -1) qs = '?';
path += `${qs}accountSwitchKey=${accountKey}`;
if (path.indexOf('?') == -1) queryString = '?';
path += `${queryString}accountSwitchKey=${accountKey}`;
}
if (path.includes(EDGEWORKERS_API_BASE)) {
headers[EDGEWORKERS_CLIENT_HEADER] = 'CLI';
Expand Down
22 changes: 11 additions & 11 deletions src/edgekv/ekv-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ const INIT_EKV_TIMEOUT = 120000;
const DEFAULT_EKV_TIMEOUT = 60000;

export function getNameSpaceList(network: string, details: boolean) {
let qs = '';
let queryString = '';
if (details) {
qs += `?details=${details}`;
queryString += `?details=${details}`;
}
return httpEdge
.getJson(
`${EDGEKV_API_BASE}/networks/${network}/namespaces${qs}`,
`${EDGEKV_API_BASE}/networks/${network}/namespaces${queryString}`,
cliUtils.getTimeout(DEFAULT_EKV_TIMEOUT),
ekvMetrics.listNameSpaces
)
Expand Down Expand Up @@ -241,16 +241,16 @@ export function getItemsFromGroup(
maxItems?: number,
sandboxid?: string
) {
let qs = '';
let queryString = '';
if (maxItems !== undefined) {
qs += `?maxItems=${maxItems}`;
queryString += `?maxItems=${maxItems}`;
}
if (sandboxid) {
qs += maxItems == undefined ? '?' : '&';
qs += `sandboxId=${sandboxid}`;
queryString += maxItems == undefined ? '?' : '&';
queryString += `sandboxId=${sandboxid}`;
}

const listItemsPath = `${EDGEKV_API_BASE}/networks/${network}/namespaces/${namespace}/groups/${groupId}${qs}`;
const listItemsPath = `${EDGEKV_API_BASE}/networks/${network}/namespaces/${namespace}/groups/${groupId}${queryString}`;
return httpEdge
.getJson(
listItemsPath,
Expand Down Expand Up @@ -300,13 +300,13 @@ export function getSingleToken(tokenName: string) {
}

export function getTokenList(incExpired: boolean) {
let qs = '';
let queryString = '';
if (incExpired) {
qs += `?includeExpired=${incExpired}`;
queryString += `?includeExpired=${incExpired}`;
}
return httpEdge
.getJson(
`${EDGEKV_API_BASE}/tokens${qs}`,
`${EDGEKV_API_BASE}/tokens${queryString}`,
cliUtils.getTimeout(DEFAULT_EKV_TIMEOUT),
ekvMetrics.readTokenList
)
Expand Down
16 changes: 12 additions & 4 deletions src/edgeworkers/ew-cli-main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ import {
WORKING_DIRECTORY,
DOWNLOAD_PATH,
VERSION_ID,
ACTIVATION_ID,
ACTIVATION_ID,
ACTIVE,
NETWORK,
EDGEWORKER_NAME,
EXPIRY,
EXPIRY,
FORMAT,
REPORT_ID,
END_DATE,
Expand Down Expand Up @@ -371,13 +373,19 @@ program
.alias('list-activations')
.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)')
.action(async function (ewId, options) {
options['versionId'] = options.versionId || configUtils.searchProperty(VERSION_ID);
options['activationId'] = options.activationId || configUtils.searchProperty(ACTIVATION_ID);
options['activeOnNetwork'] = options.activeOnNetwork || configUtils.searchProperty(ACTIVE);
options['network'] = options.network || configUtils.searchProperty(NETWORK);

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

try {
await cliHandler.showEdgeWorkerActivationOverview(ewId, options);
} catch (e) {
Expand Down
14 changes: 8 additions & 6 deletions src/edgeworkers/ew-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -805,18 +805,20 @@ export async function downloadTarball(

export async function showEdgeWorkerActivationOverview(
ewId: string,
options?: { versionId?: string; activationId?: string }
options?: { versionId?: string; activationId?: string; activeOnNetwork?: boolean; network?: string; }
) {
let activations = null;
const activation = [];
let accountId = '';
let versionId = options.versionId;
let activationId = options.activationId;
const active = options.activeOnNetwork;
const network = options.network;

if (versionId) {
activations = await cliUtils.spinner(
edgeWorkersSvc.getVersionActivations(ewId, versionId),
`Fetching all Activations for EdgeWorker Id ${ewId}, Version ${versionId}`
edgeWorkersSvc.getActivations(ewId, versionId, network),
`Fetching all Activations for EdgeWorker Id ${ewId}, Version ${versionId}${network ? ', Network ' + network : ''}`
);

if (Object.prototype.hasOwnProperty.call(activations, 'activations')){
Expand All @@ -830,8 +832,8 @@ export async function showEdgeWorkerActivationOverview(
activations = [activations];
} else {
activations = await cliUtils.spinner(
edgeWorkersSvc.getAllActivations(ewId),
`Fetching all Activations for EdgeWorker Id ${ewId}`
edgeWorkersSvc.getActivations(ewId, undefined, network, active),
`Fetching ${active ? 'active version' : 'all activations' } for EdgeWorker Id ${ewId}${network ? ' on ' + network : ''}`
);
// remove outer envelope of JSON data

Expand All @@ -857,7 +859,7 @@ export async function showEdgeWorkerActivationOverview(
);
});

const msg = `The following EdgeWorker Activations currently exist for account: ${accountId}, ewId: ${ewId}, version: ${versionId}, activationId: ${activationId}`;
const msg = `The following EdgeWorker Activations currently exist for account: ${accountId}, ewId: ${ewId}, version: ${active ? 'active' : versionId}, activationId: ${activationId}, network: ${network ? network : 'any'}`;
if (ewJsonOutput.isJSONOutputMode()) {
ewJsonOutput.writeJSONOutput(0, msg, activation);
} else {
Expand Down
71 changes: 38 additions & 33 deletions src/edgeworkers/ew-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ function fetchTarball(
) {
const edge = envUtils.getEdgeGrid();
let path = pth;
let qs = '&';
let queryString = '&';
const accountKey = httpEdge.accountKey;
if (accountKey) {
// Check if query string already included in path, if not use ? otherwise use &
if (path.indexOf('?') == -1) qs = '?';
path += `${qs}accountSwitchKey=${accountKey}`;
if (path.indexOf('?') == -1) queryString = '?';
path += `${queryString}accountSwitchKey=${accountKey}`;
}
headers[EDGEWORKERS_CLIENT_HEADER] = 'CLI';
// headers[EDGEWORKERS_IDE_HEADER] = 'VSCODE';
Expand Down Expand Up @@ -110,17 +110,17 @@ export function getEdgeWorkerId(ewId: string) {
}

export function getAllEdgeWorkerIds(groupId?: string, resourceTierId?: string) {
let qs = '';
let queryString = '';
if (groupId != undefined || groupId != null) {
qs += `?groupId=${groupId}`;
queryString += `?groupId=${groupId}`;
}
if (resourceTierId != undefined) {
qs += groupId == undefined ? '?' : '&';
qs += `resourceTierId=${resourceTierId}`;
queryString += groupId == undefined ? '?' : '&';
queryString += `resourceTierId=${resourceTierId}`;
}
return httpEdge
.getJson(
`${EDGEWORKERS_API_BASE}/ids${qs}`,
`${EDGEWORKERS_API_BASE}/ids${queryString}`,
cliUtils.getTimeout(DEFAULT_EW_TIMEOUT)
)
.then((r) => r.body)
Expand Down Expand Up @@ -154,13 +154,13 @@ export function getContracts() {
}

export function getProperties(ewId: string, activeOnly: boolean) {
let qs = '';
let queryString = '';
if (activeOnly !== undefined) {
qs = '?activeOnly=true';
queryString = '?activeOnly=true';
}
return httpEdge
.getJson(
`${EDGEWORKERS_API_BASE}/ids/${ewId}/properties${qs}`,
`${EDGEWORKERS_API_BASE}/ids/${ewId}/properties${queryString}`,
cliUtils.getTimeout(DEFAULT_EW_TIMEOUT)
)
.then((r) => r.body)
Expand Down Expand Up @@ -269,13 +269,32 @@ export function deleteVersion(ewId: string, versionId: string) {
.catch((err) => error.handleError(err, 'DELETE_VERSION'));
}

export function getAllActivations(ewId: string) {
export function getActivations(ewId: string, versionId?: string, network?: string, active?: boolean) {
let queryString = '?';

if ((network == undefined || network == null) && (active == undefined || active == null) && (versionId === undefined || versionId === null)) {
queryString = '';
} else {
if (versionId) {
queryString += `version=${versionId}`;
}

if (active) {
queryString += `${queryString == '?' ? '' : '&'}activeOnNetwork=true`;
}

if (network) {
queryString += `${queryString == '?' ? '' : '&'}network=${network}`;
}
}

return httpEdge
.getJson(
`${EDGEWORKERS_API_BASE}/ids/${ewId}/activations`,
`${EDGEWORKERS_API_BASE}/ids/${ewId}/activations${queryString}`,
cliUtils.getTimeout(DEFAULT_EW_TIMEOUT)
)
.then((r) => r.body);
.then((r) => r.body)
.catch((err) => error.handleError(err, 'GET_ACTIVATIONS'));
}

export function getActivationID(ewId: string, activationId: string) {
Expand All @@ -287,20 +306,6 @@ export function getActivationID(ewId: string, activationId: string) {
.then((r) => r.body);
}

export function getVersionActivations(ewId: string, versionId: string) {
let qs = '?version=';
if (versionId === undefined || versionId === null) {
qs = '';
versionId = '';
}
return httpEdge
.getJson(
`${EDGEWORKERS_API_BASE}/ids/${ewId}/activations${qs}${versionId}`,
cliUtils.getTimeout(DEFAULT_EW_TIMEOUT)
)
.then((r) => r.body);
}

export function createActivationId(
ewId: string,
network: string,
Expand Down Expand Up @@ -420,18 +425,18 @@ export function getReport (
eventHandlers: Array<string>,
end?: string,
) {
let qs = `?start=${start}&edgeWorker=${ewid}`;
if (end) qs += `&end=${end}`;
let queryString = `?start=${start}&edgeWorker=${ewid}`;
if (end) queryString += `&end=${end}`;
for (const status of statuses){
qs += `&status=${status}`;
queryString += `&status=${status}`;
}
for (const eventHandler of eventHandlers){
qs += `&eventHandler=${eventHandler}`;
queryString += `&eventHandler=${eventHandler}`;
}

return httpEdge
.getJson(
`${EDGEWORKERS_API_BASE}/reports/${reportId}${qs}`,
`${EDGEWORKERS_API_BASE}/reports/${reportId}${queryString}`,
cliUtils.getTimeout(DEFAULT_EW_TIMEOUT)
)
.then((r) => r.body)
Expand Down
1 change: 1 addition & 0 deletions src/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export const RESOURCE_TIER_ID = 'resourceTierId';
export const CONTRACT_ID = 'contractId';
export const VERSION_ID = 'versionId';
export const ACTIVATION_ID = 'activationId';
export const ACTIVE = 'activeOnNetwork';
export const REPORT_ID = 'reportId';
export const BUNDLE_PATH = 'bundlePath';
export const WORKING_DIRECTORY = 'workingDirectory';
Expand Down
1 change: 1 addition & 0 deletions src/utils/http-error-message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export enum ErrorMessage {
GENERIC_403 = 'Permission is invalid.',
GET_LIMITS_ERROR = 'ERROR: Unable to get EdgeWorkers limits.',
GET_AVAILABLE_REPORTS_ERROR = 'ERROR: Unable to get available EdgeWorkers reports.',
GET_ACTIVATIONS_ERROR = 'ERROR: Unable to get EdgeWorkers activations.',
GET_REPORT_ERROR = 'ERROR: Unable to get EdgeWorkers report.',
REGISTER_EW_ERROR = 'ERROR: Unable to create Edgeworker.',
UPDATE_EW_ERROR = 'ERROR: Unable to update Edgeworker.',
Expand Down
Loading

0 comments on commit ab585b9

Please sign in to comment.