Edits history of script submission #14899 for ' List audit logs (cockroachdb)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Cockroachdb = {
      token: string;
    };
    /**
     * List audit logs
     * Can be used by the following roles assigned at the organization scope:
    - ORG_ADMIN
    
     */
    export async function main(
      auth: Cockroachdb,
      starting_from: string | undefined,
      sort_order: "ASC" | "DESC" | undefined,
      limit: string | undefined,
    ) {
      const url = new URL(`https://cockroachlabs.cloud/api/v1/auditlogevents`);
      for (const [k, v] of [
        ["starting_from", starting_from],
        ["sort_order", sort_order],
        ["limit", limit],
      ]) {
        if (v !== undefined && v !== "" && k !== undefined) {
          url.searchParams.append(k, v);
        }
      }
      const response = await fetch(url, {
        method: "GET",
        headers: {
          Authorization: "Bearer " + auth.token,
        },
        body: undefined,
      });
      if (!response.ok) {
        const text = await response.text();
        throw new Error(`${response.status} ${text}`);
      }
      return await response.json();
    }
    

    Submitted by hugo697 235 days ago