Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

codeintel: handle -insecure-skip-verify in SCIP endpoint detection #1012

Merged
merged 2 commits into from
Jul 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ All notable changes to `src-cli` are documented in this file.

### Fixed

- Fixed `src code-intel upload` not respecting `-insecure-skip-verify`. [#1012](https://github.com/sourcegraph/src-cli/pull/1012)

### Removed

## 5.1.0
Expand Down
7 changes: 1 addition & 6 deletions cmd/src/code_intel_upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,7 @@ Examples:
func handleCodeIntelUpload(args []string) error {
ctx := context.Background()

isSCIPAvailable, err := isSCIPAvailable()
if err != nil {
return err
}

out, err := parseAndValidateCodeIntelUploadFlags(args, isSCIPAvailable)
out, isSCIPAvailable, err := parseAndValidateCodeIntelUploadFlags(args)
if !codeintelUploadFlags.json {
if out != nil {
printInferredArguments(out)
Expand Down
29 changes: 17 additions & 12 deletions cmd/src/code_intel_upload_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@ func init() {
//
// On success, the global codeintelUploadFlags object will be populated with valid values. An
// error is returned on failure.
func parseAndValidateCodeIntelUploadFlags(args []string, isSCIPAvailable bool) (*output.Output, error) {
func parseAndValidateCodeIntelUploadFlags(args []string) (*output.Output, bool, error) {
if err := codeintelUploadFlagSet.Parse(args); err != nil {
return nil, err
return nil, false, err
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-blocking: we default to "scip is not available", but it might make sense to flip the boolean and rename it into isLSIFRequired or something like that

}

out := codeintelUploadOutput()
Expand All @@ -120,51 +120,56 @@ func parseAndValidateCodeIntelUploadFlags(args []string, isSCIPAvailable bool) (
// and maybe we'll use some in the future
codeintelUploadFlags.apiFlags = api.NewFlags(apiClientFlagSet)
if err := apiClientFlagSet.Parse(insecureSkipVerifyFlag); err != nil {
return nil, err
return nil, false, err
}

if !isFlagSet(codeintelUploadFlagSet, "file") {
defaultFile, err := inferDefaultFile()
if err != nil {
return nil, err
return nil, false, err
}
codeintelUploadFlags.file = defaultFile
}

// Check to see if input file exists
if _, err := os.Stat(codeintelUploadFlags.file); os.IsNotExist(err) {
if !isFlagSet(codeintelUploadFlagSet, "file") {
return nil, formatInferenceError(argumentInferenceError{"file", err})
return nil, false, formatInferenceError(argumentInferenceError{"file", err})
}

return nil, errors.Newf("file %q does not exist", codeintelUploadFlags.file)
return nil, false, errors.Newf("file %q does not exist", codeintelUploadFlags.file)
}

isSCIPAvailable, err := isSCIPAvailable()
if err != nil {
return nil, false, err
}

if !isSCIPAvailable {
if err := handleSCIP(out); err != nil {
return nil, err
return nil, false, err
}
} else {
if err := handleLSIF(out); err != nil {
return nil, err
return nil, false, err
}
}

// Check for new file existence after transformation
if _, err := os.Stat(codeintelUploadFlags.file); os.IsNotExist(err) {
return nil, errors.Newf("file %q does not exist", codeintelUploadFlags.file)
return nil, false, errors.Newf("file %q does not exist", codeintelUploadFlags.file)
}

// Infer the remaining default arguments (may require reading from new file)
if inferenceErrors := inferMissingCodeIntelUploadFlags(); len(inferenceErrors) > 0 {
return nil, formatInferenceError(inferenceErrors[0])
return nil, false, formatInferenceError(inferenceErrors[0])
}

if err := validateCodeIntelUploadFlags(); err != nil {
return nil, err
return nil, false, err
}

return out, nil
return out, isSCIPAvailable, nil
}

// codeintelUploadOutput returns an output object that should be used to print the progres
Expand Down