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 FakeKhulnasoftCodeClient
- func (f *FakeKhulnasoftCodeClient) Clear()
- func (f *FakeKhulnasoftCodeClient) CreateBundle(_ context.Context, files map[string]string) (bundleHash string, missingFiles []string, err error)
- func (f *FakeKhulnasoftCodeClient) ExtendBundle(_ context.Context, bundleHash string, files map[string]BundleFile, ...) (string, []string, error)
- func (f *FakeKhulnasoftCodeClient) GetAllCalls(op string) [][]any
- func (f *FakeKhulnasoftCodeClient) GetCallParams(callNo int, op string) []any
- func (f *FakeKhulnasoftCodeClient) GetFilters(_ context.Context) (filters FiltersResponse, err error)
- func (f *FakeKhulnasoftCodeClient) RunAnalysis(_ context.Context, options AnalysisOptions, _ string) ([]khulnasoft.Issue, AnalysisStatus, error)
- func (f *FakeKhulnasoftCodeClient) RunAutofix(_ context.Context, options AutofixOptions, baseDir string) ([]AutofixSuggestion, AutofixStatus, error)
- func (f *FakeKhulnasoftCodeClient) SubmitAutofixFeedback(ctx context.Context, fixId string, positive bool) error
- type FiltersResponse
- type KhulnasoftAnalysisFailedError
- type KhulnasoftAutofixFailedError
- type KhulnasoftCodeClient
- type KhulnasoftCodeHTTPClient
- func (s *KhulnasoftCodeHTTPClient) CreateBundle(ctx context.Context, filesToFilehashes map[string]string) (string, []string, error)
- func (s *KhulnasoftCodeHTTPClient) ExtendBundle(ctx context.Context, bundleHash string, files map[string]BundleFile, ...) (string, []string, error)
- func (s *KhulnasoftCodeHTTPClient) GetFilters(ctx context.Context) (filters FiltersResponse, err error)
- func (s *KhulnasoftCodeHTTPClient) RunAnalysis(ctx context.Context, options AnalysisOptions, baseDir string) ([]khulnasoft.Issue, AnalysisStatus, error)
- func (s *KhulnasoftCodeHTTPClient) RunAutofix(ctx context.Context, options AutofixOptions, baseDir string) ([]AutofixSuggestion, AutofixStatus, error)
- func (s *KhulnasoftCodeHTTPClient) SubmitAutofixFeedback(ctx context.Context, fixId string, positive bool) error
- 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 []khulnasoft.Issue, err error)
- func (sc *Scanner) SupportedCommands() []khulnasoft.CommandName
- func (sc *Scanner) UploadAndAnalyze(ctx context.Context, files <-chan string, path string, ...) (issues []khulnasoft.Issue, err error)
- type UploadBatch
- type UploadStatus
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 ( FakeKhulnasoftCodeApiServiceMutex = &sync.Mutex{} FakeCommand = khulnasoft.CommandData{ Title: "Code Flow blah blah fake", CommandId: khulnasoft.NavigateToRangeCommand, Arguments: []any{"path", fakeRange}, } FakeFixCommand = khulnasoft.CommandData{ Title: "Code Flow blah blah fake", CommandId: khulnasoft.CodeFixCommand, Arguments: []any{"id", "path", fakeRange}, } FakeIssue = khulnasoft.Issue{ ID: "KHULNASOFT-123", Range: fakeRange, Severity: khulnasoft.High, Product: product.ProductCode, IssueType: khulnasoft.CodeQualityIssue, Message: "This is a dummy error (severity error)", CodelensCommands: []khulnasoft.CommandData{FakeCommand, FakeFixCommand}, CodeActions: []khulnasoft.CodeAction{FakeCodeAction}, AdditionalData: khulnasoft.CodeIssueData{ IsAutofixable: true, }, } FakeCodeAction = khulnasoft.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 khulnasoft.WorkspaceEdit }
AutofixSuggestion models a fix returned by autofix service
type Bundle ¶
type Bundle struct { KhulnasoftCode KhulnasoftCodeClient BundleHash string UploadBatches []*UploadBatch Files map[string]BundleFile // contains filtered or unexported fields }
func (*Bundle) FetchDiagnosticsData ¶
type BundleFile ¶
type BundleUploader ¶
type BundleUploader struct { KhulnasoftCode KhulnasoftCodeClient // contains filtered or unexported fields }
func NewBundler ¶
func NewBundler(KhulnasoftCode KhulnasoftCodeClient, instrumentor performance.Instrumentor) *BundleUploader
func (*BundleUploader) Upload ¶
func (b *BundleUploader) Upload(ctx context.Context, bundle Bundle, files map[string]BundleFile) (Bundle, error)
type FakeKhulnasoftCodeClient ¶
type FakeKhulnasoftCodeClient 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 (*FakeKhulnasoftCodeClient) Clear ¶
func (f *FakeKhulnasoftCodeClient) Clear()
func (*FakeKhulnasoftCodeClient) CreateBundle ¶
func (*FakeKhulnasoftCodeClient) ExtendBundle ¶
func (f *FakeKhulnasoftCodeClient) ExtendBundle( _ context.Context, bundleHash string, files map[string]BundleFile, removedFiles []string, ) (string, []string, error)
func (*FakeKhulnasoftCodeClient) GetAllCalls ¶
func (f *FakeKhulnasoftCodeClient) GetAllCalls(op string) [][]any
func (*FakeKhulnasoftCodeClient) GetCallParams ¶
func (f *FakeKhulnasoftCodeClient) GetCallParams(callNo int, op string) []any
func (*FakeKhulnasoftCodeClient) GetFilters ¶
func (f *FakeKhulnasoftCodeClient) GetFilters(_ context.Context) ( filters FiltersResponse, err error, )
func (*FakeKhulnasoftCodeClient) RunAnalysis ¶
func (f *FakeKhulnasoftCodeClient) RunAnalysis( _ context.Context, options AnalysisOptions, _ string, ) ([]khulnasoft.Issue, AnalysisStatus, error)
func (*FakeKhulnasoftCodeClient) RunAutofix ¶
func (f *FakeKhulnasoftCodeClient) RunAutofix( _ context.Context, options AutofixOptions, baseDir string, ) ([]AutofixSuggestion, AutofixStatus, error)
func (*FakeKhulnasoftCodeClient) SubmitAutofixFeedback ¶
type FiltersResponse ¶
type KhulnasoftAnalysisFailedError ¶
type KhulnasoftAnalysisFailedError struct {
Msg string
}
func (KhulnasoftAnalysisFailedError) Error ¶
func (e KhulnasoftAnalysisFailedError) Error() string
type KhulnasoftAutofixFailedError ¶
type KhulnasoftAutofixFailedError struct {
Msg string
}
Should implement `error` interface
func (KhulnasoftAutofixFailedError) Error ¶
func (e KhulnasoftAutofixFailedError) Error() string
type KhulnasoftCodeClient ¶
type KhulnasoftCodeClient 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, ) ( []khulnasoft.Issue, AnalysisStatus, error, ) RunAutofix( ctx context.Context, options AutofixOptions, baseDir string, ) ([]AutofixSuggestion, AutofixStatus, error, ) SubmitAutofixFeedback(ctx context.Context, fixId string, positive bool) error }
type KhulnasoftCodeHTTPClient ¶
type KhulnasoftCodeHTTPClient struct {
// contains filtered or unexported fields
}
func NewHTTPRepository ¶
func NewHTTPRepository( instrumentor performance2.Instrumentor, errorReporter error_reporting.ErrorReporter, client func() *http.Client, ) *KhulnasoftCodeHTTPClient
func (*KhulnasoftCodeHTTPClient) CreateBundle ¶
func (*KhulnasoftCodeHTTPClient) ExtendBundle ¶
func (s *KhulnasoftCodeHTTPClient) ExtendBundle( ctx context.Context, bundleHash string, files map[string]BundleFile, removedFiles []string, ) (string, []string, error)
func (*KhulnasoftCodeHTTPClient) GetFilters ¶
func (s *KhulnasoftCodeHTTPClient) GetFilters(ctx context.Context) ( filters FiltersResponse, err error, )
func (*KhulnasoftCodeHTTPClient) RunAnalysis ¶
func (s *KhulnasoftCodeHTTPClient) RunAnalysis( ctx context.Context, options AnalysisOptions, baseDir string, ) ([]khulnasoft.Issue, AnalysisStatus, error)
func (*KhulnasoftCodeHTTPClient) RunAutofix ¶
func (s *KhulnasoftCodeHTTPClient) RunAutofix( ctx context.Context, options AutofixOptions, baseDir string, ) ([]AutofixSuggestion, AutofixStatus, error, )
func (*KhulnasoftCodeHTTPClient) SubmitAutofixFeedback ¶
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 KhulnasoftApiClient khulnasoft_api.KhulnasoftApiClient // contains filtered or unexported fields }
func New ¶
func New(bundleUploader *BundleUploader, apiClient khulnasoft_api.KhulnasoftApiClient, reporter error_reporting.ErrorReporter, analytics ux2.Analytics, learnService learn.Service, notifier notification.Notifier, ) *Scanner
func (*Scanner) SupportedCommands ¶
func (sc *Scanner) SupportedCommands() []khulnasoft.CommandName
func (*Scanner) UploadAndAnalyze ¶
type UploadBatch ¶
type UploadBatch struct {
// contains filtered or unexported fields
}
func NewUploadBatch ¶
func NewUploadBatch() *UploadBatch