Edits history of script submission #15883 for ' Update Machine (fly)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Fly = {
      token: string;
    };
    /**
     * Update Machine
     * Update a Machine's configuration using the details provided in the request body.
    
     */
    export async function main(
      auth: Fly,
      app_name: string,
      machine_id: string,
      body: {
        config?: {
          auto_destroy?: false | true;
          checks?: {};
          containers?: {
            cmd?: string[];
            depends_on?: {
              condition?: "exited_successfully" | "healthy" | "started";
              name?: string;
            }[];
            entrypoint?: string[];
            env?: {};
            env_from?: {
              env_var?: string;
              field_ref?:
                | "id"
                | "version"
                | "app_name"
                | "private_ip"
                | "region"
                | "image";
            }[];
            exec?: string[];
            files?: {
              guest_path?: string;
              image_config?: string;
              mode?: number;
              raw_value?: string;
              secret_name?: string;
            }[];
            healthchecks?: {
              exec?: { command?: string[] };
              failure_threshold?: number;
              grace_period?: number;
              http?: {
                headers?: { name?: string; values?: string[] }[];
                method?: string;
                path?: string;
                port?: number;
                scheme?: "http" | "https";
                tls_server_name?: string;
                tls_skip_verify?: false | true;
              };
              interval?: number;
              kind?: "readiness" | "liveness";
              name?: string;
              success_threshold?: number;
              tcp?: { port?: number };
              timeout?: number;
              unhealthy?: "stop";
            }[];
            image?: string;
            name?: string;
            restart?: {
              gpu_bid_price?: number;
              max_retries?: number;
              policy?: "no" | "always" | "on-failure" | "spot-price";
            };
            secrets?: { env_var?: string; name?: string }[];
            stop?: { signal?: string; timeout?: { "time.Duration"?: number } };
            user?: string;
          }[];
          disable_machine_autostart?: false | true;
          dns?: {
            dns_forward_rules?: { addr?: string; basename?: string }[];
            hostname?: string;
            hostname_fqdn?: string;
            nameservers?: string[];
            options?: { name?: string; value?: string }[];
            searches?: string[];
            skip_registration?: false | true;
          };
          env?: {};
          files?: {
            guest_path?: string;
            image_config?: string;
            mode?: number;
            raw_value?: string;
            secret_name?: string;
          }[];
          guest?: {
            cpu_kind?: string;
            cpus?: number;
            gpu_kind?: string;
            gpus?: number;
            host_dedication_id?: string;
            kernel_args?: string[];
            memory_mb?: number;
          };
          image?: string;
          init?: {
            cmd?: string[];
            entrypoint?: string[];
            exec?: string[];
            kernel_args?: string[];
            swap_size_mb?: number;
            tty?: false | true;
          };
          metadata?: {};
          metrics?: { https?: false | true; path?: string; port?: number };
          mounts?: {
            add_size_gb?: number;
            encrypted?: false | true;
            extend_threshold_percent?: number;
            name?: string;
            path?: string;
            size_gb?: number;
            size_gb_limit?: number;
            volume?: string;
          }[];
          processes?: {
            cmd?: string[];
            entrypoint?: string[];
            env?: {};
            env_from?: {
              env_var?: string;
              field_ref?:
                | "id"
                | "version"
                | "app_name"
                | "private_ip"
                | "region"
                | "image";
            }[];
            exec?: string[];
            ignore_app_secrets?: false | true;
            secrets?: { env_var?: string; name?: string }[];
            user?: string;
          }[];
          restart?: {
            gpu_bid_price?: number;
            max_retries?: number;
            policy?: "no" | "always" | "on-failure" | "spot-price";
          };
          schedule?: string;
          services?: {
            autostart?: false | true;
            autostop?: "stop" | "off" | "suspend";
            checks?: {
              grace_period?: { "time.Duration"?: number };
              headers?: { name?: string; values?: string[] }[];
              interval?: { "time.Duration"?: number };
              method?: string;
              path?: string;
              port?: number;
              protocol?: string;
              timeout?: { "time.Duration"?: number };
              tls_server_name?: string;
              tls_skip_verify?: false | true;
              type?: string;
            }[];
            concurrency?: {
              hard_limit?: number;
              soft_limit?: number;
              type?: string;
            };
            force_instance_description?: string;
            force_instance_key?: string;
            internal_port?: number;
            min_machines_running?: number;
            ports?: {
              end_port?: number;
              force_https?: false | true;
              handlers?: string[];
              http_options?: {
                compress?: false | true;
                h2_backend?: false | true;
                headers_read_timeout?: number;
                idle_timeout?: number;
                response?: { headers?: {}; pristine?: false | true };
              };
              port?: number;
              proxy_proto_options?: { version?: string };
              start_port?: number;
              tls_options?: {
                alpn?: string[];
                default_self_signed?: false | true;
                versions?: string[];
              };
            }[];
            protocol?: string;
          }[];
          size?: string;
          standbys?: string[];
          statics?: {
            guest_path: string;
            index_document?: string;
            tigris_bucket?: string;
            url_prefix: string;
          }[];
          stop_config?: { signal?: string; timeout?: { "time.Duration"?: number } };
        };
        current_version?: string;
        lease_ttl?: number;
        lsvd?: false | true;
        min_secrets_version?: number;
        name?: string;
        region?: string;
        skip_launch?: false | true;
        skip_secrets?: false | true;
        skip_service_registration?: false | true;
      },
    ) {
      const url = new URL(
        `https://api.machines.dev/v1/apps/${app_name}/machines/${machine_id}`,
      );
    
      const response = await fetch(url, {
        method: "POST",
        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