Skip to content

Commit e1b5b91

Browse files
authored
Respect access token on lsif upload command. (#102)
1 parent dd46ef6 commit e1b5b91

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

cmd/src/lsif_upload.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,15 @@ Examples:
2626
2727
Upload an LSIF dump:
2828
29-
$ src lsif upload -repo=FOO -commit=BAR -upload-token=BAZ -file=data.lsif
29+
$ src lsif upload -repo=FOO -commit=BAR -file=data.lsif
3030
3131
Upload an LSIF dump for a subproject:
3232
33-
$ src lsif upload -repo=FOO -commit=BAR -upload-token=BAZ -file=data.lsif -root=cmd/
33+
$ src lsif upload -repo=FOO -commit=BAR -file=data.lsif -root=cmd/
3434
35+
Upload an LSIF dump when lsifEnforceAuth is enabled:
36+
37+
$ src lsif upload -repo=FOO -commit=BAR -file=data.lsif -github-token=BAZ
3538
`
3639

3740
flagSet := flag.NewFlagSet("upload", flag.ExitOnError)
@@ -151,8 +154,10 @@ Examples:
151154
if *apiFlags.getCurl {
152155
curl := fmt.Sprintf("gzip -c %s | curl \\\n", shellquote.Join(*fileFlag))
153156
curl += fmt.Sprintf(" -X POST \\\n")
154-
155157
curl += fmt.Sprintf(" %s \\\n", shellquote.Join("-H", "Content-Type: application/x-ndjson+lsif"))
158+
if cfg.AccessToken != "" {
159+
curl += fmt.Sprintf(" %s \\\n", shellquote.Join("-H", "Authorization: token "+cfg.AccessToken))
160+
}
156161
curl += fmt.Sprintf(" %s \\\n", shellquote.Join(url.String()))
157162
curl += fmt.Sprintf(" %s", shellquote.Join("--data-binary", "@-"))
158163

@@ -176,6 +181,9 @@ Examples:
176181
}
177182

178183
req.Header.Set("Content-Type", "application/x-ndjson+lsif")
184+
if cfg.AccessToken != "" {
185+
req.Header.Set("Authorization", "token "+cfg.AccessToken)
186+
}
179187

180188
// Perform the request.
181189
resp, err := http.DefaultClient.Do(req)
@@ -194,7 +202,7 @@ Examples:
194202
return err
195203
}
196204

197-
// Our request may have failed before the reaching GraphQL endpoint, so
205+
// Our request may have failed before the reaching the upload endpoint, so
198206
// confirm the status code. You can test this easily with e.g. an invalid
199207
// endpoint like -endpoint=https://google.com
200208
if resp.StatusCode < 200 || resp.StatusCode >= 300 {

0 commit comments

Comments
 (0)