From 985748b05d51b301c91590fc795d8126494d6a3c Mon Sep 17 00:00:00 2001 From: Mustafa Gezen Date: Fri, 10 Sep 2021 20:14:33 +0200 Subject: [PATCH] enhancement: add http basic auth option --- pkg/data/process.go | 4 ++-- pkg/srpmproc/process.go | 17 ++++++++++++++--- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/pkg/data/process.go b/pkg/data/process.go index 6a2d797..36d8707 100644 --- a/pkg/data/process.go +++ b/pkg/data/process.go @@ -22,7 +22,7 @@ package data import ( "github.com/go-git/go-billy/v5" - "github.com/go-git/go-git/v5/plumbing/transport/ssh" + "github.com/go-git/go-git/v5/plumbing/transport" "github.com/rocky-linux/srpmproc/pkg/blob" ) @@ -41,7 +41,7 @@ type ProcessData struct { ImportBranchPrefix string BranchPrefix string SingleTag string - Authenticator *ssh.PublicKeys + Authenticator transport.AuthMethod Importer ImportMode BlobStorage blob.Storage NoDupMode bool diff --git a/pkg/srpmproc/process.go b/pkg/srpmproc/process.go index 3f71c41..e5ed817 100644 --- a/pkg/srpmproc/process.go +++ b/pkg/srpmproc/process.go @@ -24,6 +24,8 @@ import ( "encoding/hex" "fmt" "github.com/go-git/go-billy/v5" + "github.com/go-git/go-git/v5/plumbing/transport" + "github.com/go-git/go-git/v5/plumbing/transport/http" "github.com/go-git/go-git/v5/plumbing/transport/ssh" srpmprocpb "github.com/rocky-linux/srpmproc/pb" "github.com/rocky-linux/srpmproc/pkg/blob" @@ -70,6 +72,8 @@ type ProcessDataRequest struct { RpmPrefix string SshKeyLocation string SshUser string + HttpUsername string + HttpPassword string ManualCommits string UpstreamPrefix string GitCommitterName string @@ -166,11 +170,18 @@ func NewProcessData(req *ProcessDataRequest) (*data.ProcessData, error) { lastKeyLocation = filepath.Join(usr.HomeDir, ".ssh/id_rsa") } - var authenticator *ssh.PublicKeys + var authenticator transport.AuthMethod var err error - // create ssh key authenticator - authenticator, err = ssh.NewPublicKeysFromFile(req.SshUser, lastKeyLocation, "") + if req.HttpUsername != "" { + authenticator = &http.BasicAuth{ + Username: req.HttpUsername, + Password: req.HttpPassword, + } + } else { + // create ssh key authenticator + authenticator, err = ssh.NewPublicKeysFromFile(req.SshUser, lastKeyLocation, "") + } if err != nil { log.Fatalf("could not get git authenticator: %v", err) }