upload/koji: allow passing a custom transport to koji.Login

In the near future, we will need to communicate with Koji using HTTPS.
This will surely bring the need for ignoring bad certificates/providing
our own self-signed ones. Thus, this commit prepares the Koji integration
by adding a way to accept a custom http transport which can be used to
customize the TLS settings.
This commit is contained in:
Ondřej Budai 2020-08-19 14:57:07 +02:00 committed by Tom Gundersen
parent bc02da786d
commit ecc7340570
2 changed files with 10 additions and 5 deletions

View file

@ -106,9 +106,11 @@ type CGImportResult struct {
BuildID int `xmlrpc:"build_id"`
}
func Login(server, user, password string) (*Koji, error) {
// Create a temporary xmlrpc client with the default http transport
// as we don't need sessionID, key nor callnum yet.
func Login(server, user, password string, transport http.RoundTripper) (*Koji, error) {
// Create a temporary xmlrpc client.
// The API doesn't require sessionID, sessionKey and callnum yet,
// so there's no need to use the custom Koji RoundTripper,
// let's just use the one that the called passed in.
loginClient, err := xmlrpc.NewClient(server, http.DefaultTransport)
if err != nil {
return nil, err
@ -130,6 +132,7 @@ func Login(server, user, password string) (*Koji, error) {
sessionID: reply.SessionID,
sessionKey: reply.SessionKey,
callnum: 0,
transport: transport,
}
client, err := xmlrpc.NewClient(server, kojiTransport)
@ -277,6 +280,7 @@ type Transport struct {
sessionID int64
sessionKey string
callnum int
transport http.RoundTripper
}
// RoundTrip implements the RoundTripper interface, using the default
@ -303,5 +307,5 @@ func (rt *Transport) RoundTrip(req *http.Request) (*http.Response, error) {
// Each call is given a unique callnum.
rt.callnum++
return http.DefaultTransport.RoundTrip(rClone)
return rt.transport.RoundTrip(rClone)
}

View file

@ -6,6 +6,7 @@ import (
"crypto/rand"
"io"
"io/ioutil"
"net/http"
"os"
"os/exec"
"strconv"
@ -31,7 +32,7 @@ func TestKojiImport(t *testing.T) {
// koji needs to specify a directory to which the upload should happen, let's reuse the build name
uploadDirectory := buildName
k, err := koji.Login(server, user, password)
k, err := koji.Login(server, user, password, http.DefaultTransport)
require.NoError(t, err)
defer func() {