upload/pulp: file upload method
This commit is contained in:
parent
1365347382
commit
4c002f3d54
1 changed files with 18 additions and 0 deletions
|
|
@ -5,6 +5,7 @@ import (
|
|||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"os"
|
||||
|
||||
"github.com/osbuild/pulp-client/pulpclient"
|
||||
)
|
||||
|
|
@ -57,6 +58,23 @@ func readBody(r *http.Response) string {
|
|||
return string(b)
|
||||
}
|
||||
|
||||
// UploadFile uploads the file at the given path and returns the href of the
|
||||
// new artifact.
|
||||
func (cl *Client) UploadFile(path string) (string, error) {
|
||||
fp, err := os.Open(path)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
defer fp.Close()
|
||||
create := cl.client.ArtifactsAPI.ArtifactsCreate(cl.ctx).File(fp)
|
||||
res, resp, err := create.Execute()
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("failed to upload file %q: %s (%s)", path, err.Error(), readBody(resp))
|
||||
}
|
||||
|
||||
return res.GetPulpHref(), nil
|
||||
}
|
||||
|
||||
// ListOSTreeRepositories returns a map (repository name -> pulp href) of
|
||||
// existing ostree repositories.
|
||||
func (cl *Client) ListOSTreeRepositories() (map[string]string, error) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue