1 | |
2 | type Linode = { |
3 | token: string; |
4 | }; |
5 | |
6 | * Update a StackScript |
7 | * Updates a StackScript. |
8 | */ |
9 | export async function main( |
10 | auth: Linode, |
11 | apiVersion: "v4" | "v4beta", |
12 | stackscriptId: string, |
13 | body: { |
14 | created?: string; |
15 | deployments_active?: number; |
16 | deployments_total?: number; |
17 | description?: string; |
18 | id?: number; |
19 | images?: string[]; |
20 | is_public?: false | true; |
21 | label?: string; |
22 | mine?: false | true; |
23 | rev_note?: string; |
24 | script?: string; |
25 | updated?: string; |
26 | user_defined_fields?: { |
27 | default?: string; |
28 | example: string; |
29 | label: string; |
30 | manyOf?: string; |
31 | name: string; |
32 | oneOf?: string; |
33 | }[]; |
34 | user_gravatar_id?: string; |
35 | username?: string; |
36 | }, |
37 | ) { |
38 | const url = new URL( |
39 | `https://api.linode.com/${apiVersion}/linode/stackscripts/${stackscriptId}`, |
40 | ); |
41 |
|
42 | const response = await fetch(url, { |
43 | method: "PUT", |
44 | headers: { |
45 | "Content-Type": "application/json", |
46 | Authorization: "Bearer " + auth.token, |
47 | }, |
48 | body: JSON.stringify(body), |
49 | }); |
50 | if (!response.ok) { |
51 | const text = await response.text(); |
52 | throw new Error(`${response.status} ${text}`); |
53 | } |
54 | return await response.json(); |
55 | } |
56 |
|