analysis

package
v0.0.0-...-31d77f9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 18, 2024 License: BSD-3-Clause Imports: 13 Imported by: 0

Documentation

Overview

Package analysis provides functionality for manipulating inputs and outputs of analysis endpoints.

Index

Constants

View Source
const TableName = "analysis"

Variables

View Source
var SchemaVersion string

SchemaVersion changes whenever the analysis schema changes.

Functions

This section is empty.

Types

type Diagnostic

type Diagnostic struct {
	// The package ID as reported by the analysis binary.
	PackageID    string `bigquery:"package_id"`
	AnalyzerName string `bigquery:"analyzer_name"`
	Error        string `bigquery:"error"`
	// These fields are from internal/worker.JSONDiagnostic.
	Category string        `bigquery:"category"`
	Position string        `bigquery:"position"`
	Message  string        `bigquery:"message"`
	Source   bq.NullString `bigquery:"source"`
}

A Diagnostic is a single analyzer finding.

func JSONTreeToDiagnostics

func JSONTreeToDiagnostics(jsonTree JSONTree) []*Diagnostic

JSONTreeToDiagnostics converts a jsonTree to a list of diagnostics for BigQuery. It ignores the suggested fixes of the diagnostics.

type DiagnosticsOrError

type DiagnosticsOrError struct {
	Diagnostics []JSONDiagnostic
	Error       *jsonError
}

func (*DiagnosticsOrError) UnmarshalJSON

func (de *DiagnosticsOrError) UnmarshalJSON(data []byte) error

type EnqueueParams

type EnqueueParams struct {
	Binary   string // name of analysis binary to run
	Args     string // command-line arguments to binary; split on whitespace
	Insecure bool   // if true, run outside sandbox
	Min      int    // minimum import-by count for a module to be included
	File     string // path to file containing modules; if missing, use DB
	Suffix   string // appended to task queue IDs to generate unique tasks
	User     string // user initiating enqueue
	SkipInit bool   // if true, do not initialize non-module Go projects
}

type JSONDiagnostic

type JSONDiagnostic struct {
	Category       string             `json:"category,omitempty"`
	Posn           string             `json:"posn"`
	Message        string             `json:"message"`
	SuggestedFixes []JSONSuggestedFix `json:"suggested_fixes,omitempty"`
}

A JSONDiagnostic can be used to encode and decode analysis.Diagnostics to and from JSON.

type JSONSuggestedFix

type JSONSuggestedFix struct {
	Message string         `json:"message"`
	Edits   []JSONTextEdit `json:"edits"`
}

A JSONSuggestedFix describes an edit that should be applied as a whole or not at all. It might contain multiple TextEdits/text_edits if the SuggestedFix consists of multiple non-contiguous edits.

type JSONTextEdit

type JSONTextEdit struct {
	Filename string `json:"filename"`
	Start    int    `json:"start"`
	End      int    `json:"end"`
	New      string `json:"new"`
}

A JSONTextEdit describes the replacement of a portion of a file. Start and End are zero-based half-open indices into the original byte sequence of the file, and New is the new text.

type JSONTree

type JSONTree map[string]map[string]DiagnosticsOrError

A JSONTree is a mapping from package ID to analysis name to result. Each result is either a jsonError or a list of JSONDiagnostic.

type Result

type Result struct {
	CreatedAt   time.Time `bigquery:"created_at"`
	ModulePath  string    `bigquery:"module_path"`
	Version     string    `bigquery:"version"`
	SortVersion string    `bigquery:"sort_version"`
	CommitTime  time.Time `bigquery:"commit_time"`
	// The name of the analysis binary that was executed.
	// A single binary may run multiple analyzers.
	BinaryName    string `bigquery:"binary_name"`
	Error         string `bigquery:"error"`
	ErrorCategory string `bigquery:"error_category"`
	WorkVersion          // InferSchema flattens embedded fields

	Diagnostics []*Diagnostic `bigquery:"diagnostic"`
}

Result is a row in the BigQuery analysis table. It corresponds to a result from the output for an analysis.

func ReadResults

func ReadResults(ctx context.Context, c *bigquery.Client, binaryName, binaryVersion, binaryArgs string) (_ []*Result, err error)

func (*Result) AddError

func (r *Result) AddError(err error)

func (*Result) SetUploadTime

func (r *Result) SetUploadTime(t time.Time)

type ScanParams

type ScanParams struct {
	Binary        string // name of analysis binary to run
	BinaryVersion string // hex-encoded binary hash
	Args          string // command-line arguments to binary; split on whitespace
	ImportedBy    int    // imported-by count of module in path
	Insecure      bool   // if true, run outside sandbox
	Serve         bool   // serve results back to client instead of writing them to BigQuery
	JobID         string // ID of job, if non-empty
	SkipInit      bool   // if true, do not initialize non-module Go projects
}

type ScanRequest

type ScanRequest struct {
	scan.ModuleURLPath
	ScanParams
}

func ParseScanRequest

func ParseScanRequest(r *http.Request, prefix string) (*ScanRequest, error)

func (*ScanRequest) Name

func (r *ScanRequest) Name() string

func (*ScanRequest) Params

func (r *ScanRequest) Params() string

func (*ScanRequest) Path

func (r *ScanRequest) Path() string

type WorkVersion

type WorkVersion struct {
	// A hash of the  binary executed.
	BinaryVersion string `bigquery:"binary_version"`
	BinaryArgs    string `bigquery:"binary_args"` // args passed to binary
	// The version of the currently running code. This tracks changes in the
	// logic of module scanning and processing.
	WorkerVersion string `bigquery:"worker_version"`
	// The version of the bigquery schema.
	SchemaVersion string ` bigquery:"schema_version"`
}

WorkVersion contains information that can be used to avoid duplicate work. Given two WorkVersion values v1 and v2 for the same module path and version, if v1 == v2 then it is not necessary to scan the module.

func ReadWorkVersion

func ReadWorkVersion(ctx context.Context, c *bigquery.Client, module_path, version, binary string) (wv *WorkVersion, err error)

ReadWorkVersion reads the most recent WorkVersion in the analysis table for module_path at version for binary.

type WorkVersionKey

type WorkVersionKey struct {
	Module  string
	Version string
	Binary  string
}

WorkVersionKey is the key for a WorkVersion. Always compare two WorkVersions with the same key.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL