CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
sagemathinc

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/next/pages/api/v2/compute/set-image-tested.ts
Views: 687
1
/*
2
Set whether or not the image a compute server with given id is using has been tested.
3
This is used by admins when manually doing final integration testing for a new image
4
on some cloud provider.
5
*/
6
7
import getAccountId from "lib/account/get-account";
8
import { setImageTested } from "@cocalc/server/compute/control";
9
import getParams from "lib/api/get-params";
10
import userIsInGroup from "@cocalc/server/accounts/is-in-group";
11
12
import { apiRoute, apiRouteOperation } from "lib/api";
13
import { OkStatus } from "lib/api/status";
14
import {
15
SetComputeServerImageTestedInputSchema,
16
SetComputeServerImageTestedOutputSchema,
17
} from "lib/api/schema/compute/set-image-tested";
18
19
async function handle(req, res) {
20
try {
21
res.json(await get(req));
22
} catch (err) {
23
res.json({ error: `${err.message}` });
24
return;
25
}
26
}
27
28
async function get(req) {
29
const account_id = await getAccountId(req);
30
if (!account_id) {
31
throw Error("must be signed in");
32
}
33
if (!(await userIsInGroup(account_id, "admin"))) {
34
throw Error("only admin are allowed to image tested status");
35
}
36
const { id, tested } = getParams(req);
37
await setImageTested({ id, account_id, tested });
38
return OkStatus;
39
}
40
41
export default apiRoute({
42
setImageTested: apiRouteOperation({
43
method: "POST",
44
openApiOperation: {
45
tags: ["Compute"],
46
},
47
})
48
.input({
49
contentType: "application/json",
50
body: SetComputeServerImageTestedInputSchema,
51
})
52
.outputs([
53
{
54
status: 200,
55
contentType: "application/json",
56
body: SetComputeServerImageTestedOutputSchema,
57
},
58
])
59
.handler(handle),
60
});
61
62