cmd: add a osbuild-upload-pulp-ostree utility
Simple command line wrapper around the UploadAndDistributeCommit() function.
This commit is contained in:
parent
3b8e595351
commit
fd0cae4366
1 changed files with 44 additions and 0 deletions
44
cmd/osbuild-upload-pulp-ostree/main.go
Normal file
44
cmd/osbuild-upload-pulp-ostree/main.go
Normal 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)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue