upload: define new pulp uploader

Define a basic client struct to pull in the pulp-client library.
This commit is contained in:
Achilleas Koutsou 2023-08-16 15:38:53 +02:00
parent 6663e69872
commit bc6c2fb6af
682 changed files with 308758 additions and 0 deletions

View file

@ -0,0 +1,43 @@
package pulp
import (
"context"
"net/http"
"github.com/osbuild/pulp-client/pulpclient"
)
type Client struct {
client *pulpclient.APIClient
ctx context.Context
}
type Credentials struct {
Username string
Password string
}
func NewClient(url string, creds *Credentials) *Client {
ctx := context.WithValue(context.Background(), pulpclient.ContextServerIndex, 0)
transport := &http.Transport{}
httpClient := http.Client{Transport: transport}
pulpConfig := pulpclient.NewConfiguration()
pulpConfig.HTTPClient = &httpClient
pulpConfig.Servers = pulpclient.ServerConfigurations{pulpclient.ServerConfiguration{
URL: url,
}}
client := pulpclient.NewAPIClient(pulpConfig)
if creds != nil {
ctx = context.WithValue(ctx, pulpclient.ContextBasicAuth, pulpclient.BasicAuth{
UserName: creds.Username,
Password: creds.Password,
})
}
return &Client{
client: client,
ctx: ctx,
}
}