Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/src/packages/next/pages/api/v2/compute/check-in.ts
Views: 687
/*1Compute server periodically checking in with cocalc using a project api key.23Example use, where 'sk-eTUKbl2lkP9TgvFJ00001n' is a project api key.45curl -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-in67Calling this endpoint:89- sets detailed state saying the vm is ready10- optionally returns vpn and/or cloud file system config, if input vpn_sha1 or cloud_filesystem_sha1 doesn't match11current value.1213If compute server gets back vpn_sha1 or cloud_filesystem_sha1, it should update its local14configuration accordingly.15*/1617import getProjectOrAccountId from "lib/account/get-account";18import getParams from "lib/api/get-params";19import { checkIn } from "@cocalc/server/compute/check-in";2021import { apiRoute, apiRouteOperation } from "lib/api";22import {23ComputeServerCheckInInputSchema,24ComputeServerCheckInOutputSchema,25} from "lib/api/schema/compute/check-in";262728async function handle(req, res) {29try {30res.json(await get(req));31} catch (err) {32res.json({ error: `${err.message}` });33return;34}35}3637async function get(req) {38const project_id = await getProjectOrAccountId(req);39if (!project_id) {40throw Error("invalid auth");41}42const { id, vpn_sha1, cloud_filesystem_sha1 } = getParams(req);4344return await checkIn({45project_id,46id,47vpn_sha1,48cloud_filesystem_sha1,49});50}5152export default apiRoute({53checkIn: apiRouteOperation({54method: "POST",55openApiOperation: {56tags: ["Compute"]57},58})59.input({60contentType: "application/json",61body: ComputeServerCheckInInputSchema,62})63.outputs([64{65status: 200,66contentType: "application/json",67body: ComputeServerCheckInOutputSchema,68},69])70.handler(handle),71});727374