mirror of
https://github.com/coder/coder.git
synced 2025-06-28 04:33:02 +00:00
* ci: Update DataDog GitHub branch to fallback to GITHUB_REF This was detecting branches, but not our "main" branch before. Hopefully this fixes it! * Add basic Terraform Provider * Rename post files to upload * Add tests for resources * Skip instance identity test * Add tests for ensuring agent get's passed through properly * Fix linting errors * Add echo path * Fix agent authentication * fix: Convert all jobs to use a common resource and agent type This enables a consistent API for project import and provisioned resources.
29 lines
737 B
Go
29 lines
737 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/upload", 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)
|
|
}
|