mirror of
https://github.com/coder/coder.git
synced 2025-07-03 16:13:58 +00:00
* Refactor parameter parsing to return nil values if none computed * Refactor parameter to allow for hiding redisplay * Refactor parameters to enable schema matching * Refactor provisionerd to dynamically update parameter schemas * Refactor job update for provisionerd * Handle multiple states correctly when provisioning a project * Add project import job resource table * Basic creation flow works! * Create project fully works!!! * Only show job status if completed * Add create workspace support * Replace Netflix/go-expect with ActiveState * Fix linting errors * Use forked chzyer/readline * Add create workspace CLI * Add CLI test * Move jobs to their own APIs * Remove go-expect * Fix requested changes * Skip workspacecreate test on windows
29 lines
736 B
Go
29 lines
736 B
Go
package codersdk
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"net/http"
|
|
|
|
"github.com/coder/coder/coderd"
|
|
)
|
|
|
|
const (
|
|
ContentTypeTar = "application/x-tar"
|
|
)
|
|
|
|
func (c *Client) UploadFile(ctx context.Context, contentType string, content []byte) (coderd.UploadFileResponse, error) {
|
|
res, err := c.request(ctx, http.MethodPost, "/api/v2/files", content, func(r *http.Request) {
|
|
r.Header.Set("Content-Type", contentType)
|
|
})
|
|
if err != nil {
|
|
return coderd.UploadFileResponse{}, err
|
|
}
|
|
defer res.Body.Close()
|
|
if res.StatusCode != http.StatusCreated && res.StatusCode != http.StatusOK {
|
|
return coderd.UploadFileResponse{}, readBodyAsError(res)
|
|
}
|
|
var resp coderd.UploadFileResponse
|
|
return resp, json.NewDecoder(res.Body).Decode(&resp)
|
|
}
|