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/check-in.ts
Views: 687
1
/*
2
Compute server periodically checking in with cocalc using a project api key.
3
4
Example use, where 'sk-eTUKbl2lkP9TgvFJ00001n' is a project api key.
5
6
curl -sk -u sk-eTUKbl2lkP9TgvFJ00001n: -d '{"id":"13","vpn_sha1":"fbdad59e0793e11ffa464834c647db93d1f9ec99","cloud_filesystem_sha1":"97d170e1550eee4afc0af065b78cda302a97674c"}' -H 'Content-Type: application/json' https://cocalc.com/api/v2/compute/check-in
7
8
Calling this endpoint:
9
10
- sets detailed state saying the vm is ready
11
- optionally returns vpn and/or cloud file system config, if input vpn_sha1 or cloud_filesystem_sha1 doesn't match
12
current value.
13
14
If compute server gets back vpn_sha1 or cloud_filesystem_sha1, it should update its local
15
configuration accordingly.
16
*/
17
18
import getProjectOrAccountId from "lib/account/get-account";
19
import getParams from "lib/api/get-params";
20
import { checkIn } from "@cocalc/server/compute/check-in";
21
22
import { apiRoute, apiRouteOperation } from "lib/api";
23
import {
24
ComputeServerCheckInInputSchema,
25
ComputeServerCheckInOutputSchema,
26
} from "lib/api/schema/compute/check-in";
27
28
29
async function handle(req, res) {
30
try {
31
res.json(await get(req));
32
} catch (err) {
33
res.json({ error: `${err.message}` });
34
return;
35
}
36
}
37
38
async function get(req) {
39
const project_id = await getProjectOrAccountId(req);
40
if (!project_id) {
41
throw Error("invalid auth");
42
}
43
const { id, vpn_sha1, cloud_filesystem_sha1 } = getParams(req);
44
45
return await checkIn({
46
project_id,
47
id,
48
vpn_sha1,
49
cloud_filesystem_sha1,
50
});
51
}
52
53
export default apiRoute({
54
checkIn: apiRouteOperation({
55
method: "POST",
56
openApiOperation: {
57
tags: ["Compute"]
58
},
59
})
60
.input({
61
contentType: "application/json",
62
body: ComputeServerCheckInInputSchema,
63
})
64
.outputs([
65
{
66
status: 200,
67
contentType: "application/json",
68
body: ComputeServerCheckInOutputSchema,
69
},
70
])
71
.handler(handle),
72
});
73
74