1 | |
2 | type Digitalocean = { |
3 | token: string; |
4 | }; |
5 | |
6 | * Update a Firewall |
7 | * To update the configuration of an existing firewall, send a PUT request to |
8 | `/v2/firewalls/$FIREWALL_ID`. The request should contain a full representation |
9 | of the firewall including existing attributes. **Note that any attributes that |
10 | are not provided will be reset to their default values.** |
11 |
|
12 | */ |
13 | export async function main( |
14 | auth: Digitalocean, |
15 | firewall_id: string, |
16 | body: |
17 | | ({ |
18 | id?: string; |
19 | status?: "waiting" | "succeeded" | "failed"; |
20 | created_at?: string; |
21 | pending_changes?: { |
22 | droplet_id?: number; |
23 | removing?: false | true; |
24 | status?: string; |
25 | }[]; |
26 | name?: string; |
27 | droplet_ids?: number[]; |
28 | tags?: string[] & {}; |
29 | } & { |
30 | inbound_rules?: { protocol: "tcp" | "udp" | "icmp"; ports: string } & { |
31 | sources: { |
32 | addresses?: string[]; |
33 | droplet_ids?: number[]; |
34 | load_balancer_uids?: string[]; |
35 | kubernetes_ids?: string[]; |
36 | tags?: string[] & {}; |
37 | } & {}; |
38 | }[]; |
39 | outbound_rules?: { protocol: "tcp" | "udp" | "icmp"; ports: string } & { |
40 | destinations: { |
41 | addresses?: string[]; |
42 | droplet_ids?: number[]; |
43 | load_balancer_uids?: string[]; |
44 | kubernetes_ids?: string[]; |
45 | tags?: string[] & {}; |
46 | } & {}; |
47 | }[]; |
48 | } & {}) |
49 | | ({ |
50 | id?: string; |
51 | status?: "waiting" | "succeeded" | "failed"; |
52 | created_at?: string; |
53 | pending_changes?: { |
54 | droplet_id?: number; |
55 | removing?: false | true; |
56 | status?: string; |
57 | }[]; |
58 | name?: string; |
59 | droplet_ids?: number[]; |
60 | tags?: string[] & {}; |
61 | } & { |
62 | inbound_rules?: { protocol: "tcp" | "udp" | "icmp"; ports: string } & { |
63 | sources: { |
64 | addresses?: string[]; |
65 | droplet_ids?: number[]; |
66 | load_balancer_uids?: string[]; |
67 | kubernetes_ids?: string[]; |
68 | tags?: string[] & {}; |
69 | } & {}; |
70 | }[]; |
71 | outbound_rules?: { protocol: "tcp" | "udp" | "icmp"; ports: string } & { |
72 | destinations: { |
73 | addresses?: string[]; |
74 | droplet_ids?: number[]; |
75 | load_balancer_uids?: string[]; |
76 | kubernetes_ids?: string[]; |
77 | tags?: string[] & {}; |
78 | } & {}; |
79 | }[]; |
80 | } & {}), |
81 | ) { |
82 | const url = new URL( |
83 | `https://api.digitalocean.com/v2/firewalls/${firewall_id}`, |
84 | ); |
85 |
|
86 | const response = await fetch(url, { |
87 | method: "PUT", |
88 | headers: { |
89 | "Content-Type": "application/json", |
90 | Authorization: "Bearer " + auth.token, |
91 | }, |
92 | body: JSON.stringify(body), |
93 | }); |
94 | if (!response.ok) { |
95 | const text = await response.text(); |
96 | throw new Error(`${response.status} ${text}`); |
97 | } |
98 | return await response.json(); |
99 | } |
100 |
|