Skip to content

Commit 7051ea1

Browse files
authored
Support -insecure-skip-verify flag for LSIF upload (#559)
1 parent 4d17445 commit 7051ea1

File tree

4 files changed

+38
-4
lines changed

4 files changed

+38
-4
lines changed

cmd/src/lsif_upload.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"encoding/json"
66
"flag"
77
"fmt"
8+
"io"
89
"net/url"
910
"os"
1011
"strings"
@@ -14,6 +15,7 @@ import (
1415

1516
"github.com/sourcegraph/sourcegraph/lib/codeintel/upload"
1617
"github.com/sourcegraph/sourcegraph/lib/output"
18+
"github.com/sourcegraph/src-cli/internal/api"
1719
)
1820

1921
func init() {
@@ -64,7 +66,12 @@ func handleLSIFUpload(args []string) error {
6466
return handleLSIFUploadError(nil, err)
6567
}
6668

67-
uploadID, err := upload.UploadIndex(lsifUploadFlags.file, lsifUploadOptions(out))
69+
client := api.NewClient(api.ClientOpts{
70+
Out: io.Discard,
71+
Flags: lsifUploadFlags.apiFlags,
72+
})
73+
74+
uploadID, err := upload.UploadIndex(lsifUploadFlags.file, client, lsifUploadOptions(out))
6875
if err != nil {
6976
return handleLSIFUploadError(out, err)
7077
}
@@ -163,7 +170,7 @@ func lsifUploadOptions(out *output.Output) upload.UploadOptions {
163170
}
164171
}
165172

166-
//printInferredArguments prints a block showing the effective values of flags that are
173+
// printInferredArguments prints a block showing the effective values of flags that are
167174
// inferrably defined. This function is called on all paths except for -json uploads. This
168175
// function no-ops if the given output object is nil.
169176
func printInferredArguments(out *output.Output) {

cmd/src/lsif_upload_flags.go

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"strings"
99

1010
"github.com/sourcegraph/sourcegraph/lib/codeintel/upload"
11+
"github.com/sourcegraph/src-cli/internal/api"
1112
"github.com/sourcegraph/src-cli/internal/codeintel"
1213
)
1314

@@ -32,9 +33,16 @@ var lsifUploadFlags struct {
3233
verbosity int
3334
json bool
3435
open bool
36+
apiFlags *api.Flags
3537
}
3638

37-
var lsifUploadFlagSet = flag.NewFlagSet("upload", flag.ExitOnError)
39+
var (
40+
lsifUploadFlagSet = flag.NewFlagSet("upload", flag.ExitOnError)
41+
apiClientFlagSet = flag.NewFlagSet("upload client", flag.ExitOnError)
42+
// Used to include the insecure-skip-verify flag in the help output, as we don't use any of the
43+
// other api.Client methods, so only the insecureSkipVerify flag is relevant here.
44+
dummyflag bool
45+
)
3846

3947
func init() {
4048
lsifUploadFlagSet.StringVar(&lsifUploadFlags.file, "file", "./dump.lsif", `The path to the LSIF dump file.`)
@@ -57,6 +65,7 @@ func init() {
5765
lsifUploadFlagSet.IntVar(&lsifUploadFlags.verbosity, "trace", 0, "-trace=0 shows no logs; -trace=1 shows requests and response metadata; -trace=2 shows headers, -trace=3 shows response body")
5866
lsifUploadFlagSet.BoolVar(&lsifUploadFlags.json, "json", false, `Output relevant state in JSON on success.`)
5967
lsifUploadFlagSet.BoolVar(&lsifUploadFlags.open, "open", false, `Open the LSIF upload page in your browser.`)
68+
lsifUploadFlagSet.BoolVar(&dummyflag, "insecure-skip-verify", false, "Skip validation of TLS certificates against trusted chains")
6069
}
6170

6271
// parseAndValidateLSIFUploadFlags calls lsifUploadFlagSet.Parse, then infers values for
@@ -70,6 +79,22 @@ func parseAndValidateLSIFUploadFlags(args []string) error {
7079
return err
7180
}
7281

82+
// extract only the -insecure-skip-verify flag so we dont get 'flag provided but not defined'
83+
var insecureSkipVerifyFlag []string
84+
for _, s := range args {
85+
if strings.HasPrefix(s, "-insecure-skip-verify") {
86+
insecureSkipVerifyFlag = append(insecureSkipVerifyFlag, s)
87+
}
88+
}
89+
90+
// parse the api client flags separately and then populate the lsifUploadFlags struct with the result
91+
// we could just use insecureSkipVerify but I'm including everything here because it costs nothing
92+
// and maybe we'll use some in the future
93+
lsifUploadFlags.apiFlags = api.NewFlags(apiClientFlagSet)
94+
if err := apiClientFlagSet.Parse(insecureSkipVerifyFlag); err != nil {
95+
return err
96+
}
97+
7398
if inferenceErrors := inferMissingLSIFUploadFlags(); len(inferenceErrors) > 0 {
7499
return errorWithHint{
75100
err: inferenceErrors[0].err, hint: strings.Join([]string{

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ require (
2222
github.com/sourcegraph/batch-change-utils v0.0.0-20210309183117-206c057cc03e
2323
github.com/sourcegraph/go-diff v0.6.1
2424
github.com/sourcegraph/jsonx v0.0.0-20200629203448-1a936bd500cf
25-
github.com/sourcegraph/sourcegraph/lib v0.0.0-20210622093026-6470ff817296
25+
github.com/sourcegraph/sourcegraph/lib v0.0.0-20210625192803-788d15faf64b
2626
github.com/ssor/bom v0.0.0-20170718123548-6386211fdfcf // indirect
2727
github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb // indirect
2828
golang.org/x/net v0.0.0-20210614182718-04defd469f4e

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,8 @@ github.com/sourcegraph/jsonx v0.0.0-20200629203448-1a936bd500cf h1:oAdWFqhStsWii
242242
github.com/sourcegraph/jsonx v0.0.0-20200629203448-1a936bd500cf/go.mod h1:ppFaPm6kpcHnZGqQTFhUIAQRIEhdQDWP1PCv4/ON354=
243243
github.com/sourcegraph/sourcegraph/lib v0.0.0-20210622093026-6470ff817296 h1:eP0i1yqCusx6d2jmy0X2z+dGfxKD4xI0CP9ox7UC7BA=
244244
github.com/sourcegraph/sourcegraph/lib v0.0.0-20210622093026-6470ff817296/go.mod h1:0Df1LLzPHhuxInVdcV/eIR7BVl1+R0rch5fSIK8+w5Y=
245+
github.com/sourcegraph/sourcegraph/lib v0.0.0-20210625192803-788d15faf64b h1:ybhugcgdMAlDSM/73NKFw+NY2YsEX2plpvAyH9cr96M=
246+
github.com/sourcegraph/sourcegraph/lib v0.0.0-20210625192803-788d15faf64b/go.mod h1:0Df1LLzPHhuxInVdcV/eIR7BVl1+R0rch5fSIK8+w5Y=
245247
github.com/sourcegraph/yaml v1.0.1-0.20200714132230-56936252f152 h1:z/MpntplPaW6QW95pzcAR/72Z5TWDyDnSo0EOcyij9o=
246248
github.com/sourcegraph/yaml v1.0.1-0.20200714132230-56936252f152/go.mod h1:GIjDIg/heH5DOkXY3YJ/wNhfHsQHoXGjl8G8amsYQ1I=
247249
github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ=

0 commit comments

Comments
 (0)