analyzer

package
v0.0.0-...-4d495be Latest Latest
Warning

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

Go to latest
Published: Dec 22, 2022 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AnalyzerTableName = "analyzers"

	AnalyzerStatusActive = "active"
)
View Source
const (
	CiscoAPIGuidelines = SpecAnalyzer("guidelines")
	InclusiveLanguage  = SpecAnalyzer("inclusive-language")
	Drift              = SpecAnalyzer("drift")
	Completeness       = SpecAnalyzer("completeness")
	Security           = SpecAnalyzer("security")
)
View Source
const (
	ConfigScoreConfig           = "score_config"
	ConfigServiceNameID         = "service_name_id"
	ConfigServiceNameIDTemplate = "service_name_id_template"
)
View Source
const (
	ScoreCategoryAPISecurity = "api-specification"

	SACSeverityCritical = "CRITICAL"
	SACSeverityHigh     = "HIGH"
	SACSeverityMedium   = "MEDIUM"
	SACSeverityLow      = "LOW"
	SACSeverityUnknown  = "UNKNOWN"
)
View Source
const (
	AnalyzerRuleTableName = "analyzer_rules"
)

Variables

This section is empty.

Functions

func ListToMap

func ListToMap(list []*Analyzer) map[SpecAnalyzer]*Analyzer

Types

type APIClarityConfig

type APIClarityConfig struct {
}

type APIClarityDriftResult

type APIClarityDriftResult struct {
	Events []*models2.APIEvent

	EventProvidedSpecDiffs []*models2.APIEventSpecDiff
}

func (*APIClarityDriftResult) Result

func (m *APIClarityDriftResult) Result() (*Result, error)

type Analyzer

type Analyzer struct {
	ID          string            `json:"id,omitempty" gorm:"column:id;primaryKey"`
	NameID      string            `json:"name_id" gorm:"column:name_id;unique;index"`
	Title       string            `json:"title" gorm:"column:title"`
	Description string            `json:"description" gorm:"column:description"`
	Status      string            `json:"status" gorm:"column:status;index"`
	Meta        datatypes.JSONMap `json:"meta" gorm:"column:meta"`
	Config      Config            `json:"config" gorm:"column:config"`
	CreatedAt   time.Time         `json:"created_at" gorm:"column:created_at"`
	UpdatedAt   time.Time         `json:"updated_at" gorm:"column:updated_at"`
	Position    int               `json:"position" gorm:"column:position"`

	Rules []*Rule `json:"rules" gorm:"foreignKey:AnalyzerNameID;references:NameID;constraint:OnUpdate:CASCADE,OnDelete:SET NULL;"`
}

Analyzer represents an analyzer

func (*Analyzer) BeforeCreate

func (m *Analyzer) BeforeCreate(tx *gorm.DB) (err error)

func (*Analyzer) BeforeSave

func (m *Analyzer) BeforeSave(tx *gorm.DB) (err error)

func (*Analyzer) GetID

func (m *Analyzer) GetID() string

GetID returns the ID of analyzer object

func (*Analyzer) GetIndex

func (m *Analyzer) GetIndex(field string) string

GetIndex returns an index for specific field

func (*Analyzer) GetIndexValue

func (m *Analyzer) GetIndexValue(field string) string

GetIndexValue return index value for specified field

func (*Analyzer) GetIndexValues

func (m *Analyzer) GetIndexValues() map[string]string

GetIndexValues return all field index values

func (*Analyzer) GetIndexes

func (m *Analyzer) GetIndexes() map[string]string

GetIndexes returns all the field indexes

func (*Analyzer) GetTags

func (m *Analyzer) GetTags() []string

GetTags returns all the tags

func (*Analyzer) Sortable

func (m *Analyzer) Sortable(field string) bool

Sortable checks if field is sortable.

func (*Analyzer) SortableFields

func (m *Analyzer) SortableFields() map[string]struct{}

SortableFields returns all sortable fields

func (*Analyzer) String

func (m *Analyzer) String() string

String returns the text representation of analyzer object

func (*Analyzer) TableName

func (m *Analyzer) TableName() string

TableName implements gorm Tabler interface

type AnalyzersScoreConfigs

type AnalyzersScoreConfigs map[SpecAnalyzer]*ScoreConfig

func NewAnalyzersScoreConfigsFrom

func NewAnalyzersScoreConfigsFrom(analyzers map[SpecAnalyzer]*Analyzer) (AnalyzersScoreConfigs, error)

type Config

type Config map[string]interface{}

func (Config) GetScoreConfig

func (c Config) GetScoreConfig() *ScoreConfig

func (*Config) Scan

func (c *Config) Scan(value interface{}) error

Scan implements sql.Scanner interface. See https://gorm.io/docs/data_types.html#Implements-Customized-Data-Type.

func (Config) ServiceNameID

func (c Config) ServiceNameID() string

func (Config) ServiceNameIDFromTemplate

func (c Config) ServiceNameIDFromTemplate(serviceNameID string) string

func (Config) ServiceNameIDTemplate

func (c Config) ServiceNameIDTemplate() string

