From ec19faaa243dfc04e1f97dd5389f56cbd621208c Mon Sep 17 00:00:00 2001 From: Steven Kang Date: Tue, 10 Sep 2019 10:56:16 +1200 Subject: [PATCH] fix(stack): Skip SSL Verification (#3064) * fix(stack): Skip SSL Verification * fix(stack): Skip SSL Verification * fix(stack): move httpsCli into service * fix(stack): clean-up * fix(stack): move httpsCli back into the function * fix(stack): move httpsCli and InstallProtocol back into service * fix(stack): clean-up debugging * fix(stack): parameter cleanup Co-Authored-By: Anthony Lapenna --- api/cmd/portainer/main.go | 2 +- api/git/git.go | 26 +++++++++++++++++++++----- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/api/cmd/portainer/main.go b/api/cmd/portainer/main.go index 961039738..7f4d36635 100644 --- a/api/cmd/portainer/main.go +++ b/api/cmd/portainer/main.go @@ -102,7 +102,7 @@ func initLDAPService() portainer.LDAPService { } func initGitService() portainer.GitService { - return &git.Service{} + return git.NewService() } func initClientFactory(signatureService portainer.DigitalSignatureService, reverseTunnelService portainer.ReverseTunnelService) *docker.ClientFactory { diff --git a/api/git/git.go b/api/git/git.go index add688b01..116a5f113 100644 --- a/api/git/git.go +++ b/api/git/git.go @@ -1,21 +1,37 @@ package git import ( + "crypto/tls" + "net/http" "net/url" "strings" + "time" "gopkg.in/src-d/go-git.v4" "gopkg.in/src-d/go-git.v4/plumbing" + "gopkg.in/src-d/go-git.v4/plumbing/transport/client" + githttp "gopkg.in/src-d/go-git.v4/plumbing/transport/http" ) // Service represents a service for managing Git. -type Service struct{} +type Service struct { + httpsCli *http.Client +} // NewService initializes a new service. -func NewService(dataStorePath string) (*Service, error) { - service := &Service{} +func NewService() *Service { + httpsCli := &http.Client{ + Transport: &http.Transport{ + TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, + }, + Timeout: 300 * time.Second, + } - return service, nil + client.InstallProtocol("https", githttp.NewClient(httpsCli)) + + return &Service{ + httpsCli: httpsCli, + } } // ClonePublicRepository clones a public git repository using the specified URL in the specified @@ -32,7 +48,7 @@ func (service *Service) ClonePrivateRepositoryWithBasicAuth(repositoryURL, refer return cloneRepository(repositoryURL, referenceName, destination) } -func cloneRepository(repositoryURL, referenceName string, destination string) error { +func cloneRepository(repositoryURL, referenceName, destination string) error { options := &git.CloneOptions{ URL: repositoryURL, }