Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Add support for insecure SVN repos #52

Merged
merged 4 commits into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,7 @@

# Dependency directories (remove the comment below to include it)
# vendor/

# IDE directories
.idea/

15 changes: 14 additions & 1 deletion repository/factory.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package repository

import (
"os"

hub "github.com/konveyor/tackle2-hub/addon"
"github.com/konveyor/tackle2-hub/api"
"os"
)

var (
Expand All @@ -17,21 +18,32 @@ func init() {

// New SCM repository factory.
func New(destDir string, remote *api.Repository, identities []api.Ref) (r SCM, err error) {
var insecure bool
switch remote.Kind {
case "subversion":
insecure, err = addon.Setting.Bool("svn.insecure.enabled")
if err != nil {
return
}
r = &Subversion{
Path: destDir,
Remote: Remote{
Repository: remote,
Identities: identities,
Insecure: insecure,
},
}
default:
insecure, err = addon.Setting.Bool("git.insecure.enabled")
if err != nil {
return
}
r = &Git{
Path: destDir,
Remote: Remote{
Repository: remote,
Identities: identities,
Insecure: insecure,
},
}
}
Expand All @@ -51,6 +63,7 @@ type SCM interface {
type Remote struct {
*api.Repository
Identities []api.Ref
Insecure bool
}

// FindIdentity by kind.
Expand Down
14 changes: 3 additions & 11 deletions repository/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,9 @@ func (r *Git) Validate() (err error) {
if err != nil {
return
}
insecure, err := addon.Setting.Bool("git.insecure.enabled")
if err != nil {
return
}
switch u.Scheme {
case "http":
if !insecure {
if !r.Insecure {
err = errors.New("http URL used with git.insecure.enabled = FALSE")
return
}
Expand Down Expand Up @@ -151,10 +147,7 @@ func (r *Git) writeConfig() (err error) {
path)
return
}
insecure, err := addon.Setting.Bool("git.insecure.enabled")
if err != nil {
return
}

proxy, err := r.proxy()
if err != nil {
return
Expand All @@ -165,7 +158,7 @@ func (r *Git) writeConfig() (err error) {
s += "[credential]\n"
s += "helper = store\n"
s += "[http]\n"
s += fmt.Sprintf("sslVerify = %t\n", !insecure)
s += fmt.Sprintf("sslVerify = %t\n", !r.Insecure)
if proxy != "" {
s += fmt.Sprintf("proxy = %s\n", proxy)
}
Expand All @@ -181,7 +174,6 @@ func (r *Git) writeConfig() (err error) {
return
}

//
// writeCreds writes credentials (store) file.
func (r *Git) writeCreds(id *api.Identity) (err error) {
if id.User == "" || id.Password == "" {
Expand Down
34 changes: 19 additions & 15 deletions repository/subversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@ package repository
import (
"errors"
"fmt"
liberr "github.com/jortel/go-utils/error"
"github.com/konveyor/tackle2-addon/command"
"github.com/konveyor/tackle2-addon/ssh"
"github.com/konveyor/tackle2-hub/api"
"github.com/konveyor/tackle2-hub/nas"
"io"
urllib "net/url"
"os"
pathlib "path"
"strings"

liberr "github.com/jortel/go-utils/error"
"github.com/konveyor/tackle2-addon/command"
"github.com/konveyor/tackle2-addon/ssh"
"github.com/konveyor/tackle2-hub/api"
"github.com/konveyor/tackle2-hub/nas"
)

// Subversion repository.
Expand All @@ -27,13 +28,9 @@ func (r *Subversion) Validate() (err error) {
if err != nil {
return
}
insecure, err := addon.Setting.Bool("svn.insecure.enabled")
if err != nil {
return
}
switch u.Scheme {
case "http":
if !insecure {
if !r.Insecure {
err = errors.New("http URL used with snv.insecure.enabled = FALSE")
return
}
Expand Down Expand Up @@ -77,13 +74,9 @@ func (r *Subversion) Fetch() (err error) {
func (r *Subversion) checkout(branch string) (err error) {
url := r.URL()
_ = nas.RmDir(r.Path)
insecure, err := addon.Setting.Bool("svn.insecure.enabled")
if err != nil {
return
}
cmd := command.New("/usr/bin/svn")
cmd.Options.Add("--non-interactive")
if insecure {
if r.Insecure {
cmd.Options.Add("--trust-server-cert")
}

Expand Down Expand Up @@ -124,6 +117,10 @@ func (r *Subversion) addFiles(files []string) (err error) {
cmd := command.New("/usr/bin/svn")
cmd.Dir = r.Path
cmd.Options.Add("add")
cmd.Options.Add("--non-interactive")
if r.Insecure {
cmd.Options.Add("--trust-server-cert")
}
cmd.Options.Add("--force", files...)
err = cmd.Run()
return
Expand All @@ -138,6 +135,10 @@ func (r *Subversion) Commit(files []string, msg string) (err error) {
cmd := command.New("/usr/bin/svn")
cmd.Dir = r.Path
cmd.Options.Add("commit", "-m", msg)
cmd.Options.Add("--non-interactive")
if r.Insecure {
cmd.Options.Add("--trust-server-cert")
}
err = cmd.Run()
return
}
Expand Down Expand Up @@ -201,6 +202,9 @@ func (r *Subversion) writePassword(id *api.Identity) (err error) {

cmd := command.New("/usr/bin/svn")
cmd.Options.Add("--non-interactive")
if r.Insecure {
cmd.Options.Add("--trust-server-cert")
}
cmd.Options.Add("--username")
cmd.Options.Add(id.User)
cmd.Options.Add("--password")
Expand Down