1 | |
2 | type Clickhouse = { |
3 | username: string; |
4 | password: string; |
5 | host: string; |
6 | }; |
7 | |
8 | * Update service state |
9 | * Starts or stop service |
10 | */ |
11 | export async function main( |
12 | auth: Clickhouse, |
13 | organizationId: string, |
14 | serviceId: string, |
15 | body: { command?: "start" | "stop" } |
16 | ) { |
17 | const url = new URL( |
18 | `https://api.clickhouse.cloud/v1/organizations/${organizationId}/services/${serviceId}/state` |
19 | ); |
20 |
|
21 | const response = await fetch(url, { |
22 | method: "PATCH", |
23 | headers: { |
24 | "Content-Type": "application/json", |
25 | Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`), |
26 | }, |
27 | body: JSON.stringify(body), |
28 | }); |
29 | if (!response.ok) { |
30 | const text = await response.text(); |
31 | throw new Error(`${response.status} ${text}`); |
32 | } |
33 | return await response.json(); |
34 | } |
35 |
|