1 |
|
2 | * get variable |
3 | * |
4 | */ |
5 | export async function main( |
6 | workspace: string, |
7 | path: string, |
8 | decrypt_secret: string | undefined, |
9 | include_encrypted: string | undefined |
10 | ) { |
11 | const url = new URL(`${BASE_URL}/api/w/${workspace}/variables/get/${path}`); |
12 | for (const [k, v] of [ |
13 | ["decrypt_secret", decrypt_secret], |
14 | ["include_encrypted", include_encrypted], |
15 | ]) { |
16 | if (v !== undefined && v !== "") { |
17 | url.searchParams.append(k, v); |
18 | } |
19 | } |
20 | const response = await fetch(url, { |
21 | method: "GET", |
22 | headers: { |
23 | Authorization: "Bearer " + WM_TOKEN, |
24 | }, |
25 | body: undefined, |
26 | }); |
27 | if (!response.ok) { |
28 | const text = await response.text(); |
29 | throw new Error(`${response.status} ${text}`); |
30 | } |
31 | return await response.json(); |
32 | } |
33 |
|