Edits history of script submission #17170 for ' Update a user's grants (linode)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Linode = {
      token: string;
    };
    /**
     * Update a user's grants
     * Update the grants a user has.
     */
    export async function main(
      auth: Linode,
      apiVersion: "v4" | "v4beta",
      username: string,
      body: {
        database?: {
          id?: number;
          label?: string;
          permissions?: "read_only" | "read_write";
        }[];
        domain?: {
          id?: number;
          label?: string;
          permissions?: "read_only" | "read_write";
        }[];
        firewall?: {
          id?: number;
          label?: string;
          permissions?: "read_only" | "read_write";
        }[];
        global?: {
          account_access?: "read_only" | "read_write";
          add_databases?: false | true;
          add_domains?: false | true;
          add_firewalls?: false | true;
          add_images?: false | true;
          add_linodes?: false | true;
          add_longview?: false | true;
          add_nodebalancers?: false | true;
          add_stackscripts?: false | true;
          add_volumes?: false | true;
          add_vpcs?: false | true;
          cancel_account?: false | true;
          child_account_access?: false | true;
          longview_subscription?: false | true;
        };
        image?: {
          id?: number;
          label?: string;
          permissions?: "read_only" | "read_write";
        }[];
        linode?: {
          id?: number;
          label?: string;
          permissions?: "read_only" | "read_write";
        }[];
        longview?: {
          id?: number;
          label?: string;
          permissions?: "read_only" | "read_write";
        }[];
        nodebalancer?: {
          id?: number;
          label?: string;
          permissions?: "read_only" | "read_write";
        }[];
        stackscript?: {
          id?: number;
          label?: string;
          permissions?: "read_only" | "read_write";
        }[];
        volume?: {
          id?: number;
          label?: string;
          permissions?: "read_only" | "read_write";
        }[];
        vpc?: {
          id?: number;
          label?: string;
          permissions?: "read_only" | "read_write";
        }[];
      },
    ) {
      const url = new URL(
        `https://api.linode.com/${apiVersion}/account/users/${username}/grants`,
      );
    
      const response = await fetch(url, {
        method: "PUT",
        headers: {
          "Content-Type": "application/json",
          Authorization: "Bearer " + auth.token,
        },
        body: JSON.stringify(body),
      });
      if (!response.ok) {
        const text = await response.text();
        throw new Error(`${response.status} ${text}`);
      }
      return await response.json();
    }
    

    Submitted by hugo697 235 days ago