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/set-template.ts
Views: 687
/*1Set a specific compute server template by id. This operation is designed for2administrators only.3*/45import getAccountId from "lib/account/get-account";6import { setTemplate } from "@cocalc/server/compute/templates";7import getParams from "lib/api/get-params";8import userIsInGroup from "@cocalc/server/accounts/is-in-group";910import { apiRoute, apiRouteOperation } from "lib/api";11import { OkStatus } from "lib/api/status";12import {13SetComputeServerTemplateInputSchema,14SetComputeServerTemplateOutputSchema,15} from "lib/api/schema/compute/set-template";1617async function handle(req, res) {18try {19res.json(await get(req));20} catch (err) {21res.json({ error: `${err.message}` });22return;23}24}2526async function get(req) {27const account_id = await getAccountId(req);28if (!account_id) {29throw Error("must be signed in");30}31if (!(await userIsInGroup(account_id, "admin"))) {32// admin only functionality for now.33throw Error(34"only admin are allowed to set compute server configuration templates",35);36}37const { id, template } = getParams(req);38await setTemplate({ account_id, id, template });39return OkStatus;40}4142export default apiRoute({43setTemplate: apiRouteOperation({44method: "POST",45openApiOperation: {46tags: ["Compute", "Admin"],47},48})49.input({50contentType: "application/json",51body: SetComputeServerTemplateInputSchema,52})53.outputs([54{55status: 200,56contentType: "application/json",57body: SetComputeServerTemplateOutputSchema,58},59])60.handler(handle),61});626364