diff --git a/cmd/root.go b/cmd/root.go index 44df1509..63655d43 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -19,6 +19,7 @@ var presetQuery string // named / preset query fl var dbPath string // path to sqlite db file on disk to mount on var repo string // path to repo on disk var cloneDir string // path to directory to clone repos in +var gitSSLNoVerify = os.Getenv("GIT_SSL_NO_VERIFY") // if set to anything, will not verify SSL when cloning var githubToken = os.Getenv("GITHUB_TOKEN") // GitHub auth token for GitHub tables var sourcegraphToken = os.Getenv("SOURCEGRAPH_TOKEN") // Sourcegraph auth token for Sourcegraph queries var verbose bool // whether or not to print logs to stderr diff --git a/cmd/setup.go b/cmd/setup.go index 6e59b5f2..4af9d21b 100644 --- a/cmd/setup.go +++ b/cmd/setup.go @@ -16,7 +16,8 @@ import ( func registerExt() { multiLocOpt := &locator.MultiLocatorOptions{ - CloneDir: cloneDir, + CloneDir: cloneDir, + InsecureSkipTLS: gitSSLNoVerify != "", } if githubToken != "" { multiLocOpt.HTTPAuth = &http.BasicAuth{Username: githubToken} diff --git a/pkg/locator/locator.go b/pkg/locator/locator.go index c1da6231..631903a6 100644 --- a/pkg/locator/locator.go +++ b/pkg/locator/locator.go @@ -97,7 +97,7 @@ func determineCloneDir(path, baseCloneDir string) (string, bool, error) { // http repositories on-demand into temporary storage. It is recommended // that you club it with something like CachedLocator to improve performance // and remove the need to clone a single repository multiple times. -func HttpLocator(cloneDir string) func() services.RepoLocator { +func HttpLocator(o *MultiLocatorOptions) func() services.RepoLocator { return func() services.RepoLocator { return options.RepoLocatorFn(func(ctx context.Context, path string) (*git.Repository, error) { var err error @@ -107,11 +107,11 @@ func HttpLocator(cloneDir string) func() services.RepoLocator { var cd string var isTmp bool - if cd, isTmp, err = determineCloneDir(path, cloneDir); err != nil { + if cd, isTmp, err = determineCloneDir(path, o.CloneDir); err != nil { return nil, errors.Wrap(err, "could not determine clone directory") } - return git.PlainCloneContext(ctx, cd, isTmp, &git.CloneOptions{URL: path}) + return git.PlainCloneContext(ctx, cd, isTmp, &git.CloneOptions{URL: path, InsecureSkipTLS: o.InsecureSkipTLS}) }) } } @@ -145,7 +145,7 @@ func httpLocatorWithAuth(user, pass string, rl services.RepoLocator) func() serv // ssh repositories on-demand into temporary storage. It is recommended // that you club it with something like CachedLocator to improve performance // and remove the need to clone a single repository multiple times. -func SSHLocator(cloneDir string) func() services.RepoLocator { +func SSHLocator(o *MultiLocatorOptions) func() services.RepoLocator { return func() services.RepoLocator { return options.RepoLocatorFn(func(ctx context.Context, path string) (*git.Repository, error) { path = strings.TrimPrefix(path, "ssh://") @@ -166,7 +166,7 @@ func SSHLocator(cloneDir string) func() services.RepoLocator { var cd string var isTmp bool var err error - if cd, isTmp, err = determineCloneDir(path, cloneDir); err != nil { + if cd, isTmp, err = determineCloneDir(path, o.CloneDir); err != nil { return nil, errors.Wrap(err, "could not determine clone directory") } @@ -175,14 +175,15 @@ func SSHLocator(cloneDir string) func() services.RepoLocator { return nil, errors.Wrap(err, "failed to create an SSH authentication method") } - return git.PlainCloneContext(ctx, cd, isTmp, &git.CloneOptions{URL: path, Auth: auth}) + return git.PlainCloneContext(ctx, cd, isTmp, &git.CloneOptions{URL: path, Auth: auth, InsecureSkipTLS: o.InsecureSkipTLS}) }) } } type MultiLocatorOptions struct { - HTTPAuth *http.BasicAuth - CloneDir string + HTTPAuth *http.BasicAuth + CloneDir string + InsecureSkipTLS bool } // MultiLocator returns a locator service that work with multiple git protocols @@ -192,8 +193,8 @@ func MultiLocator(o *MultiLocatorOptions) services.RepoLocator { o = &MultiLocatorOptions{} } var locators = map[string]func() services.RepoLocator{ - "http": HttpLocator(o.CloneDir), - "ssh": SSHLocator(o.CloneDir), + "http": HttpLocator(o), + "ssh": SSHLocator(o), "file": DiskLocator, } diff --git a/shared.go b/shared.go index 7038586e..4e5eff86 100644 --- a/shared.go +++ b/shared.go @@ -16,17 +16,18 @@ import ( ) func init() { + multiLocOpt := &locator.MultiLocatorOptions{ + InsecureSkipTLS: os.Getenv("GIT_SSL_NO_VERIFY") != "", + } + githubToken := os.Getenv("GITHUB_TOKEN") - var multiLocOpt locator.MultiLocatorOptions if githubToken != "" { - multiLocOpt = locator.MultiLocatorOptions{ - HTTPAuth: &http.BasicAuth{Username: githubToken}, - } + multiLocOpt.HTTPAuth = &http.BasicAuth{Username: githubToken} } sqlite.Register(extensions.RegisterFn( options.WithExtraFunctions(), - options.WithRepoLocator(locator.CachedLocator(locator.MultiLocator(&multiLocOpt))), + options.WithRepoLocator(locator.CachedLocator(locator.MultiLocator(multiLocOpt))), options.WithGitHub(), options.WithContextValue("githubToken", githubToken), options.WithContextValue("githubPerPage", os.Getenv("GITHUB_PER_PAGE")),