Skip to content

Commit

Permalink
mirror-bitbucket-server: use TLS by default
Browse files Browse the repository at this point in the history
Change-Id: I0c3eb10b0a328597582548ace3055952ad62cb9e
  • Loading branch information
greenyouse authored and hanwen committed Sep 17, 2020
1 parent 3c99d42 commit a75291a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 14 deletions.
4 changes: 4 additions & 0 deletions cmd/zoekt-indexserver/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ type ConfigEntry struct {
GitilesURL string
CGitURL string
BitBucketServerURL string
DisableTLS bool
CredentialPath string
ProjectType string
Name string
Expand Down Expand Up @@ -208,6 +209,9 @@ func executeMirror(cfg []ConfigEntry, repoDir string, pendingRepos chan<- string
if c.BitBucketServerProject != "" {
cmd.Args = append(cmd.Args, "-project", c.BitBucketServerProject)
}
if c.DisableTLS {
cmd.Args = append(cmd.Args, "-disable-tls")
}
if c.ProjectType != "" {
cmd.Args = append(cmd.Args, "-type", c.ProjectType)
}
Expand Down
31 changes: 17 additions & 14 deletions cmd/zoekt-mirror-bitbucket-server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import (
func main() {
dest := flag.String("dest", "", "destination directory")
serverUrl := flag.String("url", "", "BitBucket Server url")
disableTLS := flag.Bool("disable-tls", false, "disables TLS verification")
credentialsFile := flag.String("credentials", ".bitbucket-credentials", "file holding BitBucket Server credentials")
project := flag.String("project", "", "project to mirror")
deleteRepos := flag.Bool("delete", false, "delete missing repos")
Expand Down Expand Up @@ -86,27 +87,29 @@ func main() {
ctx = context.WithValue(ctx, bitbucketv1.ContextBasicAuth, basicAuth)
defer cancel()

tr := &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
}
httpClient := &http.Client{
Transport: tr,
}
httpClientConfig := func(configs *bitbucketv1.Configuration) {
configs.HTTPClient = httpClient
}

apiPath, err := url.Parse("/rest")
if err != nil {
log.Fatal(err)
}

apiBaseURL := rootURL.ResolveReference(apiPath).String()

client := bitbucketv1.NewAPIClient(
ctx,
bitbucketv1.NewConfiguration(apiBaseURL, httpClientConfig),
)
var config *bitbucketv1.Configuration
if *disableTLS {
tr := &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
}
httpClient := &http.Client{
Transport: tr,
}
httpClientConfig := func(configs *bitbucketv1.Configuration) {
configs.HTTPClient = httpClient
}
config = bitbucketv1.NewConfiguration(apiBaseURL, httpClientConfig)
} else {
config = bitbucketv1.NewConfiguration(apiBaseURL)
}
client := bitbucketv1.NewAPIClient(ctx, config)

var repos []bitbucketv1.Repository

Expand Down

0 comments on commit a75291a

Please sign in to comment.