func (Config) UnmarshalInto

func (c Config) UnmarshalInto(v interface{}) error

func (Config) Value

func (c Config) Value() (driver.Value, error)

Value implements driver.Valuer interface. See https://gorm.io/docs/data_types.html#Implements-Customized-Data-Type.

type Finding

type Finding struct {
	Type  rule.FindingType      `json:"type"`
	Path  []string              `json:"path"`
	Range *FindingPositionRange `json:"range,omitempty"`
	Diff  *FindingDiff          `json:"diff,omitempty"`
}

type FindingDiff

type FindingDiff struct {
	Old string `json:"old"`
	New string `json:"new"`
}

type FindingPosition

type FindingPosition struct {
	Line   int `json:"line"`
	Column int `json:"column"`
}

type FindingPositionRange

type FindingPositionRange struct {
	Start *FindingPosition `json:"start"`
	End   *FindingPosition `json:"end"`
}

FindingPositionRange represents

type Findings

type Findings struct {
	Message    string     `json:"message"`
	Mitigation string     `json:"mitigation"`
	Data       []*Finding `json:"data"`
}

type Result

type Result struct {
	Summary  *ResultSummary       `json:"summary" gorm:"column:summary"`
	Findings SeverityRuleFindings `json:"findings" gorm:"column:findings"`
	// contains filtered or unexported fields
}

Result represents the result of a models.SpecAnalysis.

func GetSecurityResult

func GetSecurityResult(spec string, in *models.APIServiceDrillDownExternal) (*Result, error)

func NewResult

func NewResult() *Result

NewResult constructs a new Result.

func (Result) AddFinding

func (r Result) AddFinding(severity rule.SeverityName, ruleNameID rule.NameID, finding *Finding)

type ResultSummary

type ResultSummary struct {
	Stats *SeverityRuleFindingsStats `json:"stats"`
}

ResultSummary represents a summary of Result.Findings.

func NewResultSummary

func NewResultSummary() *ResultSummary

NewResultSummary constructs a new ResultSummary with default stats initialized.

type Resulter

type Resulter interface{ Result() (*Result, error) }

type Rule

type Rule struct {
	ID             string            `json:"id,omitempty" gorm:"column:id;primaryKey"`
	NameID         string            `json:"name_id" gorm:"column:name_id;unique;index"`
	AnalyzerNameID string            `json:"analyzer_name_id" gorm:"column:analyzer_name_id;index"`
	Title          string            `json:"title" gorm:"column:title"`
	Description    string            `json:"description" gorm:"column:description"`
	Severity       string            `json:"severity" gorm:"column:severity"`
	Mitigation     string            `json:"mitigation" gorm:"column:mitigation"`
	Meta           datatypes.JSONMap `json:"meta" gorm:"column:meta"`
	CreatedAt      time.Time         `json:"created_at" gorm:"column:created_at"`
	UpdatedAt      time.Time         `json:"updated_at" gorm:"column:updated_at"`
}

Rule represents an analyzer rule

func (*Rule) BeforeCreate

func (m *Rule) BeforeCreate(tx *gorm.DB) (err error)

func (*Rule) GetID

func (m *Rule) GetID() string

GetID returns the ID of analyzerRule object

func (*Rule) GetIndex

func (m *Rule) GetIndex(field string) string

GetIndex returns an index for specific field

func (*Rule) GetIndexValue

func (m *Rule) GetIndexValue(field string) string

GetIndexValue return index value for specified field

func (*Rule) GetIndexValues

func (m *Rule) GetIndexValues() map[string]string

GetIndexValues return all field index values

func (*Rule) GetIndexes

func (m *Rule) GetIndexes() map[string]string

GetIndexes returns all the field indexes

func (*Rule) GetTags

func (m *Rule) GetTags() []string

GetTags returns all the tags

func (*Rule) Sortable

func (m *Rule) Sortable(field string) bool

Sortable checks if field is sortable.

func (*Rule) SortableFields

func (m *Rule) SortableFields() map[string]struct{}

SortableFields returns all sortable fields

func (*Rule) String

func (m *Rule) String() string

String returns the text representation of analyzerRule object

func (*Rule) TableName

func (m *Rule) TableName() string

TableName implements gorm Tabler interface

type RuleFindings

type RuleFindings struct {
	Rules map[rule.NameID]*Findings `json:"rules"`
}

type RuleFindingsStats

type RuleFindingsStats struct {
	Count       int                 `json:"count"`
	Occurrences int                 `json:"occurrences"`
	Data        map[rule.NameID]int `json:"rules"`
}

RuleFindingsStats contains stats of RuleFindings.

type ScoreConfig

type ScoreConfig struct {
	AnalyzerWeight  *float32                  `json:"analyzer_weight"`
	SeverityWeights map[rule.SeverityName]int `json:"severity_weights"`
}

func NewScoreConfig

func NewScoreConfig(setDefaults bool) *ScoreConfig

type SecurityConfig

type SecurityConfig struct {
	Name string // composed sac external api name, e.g. carts.api.apiregistry
}

type SecurityFinding

