1 | |
2 | type Linode = { |
3 | token: string; |
4 | }; |
5 | |
6 | * Rebuild a config |
7 | * Rebuilds a NodeBalancer Config and its Nodes that you have permission to modify. |
8 | */ |
9 | export async function main( |
10 | auth: Linode, |
11 | apiVersion: "v4" | "v4beta", |
12 | nodeBalancerId: string, |
13 | configId: string, |
14 | body: |
15 | | ({ |
16 | algorithm?: "roundrobin" | "leastconn" | "source"; |
17 | check?: "none" | "connection" | "http" | "http_body"; |
18 | check_attempts?: number; |
19 | check_body?: string; |
20 | check_interval?: number; |
21 | check_passive?: false | true; |
22 | check_path?: string; |
23 | check_timeout?: number; |
24 | cipher_suite?: string; |
25 | id?: number; |
26 | nodebalancer_id?: number; |
27 | nodes: { |
28 | address?: string; |
29 | config_id?: number; |
30 | id?: number; |
31 | label?: string; |
32 | mode?: "accept" | "reject" | "drain" | "backup"; |
33 | nodebalancer_id?: number; |
34 | status?: "unknown" | "UP" | "DOWN"; |
35 | weight?: number; |
36 | }[]; |
37 | nodes_status?: { down?: number; up?: number }; |
38 | port?: number; |
39 | protocol?: "tcp"; |
40 | proxy_protocol?: "none" | "v1" | "v2"; |
41 | ssl_cert?: string; |
42 | ssl_commonname?: string; |
43 | ssl_fingerprint?: string; |
44 | ssl_key?: string; |
45 | stickiness?: "none" | "table"; |
46 | } & { |
47 | nodes: { |
48 | address?: string; |
49 | id?: number; |
50 | label?: string; |
51 | mode?: "accept" | "reject" | "drain" | "backup"; |
52 | weight?: number; |
53 | }[]; |
54 | }) |
55 | | ({ |
56 | algorithm?: "roundrobin" | "leastconn" | "source"; |
57 | check?: "none" | "connection" | "http" | "http_body"; |
58 | check_attempts?: number; |
59 | check_body?: string; |
60 | check_interval?: number; |
61 | check_passive?: false | true; |
62 | check_path?: string; |
63 | check_timeout?: number; |
64 | cipher_suite?: string; |
65 | id?: number; |
66 | nodebalancer_id?: number; |
67 | nodes: { |
68 | address?: string; |
69 | config_id?: number; |
70 | id?: number; |
71 | label?: string; |
72 | mode?: "accept" | "reject" | "drain" | "backup"; |
73 | nodebalancer_id?: number; |
74 | status?: "unknown" | "UP" | "DOWN"; |
75 | weight?: number; |
76 | }[]; |
77 | nodes_status?: { down?: number; up?: number }; |
78 | port?: number; |
79 | protocol?: "http"; |
80 | proxy_protocol?: string; |
81 | ssl_cert?: string; |
82 | ssl_commonname?: string; |
83 | ssl_fingerprint?: string; |
84 | ssl_key?: string; |
85 | stickiness?: "none" | "table" | "http_cookie"; |
86 | } & { |
87 | nodes: { |
88 | address?: string; |
89 | id?: number; |
90 | label?: string; |
91 | mode?: "accept" | "reject" | "drain" | "backup"; |
92 | weight?: number; |
93 | }[]; |
94 | }) |
95 | | ({ |
96 | algorithm?: "roundrobin" | "leastconn" | "source"; |
97 | check?: "none" | "connection" | "http" | "http_body"; |
98 | check_attempts?: number; |
99 | check_body?: string; |
100 | check_interval?: number; |
101 | check_passive?: false | true; |
102 | check_path?: string; |
103 | check_timeout?: number; |
104 | cipher_suite?: "recommended" | "legacy"; |
105 | id?: number; |
106 | nodebalancer_id?: number; |
107 | nodes: { |
108 | address?: string; |
109 | config_id?: number; |
110 | id?: number; |
111 | label?: string; |
112 | mode?: "accept" | "reject" | "drain" | "backup"; |
113 | nodebalancer_id?: number; |
114 | status?: "unknown" | "UP" | "DOWN"; |
115 | weight?: number; |
116 | }[]; |
117 | nodes_status?: { down?: number; up?: number }; |
118 | port?: number; |
119 | protocol?: "https"; |
120 | proxy_protocol?: string; |
121 | ssl_cert?: string; |
122 | ssl_commonname?: string; |
123 | ssl_fingerprint?: string; |
124 | ssl_key?: string; |
125 | stickiness?: "none" | "table" | "http_cookie"; |
126 | } & { |
127 | nodes: { |
128 | address?: string; |
129 | id?: number; |
130 | label?: string; |
131 | mode?: "accept" | "reject" | "drain" | "backup"; |
132 | weight?: number; |
133 | }[]; |
134 | }), |
135 | ) { |
136 | const url = new URL( |
137 | `https://api.linode.com/${apiVersion}/nodebalancers/${nodeBalancerId}/configs/${configId}/rebuild`, |
138 | ); |
139 |
|
140 | const response = await fetch(url, { |
141 | method: "POST", |
142 | headers: { |
143 | "Content-Type": "application/json", |
144 | Authorization: "Bearer " + auth.token, |
145 | }, |
146 | body: JSON.stringify(body), |
147 | }); |
148 | if (!response.ok) { |
149 | const text = await response.text(); |
150 | throw new Error(`${response.status} ${text}`); |
151 | } |
152 | return await response.json(); |
153 | } |
154 |
|