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

Add /operations endpoint to list available operations #17

Closed
wants to merge 2 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
48 changes: 47 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ A Docker image can be built, then run by doing the following:
## API overview
> For full documentation of the API, you can find the swagger page hosted at the root url. See [Installing](#Installing) to run the application and browse the docs.

Currently the server just has one endpoint: `/bake`. This endpoint accepts a POST request with the following body:
The most important endpoint is `/bake`. This endpoint accepts a POST request with the following body:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you make this part of the README a list of endpoints with anchor tags to their respective parts of the documentation please?


|Parameter|Type|Description|
|---|---|---|
Expand Down Expand Up @@ -160,6 +160,52 @@ Response:
}
```

There is also a `/operations` endpoint. This endpoint accepts a GET request and responds with a JSON object listing the available operations on this server. Each operation name is one attribute, and its value is the description of the arguments it can take.

#### Example: operation list
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a section for /operations and put this example under it please

Response:
```javascript
{
"FromBase64" : {
"alphabet" : {
"type" : "editableOption",
"options" : [
{
"name" : "Standard (RFC 4648): A-Za-z0-9+/=",
"value" : "A-Za-z0-9+/="
},
{
"name" : "URL safe (RFC 4648 §5): A-Za-z0-9-_",
"value" : "A-Za-z0-9-_"
},
[...]
]
},
"removeNon-alphabetChars" : {
"type" : "boolean",
"value" : true
}
},
"ToBase64" : {
"alphabet" : {
"type" : "editableOption",
"options" : [
{
"name" : "Standard (RFC 4648): A-Za-z0-9+/=",
"value" : "A-Za-z0-9+/="
},
{
"name" : "URL safe (RFC 4648 §5): A-Za-z0-9-_",
"value" : "A-Za-z0-9-_"
},
[...]
]
}
},
[...]
}
```

## Licencing

CyberChef-server is released under the [Apache 2.0 Licence](https://www.apache.org/licenses/LICENSE-2.0) and is covered by [Crown Copyright](https://www.nationalarchives.gov.uk/information-management/re-using-public-sector-information/copyright-and-re-use/crown-copyright/).
2 changes: 2 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import errorHandler from "./lib/errorHandler.js";
import helmet from "helmet";

import bakeRouter from "./routes/bake";
import operationsRouter from "./routes/operations";

const app = express();
app.disable("x-powered-by");
Expand Down Expand Up @@ -37,6 +38,7 @@ const swaggerFile = fs.readFileSync("./swagger.yml", "utf8");

// Routes
app.use("/bake", bakeRouter);
app.use("/operations", operationsRouter);


// Default route
Expand Down
16 changes: 16 additions & 0 deletions routes/operations.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Router } from "express";
const router = Router();
import { operations } from "cyberchef/src/node/index.mjs";

/**
* operationsGet
*/
router.get("/", async (req, res, next) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a bit of a nit: please could you make this function a function rather than an arrow function, just for consistency please.

const ret = {};
for (const op of operations) {
if (op.opName) ret[op.opName] = op.args;
}
res.send(ret);
});

export default router;
58 changes: 57 additions & 1 deletion swagger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,62 @@ info:


paths:
/operations:
get:
summary: List available operations
description: >
Retrieve a list of all available operations on this server.
The return value is an object whose attributes are operation names,
and each attribute value is the description of the arguments
the argument takes.
responses:
'200':
description: OK
content:
application/json:
schema:
type: object
example: >
{
"FromBase64" : {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please can you define the example response in YAML rather than a string that looks like JSON please. there should be an example of this in swagger.yml now that the magic operation docs are included

"alphabet" : {
"type" : "editableOption",
"options" : [
{
"name" : "Standard (RFC 4648): A-Za-z0-9+/=",
"value" : "A-Za-z0-9+/="
},
{
"name" : "URL safe (RFC 4648 §5): A-Za-z0-9-_",
"value" : "A-Za-z0-9-_"
},
[...]
]
},
"removeNon-alphabetChars" : {
"type" : "boolean",
"value" : true
}
},
"ToBase64" : {
"alphabet" : {
"type" : "editableOption",
"options" : [
{
"name" : "Standard (RFC 4648): A-Za-z0-9+/=",
"value" : "A-Za-z0-9+/="
},
{
"name" : "URL safe (RFC 4648 §5): A-Za-z0-9-_",
"value" : "A-Za-z0-9-_"
},
[...]
]
}
},
[...]
}

/bake:
post:
summary: Bakes a recipe
Expand Down Expand Up @@ -99,4 +155,4 @@ components:
width: 16
upperCaseHex: true
includeFinalLength: false