type SecurityFinding struct {
	Severity           string        `json:"severity"`
	Kind               string        `json:"kind"`
	Type               string        `json:"type"`
	Code               string        `json:"code"`
	Message            string        `json:"message"`
	Location           []interface{} `json:"location"`
	CrRawFindingID     string        `json:"cr_raw_finding_id"`
	CrFindingIndex     int           `json:"cr_finding_index"`
	AffectedEndpoints  []interface{} `json:"affected_endpoints"`
	Source             string        `json:"source"`
	SeverityCategory   string        `json:"severity_category"`
	CrankshaftClassID  string        `json:"crankshaft_class_id"`
	CrankshaftSeverity string        `json:"crankshaft_severity"`
	CrankshaftCategory string        `json:"crankshaft_category"`
	CrankshaftJsonpath string        `json:"crankshaft_jsonpath"`
}

func NewSecurityFindingData

func NewSecurityFindingData(sf *models.ScoreFinding) (data []*SecurityFinding, err error)

func (*SecurityFinding) JSONPaths

func (m *SecurityFinding) JSONPaths() []string

type SeverityRuleFindings

type SeverityRuleFindings map[rule.SeverityName]*RuleFindings

SeverityRuleFindings defines a grouping of rule findings by their severities.

func NewSeverityRuleFindings

func NewSeverityRuleFindings() SeverityRuleFindings

NewSeverityRuleFindings constructs a new SeverityRuleFindings with default severities initialized.

type SeverityRuleFindingsStats

type SeverityRuleFindingsStats struct {
	Count       int                `json:"count"`
	Occurrences int                `json:"occurrences"`
	Hint        *RuleFindingsStats `json:"hint"`
	Info        *RuleFindingsStats `json:"info"`
	Warning     *RuleFindingsStats `json:"warning"`
	Error       *RuleFindingsStats `json:"error"`
}

SeverityRuleFindingsStats contains stats of SeverityRuleFindings.

type SpecAnalyzer

type SpecAnalyzer string

SpecAnalyzer represents the name of a spec analyzer.

type SpectralConfig

type SpectralConfig struct {
	Ruleset *string // choose a ruleset [string] [choices: "cisco", "cisco-without-oas", "cx", "cx-without-oas", "cx-dictionary"] [default: "cisco-without-oas"]
}

func (*SpectralConfig) SetDefaults

func (c *SpectralConfig) SetDefaults()

func (*SpectralConfig) SetRuleset

func (c *SpectralConfig) SetRuleset(ruleset string)

type SpectralResult

type SpectralResult []*SpectralResultItem

func (SpectralResult) Result

func (m SpectralResult) Result() (*Result, error)

type SpectralResultItem

type SpectralResultItem struct {
	Code     string   `json:"code"`
	Path     []string `json:"path"`
	Message  string   `json:"message"`
	Severity int      `json:"severity"`
	Range    struct {
		Start struct {
			Line      int `json:"line"`
			Character int `json:"character"`
		} `json:"start"`
		End struct {
			Line      int `json:"line"`
			Character int `json:"character"`
		} `json:"end"`
	} `json:"range"`
	Source string `json:"source"`
}

type WokeConfig

type WokeConfig struct {
	Config              string // Config file (default is .woke.yaml in current directory, or $HOME)
	DisableDefaultRules bool   // Disable the default ruleset
	ExitOneOnFailure    bool   // Exit with exit code 1 on failures
	NoIgnore            bool   // Ignored files in .gitignore, .ignore, .wokeignore, .git/info/exclude, and inline ignores are processed
	OutputName          string // Output type [text,simple,github-actions,json,sonarqube]
}

func (*WokeConfig) SetDefaults

func (c *WokeConfig) SetDefaults()

type WokeResult

type WokeResult struct {
	Filename string `json:"Filename"`
	Results  []struct {
		Rule struct {
			Name         string   `json:"Name"`
			Terms        []string `json:"Terms"`
			Alternatives []string `json:"Alternatives"`
			Note         string   `json:"Note"`
			Severity     string   `json:"Severity"`
			Options      struct {
				WordBoundary      bool        `json:"WordBoundary"`
				WordBoundaryStart bool        `json:"WordBoundaryStart"`
				WordBoundaryEnd   bool        `json:"WordBoundaryEnd"`
				IncludeNote       bool        `json:"IncludeNote"`
				Categories        interface{} `json:"Categories"`
			} `json:"Options"`
		} `json:"Rule"`
		Finding       string `json:"Finding"`
		Line          string `json:"Line"`
		StartPosition struct {
			Filename string `json:"Filename"`
			Offset   int    `json:"Offset"`
			Line     int    `json:"Line"`
			Column   int    `json:"Column"`
		} `json:"StartPosition"`
		EndPosition struct {
			Filename string `json:"Filename"`
			Offset   int    `json:"Offset"`
			Line     int    `json:"Line"`
			Column   int    `json:"Column"`
		} `json:"EndPosition"`
		Reason string `json:"Reason"`
	} `json:"Results"`
}

func (*WokeResult) Result

func (m *WokeResult) Result() (*Result, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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