Skip to content

Commit

Permalink
enhancement: add http basic auth option
Browse files Browse the repository at this point in the history
mstg committed Sep 10, 2021
1 parent 42c043f commit 985748b
Showing 2 changed files with 16 additions and 5 deletions.
4 changes: 2 additions & 2 deletions pkg/data/process.go
Original file line number Diff line number Diff line change
@@ -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
17 changes: 14 additions & 3 deletions pkg/srpmproc/process.go
Original file line number Diff line number Diff line change
@@ -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)
}

0 comments on commit 985748b

Please sign in to comment.