From fbfcf7b92264294de93f6b5eab6454dfad24faca Mon Sep 17 00:00:00 2001 From: Dylan Murray Date: Mon, 8 Jan 2024 12:46:49 -0500 Subject: [PATCH 1/4] Add support for insecure SVN repos Signed-off-by: Dylan Murray (cherry picked from commit 708b02e5a8c2e724cadc0c6687187c9d33be452e) --- .gitignore | 4 ++++ repository/factory.go | 7 +++++++ repository/subversion.go | 34 +++++++++++++++++++--------------- 3 files changed, 30 insertions(+), 15 deletions(-) diff --git a/.gitignore b/.gitignore index a1b8904..d4eadbc 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,7 @@ # Dependency directories (remove the comment below to include it) # vendor/ + +# IDE directories +.idea/ + diff --git a/repository/factory.go b/repository/factory.go index 8b82055..0c2e5e3 100644 --- a/repository/factory.go +++ b/repository/factory.go @@ -17,6 +17,10 @@ func init() { // New SCM repository factory. func New(destDir string, remote *api.Repository, identities []api.Ref) (r SCM, err error) { + insecure, err := addon.Setting.Bool("svn.insecure.enabled") + if err != nil { + return + } switch remote.Kind { case "subversion": r = &Subversion{ @@ -24,6 +28,7 @@ func New(destDir string, remote *api.Repository, identities []api.Ref) (r SCM, e Remote: Remote{ Repository: remote, Identities: identities, + Insecure: insecure, }, } default: @@ -32,6 +37,7 @@ func New(destDir string, remote *api.Repository, identities []api.Ref) (r SCM, e Remote: Remote{ Repository: remote, Identities: identities, + Insecure: insecure, }, } } @@ -51,6 +57,7 @@ type SCM interface { type Remote struct { *api.Repository Identities []api.Ref + Insecure bool } // FindIdentity by kind. diff --git a/repository/subversion.go b/repository/subversion.go index afbf115..92ae4e5 100644 --- a/repository/subversion.go +++ b/repository/subversion.go @@ -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. @@ -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 } @@ -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") } @@ -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 @@ -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 } @@ -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") From 279902c1fe9f50969145a8ae55f4967956d54f2f Mon Sep 17 00:00:00 2001 From: Dylan Murray Date: Wed, 10 Jan 2024 10:45:51 -0500 Subject: [PATCH 2/4] Fix the factory for git Signed-off-by: Dylan Murray --- repository/git.go | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/repository/git.go b/repository/git.go index f1892eb..810c718 100644 --- a/repository/git.go +++ b/repository/git.go @@ -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 } @@ -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 @@ -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) } @@ -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 == "" { From 328987418fee6ce535ecff4c46b6a3baa7c11c4d Mon Sep 17 00:00:00 2001 From: Dylan Murray Date: Wed, 10 Jan 2024 14:36:43 -0500 Subject: [PATCH 3/4] Fix go vet Signed-off-by: Dylan Murray --- repository/factory.go | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/repository/factory.go b/repository/factory.go index 0c2e5e3..74e76e5 100644 --- a/repository/factory.go +++ b/repository/factory.go @@ -1,9 +1,10 @@ package repository import ( + "os" + hub "github.com/konveyor/tackle2-hub/addon" "github.com/konveyor/tackle2-hub/api" - "os" ) var ( @@ -17,12 +18,12 @@ func init() { // New SCM repository factory. func New(destDir string, remote *api.Repository, identities []api.Ref) (r SCM, err error) { - insecure, err := addon.Setting.Bool("svn.insecure.enabled") - if err != nil { - return - } switch remote.Kind { case "subversion": + insecure, err := addon.Setting.Bool("svn.insecure.enabled") + if err != nil { + return r, err + } r = &Subversion{ Path: destDir, Remote: Remote{ @@ -32,6 +33,10 @@ func New(destDir string, remote *api.Repository, identities []api.Ref) (r SCM, e }, } default: + insecure, err := addon.Setting.Bool("git.insecure.enabled") + if err != nil { + return r, err + } r = &Git{ Path: destDir, Remote: Remote{ From 247ae3cc5655f79b2b7117cbf245060a34b53768 Mon Sep 17 00:00:00 2001 From: Dylan Murray Date: Wed, 10 Jan 2024 14:57:43 -0500 Subject: [PATCH 4/4] Style change Signed-off-by: Dylan Murray --- repository/factory.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/repository/factory.go b/repository/factory.go index 74e76e5..ea03043 100644 --- a/repository/factory.go +++ b/repository/factory.go @@ -18,11 +18,12 @@ 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") + insecure, err = addon.Setting.Bool("svn.insecure.enabled") if err != nil { - return r, err + return } r = &Subversion{ Path: destDir, @@ -33,9 +34,9 @@ func New(destDir string, remote *api.Repository, identities []api.Ref) (r SCM, e }, } default: - insecure, err := addon.Setting.Bool("git.insecure.enabled") + insecure, err = addon.Setting.Bool("git.insecure.enabled") if err != nil { - return r, err + return } r = &Git{ Path: destDir,