Edits history of script submission #14909 for ' List service accounts for an organization (cockroachdb)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Cockroachdb = {
      token: string;
    };
    /**
     * List service accounts for an organization
     * Sort order: Service account name
    
    Can be used by the following roles assigned at the organization scope:
    - ORG_ADMIN
    - CLUSTER_ADMIN
    
     */
    export async function main(
      auth: Cockroachdb,
      pagination_page: string | undefined,
      pagination_limit: string | undefined,
      pagination_as_of_time: string | undefined,
      pagination_sort_order: "ASC" | "DESC" | undefined,
    ) {
      const url = new URL(`https://cockroachlabs.cloud/api/v1/service-accounts`);
      for (const [k, v] of [
        ["pagination.page", pagination_page],
        ["pagination.limit", pagination_limit],
        ["pagination.as_of_time", pagination_as_of_time],
        ["pagination.sort_order", pagination_sort_order],
      ]) {
        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