Edits history of script submission #15873 for ' Release Lease (fly)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Fly = {
      token: string;
    };
    /**
     * Release Lease
     * Release the lease of a specific Machine within an app. Machine leases can be used to obtain an exclusive lock on modifying a Machine.
    
     */
    export async function main(
      auth: Fly,
      app_name: string,
      machine_id: string,
      fly_machine_lease_nonce: string,
    ) {
      const url = new URL(
        `https://api.machines.dev/v1/apps/${app_name}/machines/${machine_id}/lease`,
      );
    
      const response = await fetch(url, {
        method: "DELETE",
        headers: {
          "fly-machine-lease-nonce": fly_machine_lease_nonce,
          Authorization: "Bearer " + auth.token,
        },
        body: undefined,
      });
      if (!response.ok) {
        const text = await response.text();
        throw new Error(`${response.status} ${text}`);
      }
      return await response.text();
    }
    

    Submitted by hugo697 235 days ago