Documentation ¶
Overview ¶
* © 2023 Snyk 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 NewCodeErrorReporter(errorReporter error_reporting.ErrorReporter) codeClient.ErrorReporter
- func NewCodeInstrumentor() codeClient.Instrumentor
- func NewCodeTrackerFactory() codeClientScan.TrackerFactory
- func TempWorkdirWithIssues(t *testing.T) (filePath string, folderPath string)
- func ToAbsolutePath(baseDir string, relativePath string) string
- func ToEncodedNormalizedPath(rootPath string, filePath string) (string, error)
- 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 AutofixUnifiedDiffSuggestion
- type Bundle
- type BundleFile
- type BundleUploader
- type DataFlowItem
- type ExampleCommit
- type ExampleLines
- type FakeCodeScannerClient
- type FakeSnykCodeClient
- func (f *FakeSnykCodeClient) Clear()
- func (f *FakeSnykCodeClient) CreateBundle(_ context.Context, files map[string]string) (bundleHash string, missingFiles []string, err error)
- func (f *FakeSnykCodeClient) ExtendBundle(_ context.Context, bundleHash string, files map[string]BundleFile, ...) (string, []string, error)
- func (f *FakeSnykCodeClient) GetAllCalls(op string) [][]any
- func (f *FakeSnykCodeClient) GetAutofixDiffs(_ context.Context, _ string, _ AutofixOptions) (unifiedDiffSuggestions []AutofixUnifiedDiffSuggestion, status AutofixStatus, ...)
- func (f *FakeSnykCodeClient) GetAutofixSuggestions(_ context.Context, options AutofixOptions, _ string) ([]AutofixSuggestion, AutofixStatus, error)
- func (f *FakeSnykCodeClient) GetCallParams(callNo int, op string) []any
- func (f *FakeSnykCodeClient) GetFilters(_ context.Context) (filters FiltersResponse, err error)
- func (f *FakeSnykCodeClient) RunAnalysis(_ context.Context, options AnalysisOptions, _ string) ([]snyk.Issue, AnalysisStatus, error)
- func (f *FakeSnykCodeClient) SubmitAutofixFeedback(_ context.Context, _ string, _ string) error
- type FiltersResponse
- type HtmlRenderer
- type IgnoreDetail
- type IssueEnhancer
- type SarifConverter
- type ScanStatus
- type Scanner
- func (sc *Scanner) AddBundleHash(key, value string)
- func (sc *Scanner) BundleHashes() map[string]string
- func (sc *Scanner) Clear()
- func (sc *Scanner) ClearIssues(path string)
- func (sc *Scanner) DeltaScanningEnabled() bool
- func (sc *Scanner) GetAutofixDiffs(ctx context.Context, baseDir string, filePath string, issue snyk.Issue) (unifiedDiffSuggestions []AutofixUnifiedDiffSuggestion, err error)
- func (sc *Scanner) IsEnabled() bool
- func (sc *Scanner) IsProviderFor(issueType product.FilterableIssueType) bool
- func (sc *Scanner) Issue(key string) snyk.Issue
- func (sc *Scanner) Issues() snyk.IssuesByFile
- func (sc *Scanner) IssuesForFile(path string) []snyk.Issue
- func (sc *Scanner) IssuesForRange(path string, r snyk.Range) []snyk.Issue
- func (sc *Scanner) Product() product.Product
- func (sc *Scanner) RegisterCacheRemovalHandler(handler func(path string))
- func (sc *Scanner) Scan(ctx context.Context, path string, folderPath string) (issues []snyk.Issue, err error)
- func (sc *Scanner) SupportedCommands() []types.CommandName
- func (sc *Scanner) UploadAndAnalyze(ctx context.Context, files <-chan string, path string, ...) (issues []snyk.Issue, err error)
- func (sc *Scanner) UploadAndAnalyzeWithIgnores(ctx context.Context, path string, files <-chan string, ...) (issues []snyk.Issue, err error)
- type SnykAnalysisFailedError
- type SnykAutofixFailedError
- type SnykCodeClient
- type SnykCodeHTTPClient
- func (s *SnykCodeHTTPClient) CreateBundle(ctx context.Context, filesToFilehashes map[string]string) (string, []string, error)
- func (s *SnykCodeHTTPClient) ExtendBundle(ctx context.Context, bundleHash string, files map[string]BundleFile, ...) (string, []string, error)
- func (s *SnykCodeHTTPClient) GetAutofixDiffs(ctx context.Context, baseDir string, options AutofixOptions) (unifiedDiffSuggestions []AutofixUnifiedDiffSuggestion, status AutofixStatus, ...)
- func (s *SnykCodeHTTPClient) GetAutofixSuggestions(ctx context.Context, options AutofixOptions, baseDir string) (autofixSuggestions []AutofixSuggestion, status AutofixStatus, err error)
- func (s *SnykCodeHTTPClient) GetFilters(ctx context.Context) (filters FiltersResponse, err error)
- func (s *SnykCodeHTTPClient) RunAnalysis(ctx context.Context, options AnalysisOptions, baseDir string) ([]snyk.Issue, AnalysisStatus, error)
- func (s *SnykCodeHTTPClient) RunAutofix(ctx context.Context, options AutofixOptions) (AutofixResponse, error)
- func (s *SnykCodeHTTPClient) SubmitAutofixFeedback(ctx context.Context, fixId string, feedback string) error
- type SpanRecorderCode
- type UploadBatch
- type UploadStatus
Constants ¶
const ( FixPositiveFeedback string = "FIX_POSITIVE_FEEDBACK" FixNegativeFeedback string = "FIX_NEGATIVE_FEEDBACK" )
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 ( FakeSnykCodeApiServiceMutex = &sync.Mutex{} FakeCommand = types.CommandData{ Title: "Code Flow blah blah fake", CommandId: types.NavigateToRangeCommand, Arguments: []any{"path", fakeRange}, } FakeFixCommand = types.CommandData{ Title: "Code Flow blah blah fake", CommandId: types.CodeFixCommand, Arguments: []any{"id", "path", fakeRange}, } FakeIssue = snyk.Issue{ ID: "SNYK-123", Range: fakeRange, Severity: snyk.High, Product: product.ProductCode, IssueType: snyk.CodeQualityIssue, Message: "This is a dummy error (severity error)", CodelensCommands: []types.CommandData{FakeCommand, FakeFixCommand}, CodeActions: []snyk.CodeAction{FakeCodeAction}, AdditionalData: snyk.CodeIssueData{ Key: uuid.New().String(), IsAutofixable: true, }, } FakeCodeAction = snyk.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"} )
Functions ¶
func DecodePath ¶
func EncodePath ¶
func NewCodeErrorReporter ¶
func NewCodeErrorReporter(errorReporter error_reporting.ErrorReporter) codeClient.ErrorReporter
func NewCodeInstrumentor ¶
func NewCodeInstrumentor() codeClient.Instrumentor
func NewCodeTrackerFactory ¶
func NewCodeTrackerFactory() codeClientScan.TrackerFactory
func TempWorkdirWithIssues ¶
func ToAbsolutePath ¶
func ToEncodedNormalizedPath ¶
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 snyk.WorkspaceEdit }
AutofixSuggestion models a fix returned by autofix service
type AutofixUnifiedDiffSuggestion ¶
type AutofixUnifiedDiffSuggestion struct { FixId string `json:"fixId"` UnifiedDiffsPerFile map[string]string `json:"unifiedDiffsPerFile"` }
AutofixUnifiedDiffSuggestion represents the diff between the original and the fixed source code.
func (AutofixUnifiedDiffSuggestion) GetUnifiedDiffForFile ¶
func (a AutofixUnifiedDiffSuggestion) GetUnifiedDiffForFile(filePath string) string
func (AutofixUnifiedDiffSuggestion) String ¶
func (a AutofixUnifiedDiffSuggestion) String() string
type Bundle ¶
type Bundle struct { SnykCode SnykCodeClient BundleHash string UploadBatches []*UploadBatch Files map[string]BundleFile // contains filtered or unexported fields }
func (*Bundle) FetchDiagnosticsData ¶
type BundleFile ¶
type BundleUploader ¶
type BundleUploader struct { SnykCode SnykCodeClient // contains filtered or unexported fields }
func NewBundler ¶
func NewBundler(c *config.Config, SnykCode SnykCodeClient, instrumentor codeClientObservability.Instrumentor) *BundleUploader
type DataFlowItem ¶
type ExampleCommit ¶
type ExampleCommit struct { CommitURL string RepoName string RepoLink string ExampleLines []ExampleLines }
type ExampleLines ¶
type FakeCodeScannerClient ¶
type FakeCodeScannerClient struct { UploadAndAnalyzeWasCalled bool // contains filtered or unexported fields }
func (*FakeCodeScannerClient) UploadAndAnalyze ¶
func (f *FakeCodeScannerClient) UploadAndAnalyze(_ context.Context, _ string, _ scan.Target, files <-chan string, _ map[string]bool) (*codeClientSarif.SarifResponse, string, error)
type FakeSnykCodeClient ¶
type FakeSnykCodeClient 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 UnifiedDiffSuggestions []AutofixUnifiedDiffSuggestion AutofixStatus AutofixStatus Options map[string]AnalysisOptions C *config.Config // contains filtered or unexported fields }
func (*FakeSnykCodeClient) Clear ¶
func (f *FakeSnykCodeClient) Clear()
func (*FakeSnykCodeClient) CreateBundle ¶
func (*FakeSnykCodeClient) ExtendBundle ¶
func (f *FakeSnykCodeClient) ExtendBundle( _ context.Context, bundleHash string, files map[string]BundleFile, removedFiles []string, ) (string, []string, error)
func (*FakeSnykCodeClient) GetAllCalls ¶
func (f *FakeSnykCodeClient) GetAllCalls(op string) [][]any
func (*FakeSnykCodeClient) GetAutofixDiffs ¶
func (f *FakeSnykCodeClient) GetAutofixDiffs(_ context.Context, _ string, _ AutofixOptions) (unifiedDiffSuggestions []AutofixUnifiedDiffSuggestion, status AutofixStatus, err error)
func (*FakeSnykCodeClient) GetAutofixSuggestions ¶
func (f *FakeSnykCodeClient) GetAutofixSuggestions( _ context.Context, options AutofixOptions, _ string, ) ([]AutofixSuggestion, AutofixStatus, error)
func (*FakeSnykCodeClient) GetCallParams ¶
func (f *FakeSnykCodeClient) GetCallParams(callNo int, op string) []any
func (*FakeSnykCodeClient) GetFilters ¶
func (f *FakeSnykCodeClient) GetFilters(_ context.Context) ( filters FiltersResponse, err error, )
func (*FakeSnykCodeClient) RunAnalysis ¶
func (f *FakeSnykCodeClient) RunAnalysis( _ context.Context, options AnalysisOptions, _ string, ) ([]snyk.Issue, AnalysisStatus, error)
func (*FakeSnykCodeClient) SubmitAutofixFeedback ¶
type FiltersResponse ¶
type HtmlRenderer ¶
type HtmlRenderer struct {
// contains filtered or unexported fields
}
func NewHtmlRenderer ¶
func NewHtmlRenderer(c *config.Config) (*HtmlRenderer, error)
func (*HtmlRenderer) GetDetailsHtml ¶
func (renderer *HtmlRenderer) GetDetailsHtml(issue snyk.Issue) string
type IgnoreDetail ¶
type IssueEnhancer ¶
type IssueEnhancer struct { SnykCode SnykCodeClient // contains filtered or unexported fields }
type SarifConverter ¶
type SarifConverter 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 SnykApiClient snyk_api.SnykApiClient // contains filtered or unexported fields }
func New ¶
func New(bundleUploader *BundleUploader, apiClient snyk_api.SnykApiClient, reporter codeClientObservability.ErrorReporter, learnService learn.Service, notifier notification.Notifier, codeScanner codeClient.CodeScanner) *Scanner
func (*Scanner) AddBundleHash ¶
func (*Scanner) BundleHashes ¶
func (*Scanner) ClearIssues ¶
func (*Scanner) DeltaScanningEnabled ¶
func (*Scanner) GetAutofixDiffs ¶
func (*Scanner) IsProviderFor ¶
func (sc *Scanner) IsProviderFor(issueType product.FilterableIssueType) bool
func (*Scanner) Issues ¶
func (sc *Scanner) Issues() snyk.IssuesByFile
func (*Scanner) IssuesForRange ¶
func (*Scanner) RegisterCacheRemovalHandler ¶
func (*Scanner) SupportedCommands ¶
func (sc *Scanner) SupportedCommands() []types.CommandName
func (*Scanner) UploadAndAnalyze ¶
type SnykAnalysisFailedError ¶
type SnykAnalysisFailedError struct {
Msg string
}
func (SnykAnalysisFailedError) Error ¶
func (e SnykAnalysisFailedError) Error() string
type SnykAutofixFailedError ¶
type SnykAutofixFailedError struct {
Msg string
}
Should implement `error` interface
func (SnykAutofixFailedError) Error ¶
func (e SnykAutofixFailedError) Error() string
type SnykCodeClient ¶
type SnykCodeClient 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, ) ( []snyk.Issue, AnalysisStatus, error, ) GetAutofixSuggestions( ctx context.Context, options AutofixOptions, baseDir string, ) ([]AutofixSuggestion, AutofixStatus, error, ) SubmitAutofixFeedback(ctx context.Context, fixId string, result string) error GetAutofixDiffs(ctx context.Context, baseDir string, options AutofixOptions) ( unifiedDiffSuggestions []AutofixUnifiedDiffSuggestion, status AutofixStatus, err error, ) // contains filtered or unexported methods }
type SnykCodeHTTPClient ¶
type SnykCodeHTTPClient struct {
// contains filtered or unexported fields
}
func NewSnykCodeHTTPClient ¶
func NewSnykCodeHTTPClient( c *config.Config, instrumentor codeClientObservability.Instrumentor, errorReporter codeClientObservability.ErrorReporter, client func() *http.Client, ) *SnykCodeHTTPClient
func (*SnykCodeHTTPClient) CreateBundle ¶
func (*SnykCodeHTTPClient) ExtendBundle ¶
func (s *SnykCodeHTTPClient) ExtendBundle( ctx context.Context, bundleHash string, files map[string]BundleFile, removedFiles []string, ) (string, []string, error)
func (*SnykCodeHTTPClient) GetAutofixDiffs ¶
func (s *SnykCodeHTTPClient) GetAutofixDiffs(ctx context.Context, baseDir string, options AutofixOptions) ( unifiedDiffSuggestions []AutofixUnifiedDiffSuggestion, status AutofixStatus, err error, )
func (*SnykCodeHTTPClient) GetAutofixSuggestions ¶
func (s *SnykCodeHTTPClient) GetAutofixSuggestions( ctx context.Context, options AutofixOptions, baseDir string, ) (autofixSuggestions []AutofixSuggestion, status AutofixStatus, err error, )
func (*SnykCodeHTTPClient) GetFilters ¶
func (s *SnykCodeHTTPClient) GetFilters(ctx context.Context) ( filters FiltersResponse, err error, )
func (*SnykCodeHTTPClient) RunAnalysis ¶
func (s *SnykCodeHTTPClient) RunAnalysis( ctx context.Context, options AnalysisOptions, baseDir string, ) ([]snyk.Issue, AnalysisStatus, error)
func (*SnykCodeHTTPClient) RunAutofix ¶
func (s *SnykCodeHTTPClient) RunAutofix(ctx context.Context, options AutofixOptions) (AutofixResponse, error)
func (*SnykCodeHTTPClient) SubmitAutofixFeedback ¶
type SpanRecorderCode ¶
type SpanRecorderCode interface { Record(span codeClient.Span) Spans() []codeClient.Span ClearSpans() Finish(span codeClient.Span) }
type UploadBatch ¶
type UploadBatch struct {
// contains filtered or unexported fields
}
func NewUploadBatch ¶
func NewUploadBatch() *UploadBatch
type UploadStatus ¶
Source Files ¶
- autofix.go
- bundle.go
- bundle_uploader.go
- cache.go
- code.go
- code_error_reporter.go
- code_html.go
- code_instrumentor.go
- code_tracker.go
- constants.go
- convert.go
- example_commit_fixes.go
- fake_code_client_scanner.go
- fake_snyk_code_api_service.go
- issue_enhancer.go
- path.go
- sarif_utils.go
- sast_enabled.go
- sast_local_engine.go
- settings.go
- snyk_code_http_client.go
- snyk_code_http_client_interface.go
- types.go
- upload_batch.go