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

EdgeKV support #29

Closed
wants to merge 12 commits into from
Closed
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": "0.5.3",
"version": "1.0.0",
"aliases": ["ew", "edgeworkers"],
"description": "Manage Akamai EdgeWorkers code bundles."
},
{
"name": "edgekv",
"version": "0.5.3",
"version": "1.0.0",
"aliases": ["ekv", "edgekv"],
"description": "Manage Akamai EdgeKV database."
}
Expand Down
24 changes: 24 additions & 0 deletions docs/edgekv_cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
* [ Delete Item](###delete-item)
* [ List Items](###list-items)
* [ Create an Access Token](###create-an-access-token)
* [ List Access Tokens](###list-access-tokens)
* [ Retrieve Access Token](###retrieve-access-token)
* [ Resources](##resources)
* [ Reporting Issues](##reporting-issues)

Expand Down Expand Up @@ -313,6 +315,28 @@ Example:
2. The token name can be between 1 and 32 characters in length.
3. The expiry date must be at least 1 day in the future and no more than 6 months from the current date.

### List Access Tokens

List of all tokens for which the user has permission to download.

Usage: `akamai edgekv list tokens`

| Option | Description |
| - | - |
| -h, --help | Display information on how to use this EdgeKV command |

### Retrieve Access Token

Retrieve an edgeKV access token

Usage:
`akamai edgekv create token <tokenName> --save_path=<path> --overwrite`

| Option | Existence | Description |
| - | - | - |
| --save_path | Optional | Path specifying where to save the edgekv_tokens.js token file. We recommend that you save the token file in the same location as the EdgeWorkers code bundle file (.tgz). The EdgeWorkers code bundle is then automatically updated every time this command updates the edgekv_tokens.js token file.If a path is not provided the token value is displayed. This token must be securely stored and manually added to the edgekv_tokens.js token file and EdgeWorkers code bundle. |
| -o, --overwrite | Optional | This option is used in conjunction with the --save_path option to overwrite the value of an existing token with the same name in the edgekv_tokens.js file. |
| -h, --help | Display information on how to use this EdgeKV command |
___
## Resources

Expand Down
7 changes: 6 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "akamai-edgeworkers-cli",
"version": "0.5.3",
"version": "1.0.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 All @@ -23,6 +23,7 @@
"console.table": "0.10.0",
"crypto-js": "^4.0.0",
"edgegrid": "^3.0.8",
"from-seconds": "^1.0.2",
"inquirer": "6.2.0",
"jwt-decode": "^3.1.2",
"sha256-file": "^1.0.0",
Expand Down
1 change: 1 addition & 0 deletions src/cli-httpRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export function sendEdgeRequest(pth: string, method: string, body, headers) {
try {
var errorObj = JSON.parse(body);
errorObj["status"] = response.statusCode;
errorObj["traceId"] = response.headers["x-trace-id"]; // adding trace id for debugging purpose
reject(cliUtils.toJsonPretty(errorObj));
} catch (ex) {
console.error(`got error code: ${response.statusCode} calling ${method} ${path}\n${body}`);
Expand Down
33 changes: 33 additions & 0 deletions src/edgekv/ekv-cli-main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,20 @@ list
cliUtils.logAndExit(0, copywrite);
});

list
.command("tokens")
.description("List all tokens for which the user has permission to download.")
.action(async function () {
try {
await kvCliHandler.listTokens();
} catch (e) {
cliUtils.logAndExit(1, e);
}
})
.on("--help", function () {
cliUtils.logAndExit(0, copywrite);
});

const create = program.command('create')
.description("Creates a namespace or creates a token")
.on("--help", function () {
Expand Down Expand Up @@ -206,6 +220,25 @@ create
cliUtils.logAndExit(0, copywrite);
});

const download = program.command('download')
.alias("dnld")
.description("Download an edgekv token");

download
.command("token <tokenName>")
.description("Download an edgekv token")
.option('--save_path <save_path>', 'The path of the bundle where the token will be saved')
.option("-o, --overwrite", "EdgeKV token placed inside the bundle will be overwritten")
.action(async function (tokenName, options) {
try {
await kvCliHandler.retrieveToken(tokenName, options);
} catch (e) {
cliUtils.logAndExit(1, e);
}
})
.on("--help", function () {
cliUtils.logAndExit(0, copywrite);
});

const show = program.command('show')
.description("Check the initialization status of the EdgeKV or Retrieve an EdgeKV namespace. Use show -h to see available options")
Expand Down
16 changes: 11 additions & 5 deletions src/edgekv/ekv-error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,22 @@ export function handleError(err) {
} catch (e) {
return {
isError: true,
error_reason: ""
error_reason: "",
traceId: "-"
}
}

let statusCode = err["status"] == undefined ? "" : err["status"];
let traceIdVal = err["traceId"] == undefined ? "" : err["traceId"];
// this is sent by edgeKV
if (err.hasOwnProperty("errors")) {
let errors = err["errors"];
if (errors.length > 0) {
return {
isError: true,
error_reason: errors[0]["detail"],
status: statusCode
status: statusCode,
traceId: traceIdVal
}
}
}
Expand All @@ -31,13 +34,15 @@ export function handleError(err) {
return {
isError: true,
error_reason: additionalDetail["detail"],
status: statusCode
status: statusCode,
traceId: traceIdVal
}
} else {
return {
isError: true,
error_reason: "",
status: statusCode
status: statusCode,
traceId: traceIdVal
}
}
}
Expand All @@ -46,7 +51,8 @@ export function handleError(err) {
return {
isError: true,
error_reason: errDetail,
status: statusCode
status: statusCode,
traceId: traceIdVal
}
}
}
Loading