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/delete-api-key.ts
Views: 687
/*1Delete the api key of the given compute server, if one is set.2*/34import getAccountId from "lib/account/get-account";5import { getServer } from "@cocalc/server/compute/get-servers";6import getParams from "lib/api/get-params";7import { deleteProjectApiKey } from "@cocalc/server/compute/project-api-key";89import { apiRoute, apiRouteOperation } from "lib/api";10import { OkStatus } from "lib/api/status";11import {12DeleteComputeServerAPIKeyInputSchema,13DeleteComputeServerAPIKeyOutputSchema,14} from "lib/api/schema/compute/delete-api-key";1516async function handle(req, res) {17try {18res.json(await get(req));19} catch (err) {20res.json({ error: `${err.message}` });21return;22}23}2425async function get(req) {26const account_id = await getAccountId(req);27if (!account_id) {28throw Error("must be signed in");29}30const { id } = getParams(req); // security: definitely needs to be a POST request31const server = await getServer({ id, account_id });32if (server.account_id != account_id) {33throw Error("you must be the owner of the compute server");34}35await deleteProjectApiKey({ account_id, server });36return OkStatus;37}3839export default apiRoute({40deleteServerAPIKey: apiRouteOperation({41method: "POST",42openApiOperation: {43tags: ["Compute"],44},45})46.input({47contentType: "application/json",48body: DeleteComputeServerAPIKeyInputSchema,49})50.outputs([51{52status: 200,53contentType: "application/json",54body: DeleteComputeServerAPIKeyOutputSchema,55},56])57.handler(handle),58});596061