Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

validate EwId in command update-id #115

Merged
merged 1 commit into from
Dec 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.5.2",
"version": "1.6.2",
"aliases": ["ew", "edgeworkers"],
"description": "Manage Akamai EdgeWorkers code bundles."
},
{
"name": "edgekv",
"version": "1.5.2",
"version": "1.6.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.6.1",
"version": "1.6.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
5 changes: 5 additions & 0 deletions src/edgeworkers/ew-error.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import * as cliUtils from '../utils/cli-utils';
import {ErrorMessage} from '../utils/http-error-message';

export function handleError(err, commandId) {
Expand Down Expand Up @@ -59,4 +60,8 @@ export function handleError(err, commandId) {

}
}
}

export function invalidParameterError(commandId, errDetail=null) {
return handleError(cliUtils.toJsonPretty({status: 400, detail: errDetail}), commandId);
}
4 changes: 4 additions & 0 deletions src/edgeworkers/ew-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,10 @@ export function updateEdgeWorkerId(
name: string,
resourceTierId: string
) {
if(!cliUtils.isValidEwId(ewId)) {
return error.invalidParameterError('UPDATE_EW');
}

const body = { groupId: groupId, name: name };
if (resourceTierId != undefined && resourceTierId != null) {
body['resourceTierId'] = resourceTierId;
Expand Down
5 changes: 5 additions & 0 deletions src/utils/cli-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,3 +267,8 @@ export function sortObjectArray(
}
});
}

export function isValidEwId(edgeworkerId: string) {
const ewIdFormat = new RegExp('^[1-9][0-9]+');
return ewIdFormat.test(edgeworkerId);
}
17 changes: 17 additions & 0 deletions tests/utils/cli-utils.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import * as cliUtils from '../../src/utils/cli-utils';

describe('cli utils tests', () => {
describe('isValidEwId', () => {
it('should return true for valid ewId', () => {
expect(cliUtils.isValidEwId('123456')).toBe(true);
});

it('should return false for invalid ewId', () => {
expect(cliUtils.isValidEwId('wrongEwId')).toBe(false);
});

it('should return false for ewId starting with zero', () => {
expect(cliUtils.isValidEwId('0123456')).toBe(false);
});
});
});