Skip to content

Commit

Permalink
Merge pull request #63 from gchq/release/0.0.10
Browse files Browse the repository at this point in the history
Release/0.0.10
  • Loading branch information
GCHQDeveloper1138 committed Aug 1, 2024
2 parents 6073a08 + a53b04b commit 1142e60
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 16 deletions.
2 changes: 2 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import helmet from "helmet";

import bakeRouter from "./routes/bake";
import magicRouter from "./routes/magic";
import healthRouter from "./routes/health.js";

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

// Routes
app.use("/health", healthRouter);
app.use("/bake", bakeRouter);
app.use("/magic", magicRouter);

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": "cyberchef-server",
"version": "0.0.9",
"version": "0.0.10",
"description": "An application providing API access to CyberChef",
"author": "d98762625 <d98762625@gmail.com>",
"license": "Apache-2.0",
Expand Down
21 changes: 21 additions & 0 deletions routes/health.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { Router } from "express";
const router = Router();

/**
* bakePost
*/
router.get("/", async function healthGet(req, res, next) {
const healthcheck = {
uptime: process.uptime(),
message: "OK",
timestamp: Date()
};
try {
res.send(healthcheck);
} catch (error) {
healthcheck.message = error;
res.status(503).send();
}
});

export default router;
74 changes: 61 additions & 13 deletions swagger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,38 @@ openapi: 3.0.0
info:
title: CyberChef API
description: A HTTP API that exposes some of CyberChef's functionality.
version: 0.0.9
version: 0.0.10


paths:
/health:
get:
summary: Server healthcheck
description: >
If the server is up, returns a 200 response and some basic info about uptime
responses:
'200':
description: Server is alive and healthy
content:
application/json:
schema:
$ref: "#/components/schemas/HealthResponse"
example:
uptime: 1138.00
message: "OK"
timestamp: "Thu Dec 17 2017 19:23:54 GMT+0000"

'503':
description: Server error
content:
application/json:
schema:
$ref: "#/components/schemas/HealthResponse"
example:
uptime: 1138.00
message: "Internal Server Error: Not enough biscuits"
timestamp: "Thu Dec 19 2019 19:23:54 GMT+0000"
/bake:
post:
summary: Bakes a recipe
Expand Down Expand Up @@ -40,8 +68,7 @@ paths:
content:
application/json:
schema:
type: "string"
value: "Object"
$ref: "#/components/schemas/BakeResponse"
example:
type: "string"
value: "01001110,01111010,01001101,01100111,01001110,01101101,01011001,01100111,01001110,01101101,01010001,01100111,01001110,01101010,01010101,01100111,01001101,01101010,01000001,01100111,01001110,01101010,01101011,01100111,01001110,01101101,01010101,01100111,01001110,01111010,01000001,01100111,01001110,01111010,01010101,01100111,01001110,01111010,01010001,00111101"
Expand Down Expand Up @@ -71,9 +98,7 @@ paths:
content:
application/json:
schema:
type: "string"
value:
$ref: "#/components/schemas/MagicResponse"
$ref: "#/components/schemas/MagicResponse"
example:
type: 6
value:
Expand Down Expand Up @@ -127,11 +152,12 @@ components:
properties:
op:
type: string
required: true
args:
oneOf:
- $ref: "#/components/schemas/ArgArray"
- $ref: "#/components/schemas/ArgObject"
required:
- op

OperationArray:
type: array
Expand All @@ -141,7 +167,7 @@ components:
ArgArray:
type: array
items:
type: {}
type: object
example:
- 16
- true
Expand All @@ -154,6 +180,16 @@ components:
upperCaseHex: true
includeFinalLength: false

BakeResponse:
type: object
properties:
type:
type: string
value:
oneOf:
- type: string
- type: number

MagicInput:
type: object
properties:
Expand All @@ -166,7 +202,7 @@ components:
type: object
properties:
type:
type: int
type: integer
value:
type: array
items:
Expand All @@ -177,16 +213,28 @@ components:
recipe:
type: array
items:
type: Object
type: object
data:
type: string
languageScores:
type: array
items:
type: Object
type: object
matchingOps:
type: array
items:
type: Object
useful: bool
type: object
useful:
type: boolean

HealthResponse:
type: object
properties:
uptime:
type: number
message:
type: string
timestamp:
type: string


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

describe("GET /health", function() {
it("should respond with a success response", function(done) {
request(app)
.get("/health")
.set("Accept", "application/json")
.expect(200, done);
});
});

0 comments on commit 1142e60

Please sign in to comment.