mirror of
https://github.com/coder/coder.git
synced 2026-06-03 04:58:23 +00:00
9edceef0bf
This pull request introduces support for external workspace management, allowing users to register and manage workspaces that are provisioned and managed outside of the Coder. Depends on: https://github.com/coder/terraform-provider-coder/pull/424 * GET /api/v2/init-script - Gets the agent initialization script * By default, it returns a script for Linux (amd64), but with query parameters (os and arch) you can get the init script for different platforms * GET /api/v2/workspaces/{workspace}/external-agent/{agent}/credentials - Gets credentials for an external agent **(enterprise)** * Updated queries to filter workspaces/templates by the has_external_agent field
29 lines
506 B
Go
29 lines
506 B
Go
package codersdk
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"io"
|
|
"net/http"
|
|
)
|
|
|
|
func (c *Client) InitScript(ctx context.Context, os, arch string) (string, error) {
|
|
url := fmt.Sprintf("/api/v2/init-script/%s/%s", os, arch)
|
|
res, err := c.Request(ctx, http.MethodGet, url, nil)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
defer res.Body.Close()
|
|
|
|
if res.StatusCode != http.StatusOK {
|
|
return "", ReadBodyAsError(res)
|
|
}
|
|
|
|
script, err := io.ReadAll(res.Body)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
return string(script), nil
|
|
}
|