Documentation ¶
Overview ¶
* © 2023 Khulnasoft Limited All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License.
Index ¶
- Constants
- Variables
- func DecodePath(encodedRelativePath string) (string, error)
- func EncodePath(relativePath string) string
- func TempWorkdirWithVulnerabilities(t *testing.T) (filePath string, path string)
- func ToAbsolutePath(baseDir string, relativePath string) string
- func ToRelativeUnixPath(baseDir string, absoluteFilePath string) (string, error)
- type AnalysisOptions
- type AnalysisRequest
- type AnalysisRequestKey
- type AnalysisStatus
- type AutofixFeedback
- type AutofixOptions
- type AutofixRequest
- type AutofixRequestKey
- type AutofixResponse
- type AutofixStatus
- type AutofixSuggestion
- type Bundle
- type BundleFile
- type BundleUploader
- type FakeVulnmapCodeClient
- func (f *FakeVulnmapCodeClient) Clear()
- func (f *FakeVulnmapCodeClient) CreateBundle(_ context.Context, files map[string]string) (bundleHash string, missingFiles []string, err error)
- func (f *FakeVulnmapCodeClient) ExtendBundle(_ context.Context, bundleHash string, files map[string]BundleFile, ...) (string, []string, error)
- func (f *FakeVulnmapCodeClient) GetAllCalls(op string) [][]any
- func (f *FakeVulnmapCodeClient) GetCallParams(callNo int, op string) []any
- func (f *FakeVulnmapCodeClient) GetFilters(_ context.Context) (filters FiltersResponse, err error)
- func (f *FakeVulnmapCodeClient) RunAnalysis(_ context.Context, options AnalysisOptions, _ string) ([]vulnmap.Issue, AnalysisStatus, error)
- func (f *FakeVulnmapCodeClient) RunAutofix(_ context.Context, options AutofixOptions, baseDir string) ([]AutofixSuggestion, AutofixStatus, error)
- func (f *FakeVulnmapCodeClient) SubmitAutofixFeedback(ctx context.Context, fixId string, positive bool) error
- type FiltersResponse
- type SarifResponse
- type ScanMetrics
- type ScanStatus
- type Scanner
- func (sc *Scanner) IsEnabled() bool
- func (sc *Scanner) Product() product.Product
- func (sc *Scanner) Scan(ctx context.Context, path string, folderPath string) (issues []vulnmap.Issue, err error)
- func (sc *Scanner) SupportedCommands() []vulnmap.CommandName
- func (sc *Scanner) UploadAndAnalyze(ctx context.Context, files <-chan string, path string, ...) (issues []vulnmap.Issue, err error)
- type UploadBatch
- type UploadStatus
- type VulnmapAnalysisFailedError
- type VulnmapAutofixFailedError
- type VulnmapCodeClient
- type VulnmapCodeHTTPClient
- func (s *VulnmapCodeHTTPClient) CreateBundle(ctx context.Context, filesToFilehashes map[string]string) (string, []string, error)
- func (s *VulnmapCodeHTTPClient) ExtendBundle(ctx context.Context, bundleHash string, files map[string]BundleFile, ...) (string, []string, error)
- func (s *VulnmapCodeHTTPClient) GetFilters(ctx context.Context) (filters FiltersResponse, err error)
- func (s *VulnmapCodeHTTPClient) RunAnalysis(ctx context.Context, options AnalysisOptions, baseDir string) ([]vulnmap.Issue, AnalysisStatus, error)
- func (s *VulnmapCodeHTTPClient) RunAutofix(ctx context.Context, options AutofixOptions, baseDir string) ([]AutofixSuggestion, AutofixStatus, error)
- func (s *VulnmapCodeHTTPClient) SubmitAutofixFeedback(ctx context.Context, fixId string, positive bool) error
Constants ¶
const ( CreateBundleOperation = "createBundle" ExtendBundleWithSourceOperation = "extendBundleWithSource" RunAnalysisOperation = "runAnalysis" RunAutofixOperation = "runAutofix" GetFiltersOperation = "getFilters" FakeFileExtension = ".java" // Helper constants to synchronize fake results and tests FakeAutofixSuggestionNewText = "FAKE_AUTOFIX_NEW_TEXT" )
Variables ¶
var ( FakeVulnmapCodeApiServiceMutex = &sync.Mutex{} FakeCommand = vulnmap.CommandData{ Title: "Code Flow blah blah fake", CommandId: vulnmap.NavigateToRangeCommand, Arguments: []any{"path", fakeRange}, } FakeFixCommand = vulnmap.CommandData{ Title: "Code Flow blah blah fake", CommandId: vulnmap.CodeFixCommand, Arguments: []any{"id", "path", fakeRange}, } FakeIssue = vulnmap.Issue{ ID: "VULNMAP-123", Range: fakeRange, Severity: vulnmap.High, Product: product.ProductCode, IssueType: vulnmap.CodeQualityIssue, Message: "This is a dummy error (severity error)", CodelensCommands: []vulnmap.CommandData{FakeCommand, FakeFixCommand}, CodeActions: []vulnmap.CodeAction{FakeCodeAction}, AdditionalData: vulnmap.CodeIssueData{ IsAutofixable: true, }, } FakeCodeAction = vulnmap.CodeAction{ Title: "FakeAction", Command: &FakeCommand, } FakeFilters = []string{".cjs", ".ejs", ".es", ".es6", ".htm", ".html", ".js", ".jsx", ".mjs", ".ts", ".tsx", ".vue", ".java", ".erb", ".haml", ".rb", ".rhtml", ".slim", ".kt", ".swift", ".cls", ".config", ".pom", ".wxs", ".xml", ".xsd", ".aspx", ".cs", ".py", ".go", ".c", ".cc", ".cpp", ".cxx", ".h", ".hpp", ".hxx", ".php", ".phtml"} FakeAutofixFilters = []string{FakeFileExtension} // Main test scenario -- allowlist the fake file for autofix )
Functions ¶
func DecodePath ¶
func EncodePath ¶
func ToAbsolutePath ¶
Types ¶
type AnalysisOptions ¶
type AnalysisOptions struct {
// contains filtered or unexported fields
}
type AnalysisRequest ¶
type AnalysisRequest struct { Key AnalysisRequestKey `json:"key"` Severity int `json:"severity,omitempty"` Prioritized bool `json:"prioritized,omitempty"` Legacy bool `json:"legacy"` AnalysisContext codeRequestContext `json:"analysisContext"` }
type AnalysisRequestKey ¶
type AnalysisStatus ¶
type AnalysisStatus struct {
// contains filtered or unexported fields
}
type AutofixFeedback ¶
type AutofixOptions ¶
type AutofixOptions struct {
// contains filtered or unexported fields
}
type AutofixRequest ¶
type AutofixRequest struct { Key AutofixRequestKey `json:"key"` AnalysisContext codeRequestContext `json:"analysisContext"` }
type AutofixRequestKey ¶
type AutofixRequestKey struct { Type string `json:"type"` Hash string `json:"hash"` Shard string `json:"shard"` FilePath string `json:"filePath"` RuleId string `json:"ruleId"` // 1-based to comply with Sarif and Code API, see // https://docs.oasis-open.org/sarif/sarif/v2.1.0/sarif-v2.1.0.html#_Ref493492556 LineNum int `json:"lineNum"` }
type AutofixResponse ¶
type AutofixResponse struct { Status string `json:"status"` AutofixSuggestions []autofixResponseSingleFix `json:"fixes"` }
AutofixResponse is the json-based structure to which we can translate the results of the HTTP request to Autofix upstream.
type AutofixStatus ¶
type AutofixStatus struct {
// contains filtered or unexported fields
}
type AutofixSuggestion ¶
type AutofixSuggestion struct { FixId string AutofixEdit vulnmap.WorkspaceEdit }
AutofixSuggestion models a fix returned by autofix service
type Bundle ¶
type Bundle struct { VulnmapCode VulnmapCodeClient BundleHash string UploadBatches []*UploadBatch Files map[string]BundleFile // contains filtered or unexported fields }
func (*Bundle) FetchDiagnosticsData ¶
type BundleFile ¶
type BundleUploader ¶
type BundleUploader struct { VulnmapCode VulnmapCodeClient // contains filtered or unexported fields }
func NewBundler ¶
func NewBundler(VulnmapCode VulnmapCodeClient, instrumentor performance.Instrumentor) *BundleUploader
func (*BundleUploader) Upload ¶
func (b *BundleUploader) Upload(ctx context.Context, bundle Bundle, files map[string]BundleFile) (Bundle, error)
type FakeVulnmapCodeClient ¶
type FakeVulnmapCodeClient struct { Calls map[string][][]any HasCreatedNewBundle bool HasExtendedBundle bool ExtendBundleFiles map[string]BundleFile TotalBundleCount int ExtendedBundleCount int AnalysisDuration time.Duration FailOnCreateBundle bool ConfigFiles []string NoFixSuggestions bool // contains filtered or unexported fields }
func (*FakeVulnmapCodeClient) Clear ¶
func (f *FakeVulnmapCodeClient) Clear()
func (*FakeVulnmapCodeClient) CreateBundle ¶
func (*FakeVulnmapCodeClient) ExtendBundle ¶
func (f *FakeVulnmapCodeClient) ExtendBundle( _ context.Context, bundleHash string, files map[string]BundleFile, removedFiles []string, ) (string, []string, error)
func (*FakeVulnmapCodeClient) GetAllCalls ¶
func (f *FakeVulnmapCodeClient) GetAllCalls(op string) [][]any
func (*FakeVulnmapCodeClient) GetCallParams ¶
func (f *FakeVulnmapCodeClient) GetCallParams(callNo int, op string) []any
func (*FakeVulnmapCodeClient) GetFilters ¶
func (f *FakeVulnmapCodeClient) GetFilters(_ context.Context) ( filters FiltersResponse, err error, )
func (*FakeVulnmapCodeClient) RunAnalysis ¶
func (f *FakeVulnmapCodeClient) RunAnalysis( _ context.Context, options AnalysisOptions, _ string, ) ([]vulnmap.Issue, AnalysisStatus, error)
func (*FakeVulnmapCodeClient) RunAutofix ¶
func (f *FakeVulnmapCodeClient) RunAutofix( _ context.Context, options AutofixOptions, baseDir string, ) ([]AutofixSuggestion, AutofixStatus, error)
func (*FakeVulnmapCodeClient) SubmitAutofixFeedback ¶
type FiltersResponse ¶
type SarifResponse ¶
type SarifResponse struct { Type string `json:"type"` Progress float64 `json:"progress"` Status string `json:"status"` Timing struct { FetchingCode int `json:"fetchingCode"` Queue int `json:"queue"` Analysis int `json:"analysis"` } `json:"timing"` Coverage []struct { Files int `json:"files"` IsSupported bool `json:"isSupported"` Lang string `json:"lang"` } `json:"coverage"` Sarif struct { Schema string `json:"$schema"` Version string `json:"version"` Runs []run `json:"runs"` } `json:"sarif"` }
type ScanMetrics ¶
type ScanMetrics struct {
// contains filtered or unexported fields
}
type ScanStatus ¶
type ScanStatus struct {
// contains filtered or unexported fields
}
func NewScanStatus ¶
func NewScanStatus() *ScanStatus
type Scanner ¶
type Scanner struct { BundleUploader *BundleUploader VulnmapApiClient vulnmap_api.VulnmapApiClient // contains filtered or unexported fields }
func New ¶
func New(bundleUploader *BundleUploader, apiClient vulnmap_api.VulnmapApiClient, reporter error_reporting.ErrorReporter, analytics ux2.Analytics, learnService learn.Service, notifier notification.Notifier, ) *Scanner
func (*Scanner) SupportedCommands ¶
func (sc *Scanner) SupportedCommands() []vulnmap.CommandName
type UploadBatch ¶
type UploadBatch struct {
// contains filtered or unexported fields
}
func NewUploadBatch ¶
func NewUploadBatch() *UploadBatch
type UploadStatus ¶
type VulnmapAnalysisFailedError ¶
type VulnmapAnalysisFailedError struct {
Msg string
}
func (VulnmapAnalysisFailedError) Error ¶
func (e VulnmapAnalysisFailedError) Error() string
type VulnmapAutofixFailedError ¶
type VulnmapAutofixFailedError struct {
Msg string
}
Should implement `error` interface
func (VulnmapAutofixFailedError) Error ¶
func (e VulnmapAutofixFailedError) Error() string
type VulnmapCodeClient ¶
type VulnmapCodeClient interface { GetFilters(ctx context.Context) ( filters FiltersResponse, err error) CreateBundle( ctx context.Context, files map[string]string, ) (newBundleHash string, missingFiles []string, err error) ExtendBundle( ctx context.Context, bundleHash string, files map[string]BundleFile, removedFiles []string, ) (newBundleHash string, missingFiles []string, err error) RunAnalysis( ctx context.Context, options AnalysisOptions, baseDir string, ) ( []vulnmap.Issue, AnalysisStatus, error, ) RunAutofix( ctx context.Context, options AutofixOptions, baseDir string, ) ([]AutofixSuggestion, AutofixStatus, error, ) SubmitAutofixFeedback(ctx context.Context, fixId string, positive bool) error }
type VulnmapCodeHTTPClient ¶
type VulnmapCodeHTTPClient struct {
// contains filtered or unexported fields
}
func NewHTTPRepository ¶
func NewHTTPRepository( instrumentor performance2.Instrumentor, errorReporter error_reporting.ErrorReporter, client func() *http.Client, ) *VulnmapCodeHTTPClient
func (*VulnmapCodeHTTPClient) CreateBundle ¶
func (*VulnmapCodeHTTPClient) ExtendBundle ¶
func (s *VulnmapCodeHTTPClient) ExtendBundle( ctx context.Context, bundleHash string, files map[string]BundleFile, removedFiles []string, ) (string, []string, error)
func (*VulnmapCodeHTTPClient) GetFilters ¶
func (s *VulnmapCodeHTTPClient) GetFilters(ctx context.Context) ( filters FiltersResponse, err error, )
func (*VulnmapCodeHTTPClient) RunAnalysis ¶
func (s *VulnmapCodeHTTPClient) RunAnalysis( ctx context.Context, options AnalysisOptions, baseDir string, ) ([]vulnmap.Issue, AnalysisStatus, error)
func (*VulnmapCodeHTTPClient) RunAutofix ¶
func (s *VulnmapCodeHTTPClient) RunAutofix( ctx context.Context, options AutofixOptions, baseDir string, ) ([]AutofixSuggestion, AutofixStatus, error, )