From ecc73405709826f9d03fe8a2e7bac31b0795c7de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Budai?= Date: Wed, 19 Aug 2020 14:57:07 +0200 Subject: [PATCH] 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. --- internal/upload/koji/koji.go | 12 ++++++++---- internal/upload/koji/koji_test.go | 3 ++- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/internal/upload/koji/koji.go b/internal/upload/koji/koji.go index 7e5a833ce..57cd9a1c8 100644 --- a/internal/upload/koji/koji.go +++ b/internal/upload/koji/koji.go @@ -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) } diff --git a/internal/upload/koji/koji_test.go b/internal/upload/koji/koji_test.go index a5f2a033c..8427f3f07 100644 --- a/internal/upload/koji/koji_test.go +++ b/internal/upload/koji/koji_test.go @@ -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() {