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 v2 #22

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
54 changes: 53 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,11 @@ 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.

The server has two endpoints: `/bake` and `/magic`.
The server has these endpoints:

* [`/bake`](#user-content-bake)
* [`/magic`](#user-content-magic)
* [`/operations`](#user-content-operations)

### `/bake`

Expand Down Expand Up @@ -213,6 +217,54 @@ Response:
```


### `/operations`

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
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 @@ -11,6 +11,7 @@ import helmet from "helmet";

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

const app = express();
app.disable("x-powered-by");
Expand Down Expand Up @@ -39,6 +40,7 @@ const swaggerFile = fs.readFileSync("./swagger.yml", "utf8");
// Routes
app.use("/bake", bakeRouter);
app.use("/magic", magicRouter);
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 function (req, res, next) {
const ret = {};
for (const op of operations) {
if (op.opName) ret[op.opName] = op.args;
}
res.send(ret);
});

export default router;
37 changes: 36 additions & 1 deletion swagger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,42 @@ 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:
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 @@ -189,4 +225,3 @@ components:
items:
type: Object
useful: bool

23 changes: 23 additions & 0 deletions test/operations.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import assert from "assert";
import request from "supertest";
import app from "../app";

describe("GET /operations", function() {
it("exists", (done) => {
request(app)
.get("/operations")
.expect(200, done);
});

it("contains some operations", (done) => {
request(app)
.get("/operations")
.expect(200)
.end(function(err, res) {
if (err) return done(err);
assert.notStrictEqual(res.body.ToBraille, undefined);
assert.notStrictEqual(res.body.ToBase, undefined);
done();
});
});
});