model

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: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SeverityHint Severity = iota + 1
	SeverityInfo
	SeverityWarning
	SeverityError

	SeverityNameHint    SeverityName = "hint"
	SeverityNameInfo    SeverityName = "info"
	SeverityNameWarning SeverityName = "warning"
	SeverityNameError   SeverityName = "error"
)
View Source
const (
	DiffOutputJSON     = "json"
	DiffOutputHTML     = "html"
	DiffOutputMarkdown = "markdown"
	DiffOutputText     = "text"
)
View Source
const (
	ActionAdded    = Action("added")
	ActionDeleted  = Action("deleted")
	ActionModified = Action("modified")
)
View Source
const (
	SpecAnalyzerCiscoAPIGuidelines = SpecAnalyzer("guidelines")
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Action

type Action string

type Analyzer

type Analyzer struct {
	ID          string                 `json:"id,omitempty"`
	NameID      string                 `json:"name_id"`
	Title       string                 `json:"title"`
	Description string                 `json:"description"`
	Status      string                 `json:"status"`
	Meta        map[string]interface{} `json:"meta"`
	Position    uint8                  `json:"position"`
	Config      Config                 `json:"config"`
	CreatedAt   time.Time              `json:"created_at"`
	UpdatedAt   time.Time              `json:"updated_at"`

	Rules []AnalyzerRule `json:"rules"`
}

Analyzer represents an analyzer

type AnalyzerConfig

type AnalyzerConfig map[string]interface{}

AnalyzerConfig represents configs for an analyzer (SpecAnalysis.Analyzer)

type AnalyzerConfigMap

type AnalyzerConfigMap map[SpecAnalyzer]Config

type AnalyzerList

type AnalyzerList []*Analyzer

func (AnalyzerList) Print

func (m AnalyzerList) Print(w io.Writer)

type AnalyzerRule

type AnalyzerRule struct {
	ID             string                 `json:"id,omitempty"`
	NameID         string                 `json:"name_id"`
	AnalyzerNameID string                 `json:"analyzer_name_id"`
	Title          string                 `json:"title"`
	Description    string                 `json:"description"`
	Severity       string                 `json:"severity"`
	Mitigation     string                 `json:"mitigation"`
	Meta           map[string]interface{} `json:"meta"`
	CreatedAt      time.Time              `json:"created_at"`
	UpdatedAt      time.Time              `json:"updated_at"`
}

AnalyzerRule represents an analyzer rule

type AnalyzerRuleList

type AnalyzerRuleList []*AnalyzerRule

func (AnalyzerRuleList) Print

func (m AnalyzerRuleList) Print(w io.Writer)

type Config

type Config map[string]interface{}

func (*Config) String

func (c *Config) String() string

type EndpointSummary

type EndpointSummary struct {
	Path        string `json:"path"`
	Method      string `json:"method"`
	Description string `json:"description"`

	Message string `json:"message"`
}

type Finding

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

func (*Finding) End

func (f *Finding) End() string

func (*Finding) JSONPath

func (f *Finding) JSONPath() string

func (*Finding) Start

func (f *Finding) Start() string

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 FindingType

type FindingType string
const (
	FindingTypeRange FindingType = "range"
	FindingTypeDiff              = "diff"
)

type Findings

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

type JSONResult

type JSONResult struct {
	Added      []*EndpointSummary `json:"added"`
	Deleted    []*EndpointSummary `json:"deleted"`
	Deprecated []*EndpointSummary `json:"deprecated"`
	Modified   []*ModifiedSummary `json:"modified"`

	Breaking bool   `json:"breaking"`
	Message  string `json:"message"`
}

type ModifiedSummary

type ModifiedSummary struct {
	Old *OperationSummary `json:"old"`
	New *OperationSummary `json:"new"`

	Path        string `json:"path"`
	Method      string `json:"method"`
	Summary     string `json:"summary"`
	Description string `json:"description"`

	Breaking bool   `json:"breaking"`
	Message  string `json:"message"`

	ParametersSummary  *ParametersSummary  `json:"parameters"`
	RequestBodySummary *RequestBodySummary `json:"requestBody"`
	ResponsesSummary   *ResponsesSummary   `json:"responses"`
	SecuritySummary    *SecuritySummary    `json:"security"`
}

type NameID

type NameID string

type OperationSummary

type OperationSummary struct{ openapi3.Operation }

type ParameterSummary

type ParameterSummary struct {
	Parameter, OldParameter, NewParameter *openapi3.Parameter `json:"-"`

	Name        string `json:"name"`
	In          string `json:"in"`
	Description string `json:"description"`
	Deprecated  bool   `json:"deprecated"` // TODO
	Breaking    bool   `json:"breaking"`
	Action      Action `json:"action"`
	Message     string `json:"message"`
}

type ParametersSummary

type ParametersSummary struct {
	Breaking bool                `json:"breaking"`
	Message  string              `json:"message"`
	Details  []*ParameterSummary `json:"details"`
}

type PropertiesSummary

type PropertiesSummary struct {
	Name        string `json:"name"`
	Type        string `json:"type"`
	Description string `json:"description"`
	Action      Action `json:"action"`
	Breaking    bool   `json:"breaking"`
	Message     string `json:"message"`

	Nested []*PropertiesSummary `json:"properties"`

	Group string `json:"-"` // group that this property belongs to, e.g. items
}

type RequestBodySummary

type RequestBodySummary struct {
	Breaking bool   `json:"breaking"`
	Message  string `json:"message"`

	Description string `json:"description"`

	Details []*RequestBodySummaryDetail `json:"details"`
}

type RequestBodySummaryDetail

type RequestBodySummaryDetail struct {
	ReqBody, OldReqBody, NewReqBody *openapi3.RequestBody `json:"-"`

	Properties []*PropertiesSummary `json:"properties"`

	Breaking bool   `json:"breaking"`
	Action   Action `json:"action"`
	Message  string `json:"message"`
	Name     string `json:"name"`
}

type ResponseSummaryDetail

type ResponseSummaryDetail struct {
	Res *openapi3.Response `json:"-"`

	Description string               `json:"description"`
	Name        string               `json:"name"`
	Action      Action               `json:"action"`
	Breaking    bool                 `json:"breaking"`
	Message     string               `json:"message"`
	Properties  []*PropertiesSummary `json:"properties"`
}

type ResponsesSummary

type ResponsesSummary struct {
	Breaking bool                      `json:"breaking"`
	Message  string                    `json:"message"`
	Details  []*ResponsesSummaryDetail `json:"details"`
}

type ResponsesSummaryDetail

type ResponsesSummaryDetail struct {
	Res, OldRes, NewRes *openapi3.Response `json:"-"`

	Details []*ResponseSummaryDetail `json:"details"`

	Name        string `json:"name"` // status code
	Description string `json:"description"`
	Action      Action `json:"action"`
	Breaking    bool   `json:"breaking"`
	Message     string `json:"message"`
}

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 NewResult

func NewResult() *Result

NewResult constructs a new Result.

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.

func (*ResultSummary) String

func (m *ResultSummary) String() string

type RuleFindings

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

type RuleFindingsStats

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

RuleFindingsStats contains stats of RuleFindings.

type SecuritySummary

type SecuritySummary struct {
	Breaking bool                     `json:"breaking"`
	Message  string                   `json:"message"`
	Details  []*SecuritySummaryDetail `json:"details"`
}

type SecuritySummaryDetail

type SecuritySummaryDetail struct {
	SecReq, OldSecReq, NewSecReq *openapi3.SecurityRequirement `json:"-"`

	Breaking bool   `json:"breaking"`
	Name     string `json:"name"`
	Action   Action `json:"action"`
	Message  string `json:"message"`
}

type Service

type Service struct {
	ID             string                 `json:"id,omitempty"`
	AdditionalInfo map[string]interface{} `json:"additional_info"`
	Contact        interface{}            `json:"contact"`
	Description    string                 `json:"description"`
	NameID         string                 `json:"name_id"`
	OrganizationID string                 `json:"organization_id"`
	ProductTag     string                 `json:"product_tag"`
	Title          string                 `json:"title"`
	CreatedAt      time.Time              `json:"created_at"`
	UpdatedAt      time.Time              `json:"updated_at"`

	AnalyzersConfigs AnalyzerConfigMap `json:"analyzers_configs,omitempty"`
	Summary          *ServiceSummary   `json:"summary"`
}

Service represents a service

type ServiceList

type ServiceList []*Service

func (ServiceList) Print

func (m ServiceList) Print(w io.Writer)

type ServiceSummary

type ServiceSummary struct {
	Score     *int      `json:"score"`
	Version   string    `json:"version"`
	Revision  string    `json:"revision"`
	UpdatedAt time.Time `json:"updated_at"`
}

type Severity

type Severity int

func (Severity) Name

func (s Severity) Name() SeverityName

func (Severity) String

func (s Severity) String() string

func (Severity) Weight

func (s Severity) Weight() int

type SeverityName

type SeverityName string

func (SeverityName) Severity

func (n SeverityName) Severity() Severity

func (SeverityName) String

func (n SeverityName) String() string

type SeverityRuleFindings

type SeverityRuleFindings map[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"`
	Hint    *RuleFindingsStats `json:"hint"`
	Info    *RuleFindingsStats `json:"info"`
	Warning *RuleFindingsStats `json:"warning"`
	Error   *RuleFindingsStats `json:"error"`
}

SeverityRuleFindingsStats contains stats of SeverityRuleFindings.

func (*SeverityRuleFindingsStats) TotalError

func (s *SeverityRuleFindingsStats) TotalError() int

func (*SeverityRuleFindingsStats) TotalHint

func (s *SeverityRuleFindingsStats) TotalHint() int

func (*SeverityRuleFindingsStats) TotalInfo

func (s *SeverityRuleFindingsStats) TotalInfo() int

func (*SeverityRuleFindingsStats) TotalWarning

func (s *SeverityRuleFindingsStats) TotalWarning() int

type Spec

type Spec struct {
	ID        string    `json:"id,omitempty" validate:"required"`
	Doc       SpecDoc   `json:"doc"`
	DocType   string    `json:"doc_type"`
	Revision  string    `json:"revision"`
	Score     int       `json:"score"`
	ServiceID string    `json:"service_id"`
	State     string    `json:"state"` // Archive, Releases, Development, Latest
	Valid     string    `json:"valid"`
	Version   string    `json:"version"`
	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
}

Spec represents a spec

type SpecAnalysis

type SpecAnalysis struct {
	ID        string          `json:"id,omitempty" validate:"required"`
	Analyzer  SpecAnalyzer    `json:"analyzer"`
	Config    *AnalyzerConfig `json:"config,omitempty"`
	Result    *Result         `json:"result"`
	Score     int             `json:"score"`
	ServiceID string          `json:"service_id"`
	SpecID    string          `json:"spec_id"`
	Status    string          `json:"status"` // Submitted, Invalid, Analyzed
	CreatedAt time.Time       `json:"created_at"`
	UpdatedAt time.Time       `json:"updated_at"`
}

SpecAnalysis represents a specAnalysis

type SpecAnalysisList

type SpecAnalysisList []*SpecAnalysis

func (SpecAnalysisList) Print

func (m SpecAnalysisList) Print(w io.Writer)

type SpecAnalysisRequest

type SpecAnalysisRequest struct {
	Analyzers        []SpecAnalyzer                   `json:"analyzers"`
	AnalyzersConfigs map[SpecAnalyzer]*AnalyzerConfig `json:"analyzers_configs,omitempty"`

	Spec    *Spec    `json:"spec,omitempty"`
	Service *Service `json:"service,omitempty"`
}

SpecAnalysisRequest represents a request for a SpecAnalysis

type SpecAnalysisResponse

type SpecAnalysisResponse struct {
	Results   map[SpecAnalyzer]*SpecAnalysis `json:"results,omitempty"`
	SpecScore int                            `json:"spec_score"`
}

func (*SpecAnalysisResponse) ExitCode

func (s *SpecAnalysisResponse) ExitCode() int

ExitCode returns exit code as per analysis findings

func (*SpecAnalysisResponse) Print

func (s *SpecAnalysisResponse) Print(w io.Writer, analyzers map[string]*Analyzer)

Print prints results in console

type SpecAnalyzer

type SpecAnalyzer string

type SpecDiff

type SpecDiff struct {
	ID string `json:"id,omitempty" validate:"required"`
	*SpecDiffRequest
	Result    *SpecDiffResult `json:"result"`
	ServiceID string          `json:"service_id,omitempty"`
	Status    string          `json:"status,omitempty"` // Submitted, Invalid, Diffed
	CreatedAt time.Time       `json:"created_at"`
	UpdatedAt time.Time       `json:"updated_at"`
}

SpecDiff represents a specDiff

func (*SpecDiff) HasBreakingChangesInJSON

func (m *SpecDiff) HasBreakingChangesInJSON() bool

type SpecDiffConfig

type SpecDiffConfig struct {
	OutputFormat string `json:"output_format,omitempty"` // json, html, markdown, text
}

SpecDiffConfig represents configs for a SpecDiff (SpecDiff.Config)

type SpecDiffList

type SpecDiffList []*SpecDiff

func (SpecDiffList) Print

func (m SpecDiffList) Print(w io.Writer)

type SpecDiffRequest

type SpecDiffRequest struct {
	NewSpecID string `json:"new_spec_id,omitempty"`
	OldSpecID string `json:"old_spec_id,omitempty"`

	OldSpecDoc SpecDoc `json:"old_spec_doc,omitempty"`
	NewSpecDoc SpecDoc `json:"new_spec_doc,omitempty"`

	Config *SpecDiffConfig `json:"config,omitempty"`
}

type SpecDiffResult

type SpecDiffResult struct {
	JSON     *JSONResult `json:"json,omitempty"`
	HTML     string      `json:"html,omitempty"`
	Markdown string      `json:"markdown,omitempty"`
	Text     string      `json:"text,omitempty"`
}

SpecDiffResult represents the result for a models.SpecDiff (SpecDiff.JSONResult)

func (*SpecDiffResult) Print

func (m *SpecDiffResult) Print(w io.Writer, output string)

type SpecDoc

type SpecDoc *string

func NewSpecDoc

func NewSpecDoc(b []byte) SpecDoc

type SpecList

type SpecList []*Spec

func (SpecList) Print

func (m SpecList) Print(w io.Writer)

Jump to

Keyboard shortcuts

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