cmd: add a osbuild-upload-pulp-ostree utility

Simple command line wrapper around the UploadAndDistributeCommit()
function.
This commit is contained in:
Achilleas Koutsou 2023-08-17 15:05:26 +02:00
parent 3b8e595351
commit fd0cae4366

View file

@ -0,0 +1,44 @@
package main
import (
"encoding/json"
"flag"
"fmt"
"io"
"os"
"github.com/osbuild/osbuild-composer/internal/upload/pulp"
)
func check(err error) {
if err != nil {
fmt.Fprintln(os.Stderr, err.Error())
os.Exit(1)
}
}
func readCredentials(credPath string) *pulp.Credentials {
fp, err := os.Open(credPath)
check(err)
data, err := io.ReadAll(fp)
check(err)
var creds pulp.Credentials
check(json.Unmarshal(data, &creds))
return &creds
}
func main() {
var filename, apiURL, repository, basePath, credsFile string
flag.StringVar(&filename, "archive", "", "ostree archive to upload")
flag.StringVar(&apiURL, "url", "", "server URL")
flag.StringVar(&repository, "repository", "", "repository name")
flag.StringVar(&basePath, "base-path", "", "base path for distribution (if the repository does not already exist)")
flag.StringVar(&credsFile, "credentials", "", `file containing credentials (format: {"username": "...", "password": "..."})`)
flag.Parse()
client := pulp.NewClient(apiURL, readCredentials(credsFile))
repoURL, err := client.UploadAndDistributeCommit(filename, repository, basePath)
check(err)
fmt.Printf("The commit will be available in the repository at %s\n", repoURL)
}