list audit logs (requires admin privilege)

Script windmill Verified

by admin ยท 8/13/2023

The script

Submitted by admin Typescript (fetch-only)
Verified 370 days ago
1
/**
2
 * list audit logs (requires admin privilege)
3
 *
4
 */
5
export async function main(
6
  workspace: string,
7
  page: string | undefined,
8
  per_page: string | undefined,
9
  before: string | undefined,
10
  after: string | undefined,
11
  username: string | undefined,
12
  operation: string | undefined,
13
  resource: string | undefined,
14
  action_kind: "Create" | "Update" | "Delete" | "Execute" | undefined
15
) {
16
  const url = new URL(`${BASE_URL}/api/w/${workspace}/audit/list`);
17
  for (const [k, v] of [
18
    ["page", page],
19
    ["per_page", per_page],
20
    ["before", before],
21
    ["after", after],
22
    ["username", username],
23
    ["operation", operation],
24
    ["resource", resource],
25
    ["action_kind", action_kind],
26
  ]) {
27
    if (v !== undefined && v !== "") {
28
      url.searchParams.append(k, v);
29
    }
30
  }
31
  const response = await fetch(url, {
32
    method: "GET",
33
    headers: {
34
      Authorization: "Bearer " + WM_TOKEN,
35
    },
36
    body: undefined,
37
  });
38
  if (!response.ok) {
39
    const text = await response.text();
40
    throw new Error(`${response.status} ${text}`);
41
  }
42
  return await response.json();
43
}
44