Documentation ¶
Index ¶
- Constants
- Variables
- type Error
- type EvalRuleResult
- type Linter
- type LinterPlugin
- type LinterResult
- type LinterRule
- type PluginResult
- type Repository
- func (r *Repository) Count(ctx context.Context, query string) (int, error)
- func (r *Repository) Create(ctx context.Context, linter Linter) (Linter, error)
- func (r *Repository) Delete(ctx context.Context, id id.ID) error
- func (r *Repository) Get(ctx context.Context, id id.ID) (Linter, error)
- func (r *Repository) GetDefault(ctx context.Context) Linter
- func (r *Repository) List(ctx context.Context, take, skip int, query, sortBy, sortDirection string) ([]Linter, error)
- func (r *Repository) Provision(ctx context.Context, linter Linter) error
- func (r *Repository) SetID(linters Linter, id id.ID) Linter
- func (*Repository) SortingFields() []string
- func (r *Repository) Update(ctx context.Context, linter Linter) (Linter, error)
- type Result
- type RuleResult
Constants ¶
View Source
const ( ResourceName = "Analyzer" ResourceNamePlural = "Analyzers" )
Variables ¶
View Source
var ( // plugins StandardsID = "standards" CommonID = "common" SecurityID = "security" // rules EnsureSpanNamingRuleID string = "span-naming" RequiredAttributesRuleID string = "required-attributes" EnsureAttributeNamingRuleID string = "attribute-naming" NotEmptyAttributesRuleID string = "no-empty-attributes" EnforceDnsRuleID string = "prefer-dns" EnforceHttpsProtocolRuleID string = "secure-https-protocol" EnsuresNoApiKeyLeakRuleID string = "no-api-key-leak" ErrorLevelWarning string = "warning" ErrorLevelError string = "error" ErrorLevelDisabled string = "disabled" SortWeight = map[string]int{ ErrorLevelError: 2, ErrorLevelWarning: 1, ErrorLevelDisabled: 0, } DefaultPlugins = []LinterPlugin{ StandardsPlugin, CommonPlugin, SecurityPlugin, } AvailablePlugins = []string{StandardsPlugin.ID, CommonPlugin.ID, SecurityPlugin.ID} // standards StandardsPlugin = LinterPlugin{ ID: StandardsID, Name: "OTel Semantic Conventions", Description: "Enforce trace standards following OTel Semantic Conventions", Enabled: true, Rules: []LinterRule{ EnsureSpanNamingRule, RequiredAttributesRule, EnsureAttributeNamingRule, NotEmptyAttributesRule, }, } EnsureSpanNamingRule = LinterRule{ ID: EnsureSpanNamingRuleID, Name: "Span Naming", Description: "Enforce span names that identify a class of Spans", ErrorDescription: "", Tips: []string{}, Weight: 25, ErrorLevel: "error", } RequiredAttributesRule = LinterRule{ ID: RequiredAttributesRuleID, Name: "Required Attributes", Description: "Enforce required attributes by span type", ErrorDescription: "This span is missing the following required attributes:", Tips: []string{"This rule checks if all required attributes are present in spans of given type"}, Weight: 25, ErrorLevel: "error", } EnsureAttributeNamingRule = LinterRule{ ID: EnsureAttributeNamingRuleID, Name: "Attribute Naming", Description: "Enforce attribute keys to follow common specifications", ErrorDescription: "The following attributes do not follow the naming convention:", Tips: []string{ "You should always add namespaces to your span names to ensure they will not be overwritten", "Use snake_case to separate multi-words. Ex: http.status_code instead of http.statusCode", }, Weight: 25, ErrorLevel: "error", } NotEmptyAttributesRule = LinterRule{ ID: NotEmptyAttributesRuleID, Name: "No Empty Attributes", Description: "Disallow empty attribute values", ErrorDescription: "The following attributes are empty:", Tips: []string{"Empty attributes don't provide any information about the operation and should be removed"}, Weight: 25, ErrorLevel: "error", } // common CommonPlugin = LinterPlugin{ ID: CommonID, Name: "Common Problems", Description: "Help you find common mistakes with your application", Enabled: true, Rules: []LinterRule{ EnforceDnsRule, }, } EnforceDnsRule = LinterRule{ ID: EnforceDnsRuleID, Name: "Prefer DNS", Description: "Enforce usage of DNS instead of IP addresses", ErrorDescription: "The following attributes are using IP addresses instead of DNS:", Tips: []string{}, Weight: 100, ErrorLevel: "error", } // security SecurityPlugin = LinterPlugin{ ID: SecurityID, Name: "Security", Description: "Help you find security problems with your application", Enabled: true, Rules: []LinterRule{ EnforceHttpsProtocolRule, EnsuresNoApiKeyLeakRule, }, } EnforceHttpsProtocolRule = LinterRule{ ID: EnforceHttpsProtocolRuleID, Name: "Secure HTTPS Protocol", Description: "Enforce usage of secure protocol for HTTP server spans", ErrorDescription: "The following attributes are using insecure http protocol:", Tips: []string{}, Weight: 30, ErrorLevel: "error", } EnsuresNoApiKeyLeakRule = LinterRule{ ID: EnsuresNoApiKeyLeakRuleID, Name: "No API Key Leak", Description: "Disallow leaked API keys for HTTP spans", ErrorDescription: "The following attributes are exposing API keys:", Tips: []string{}, Weight: 70, ErrorLevel: "error", } )
Functions ¶
This section is empty.
Types ¶
type EvalRuleResult ¶
type Linter ¶
type Linter struct { ID id.ID `json:"id"` Name string `json:"name"` Enabled bool `json:"enabled"` MinimumScore int `json:"minimumScore"` Plugins []LinterPlugin `json:"plugins"` }
func GetDefaultLinter ¶
func GetDefaultLinter() Linter
func (Linter) EnabledPlugins ¶
func (l Linter) EnabledPlugins() []LinterPlugin
func (Linter) ShouldSkip ¶
func (Linter) WithMetadata ¶
type LinterPlugin ¶
type LinterPlugin struct { ID string `json:"id"` Enabled bool `json:"enabled"` Rules []LinterRule `json:"rules"` // internal fields Name string `json:"name"` Description string `json:"description"` }
type LinterResult ¶
type LinterResult struct { Plugins []PluginResult `json:"plugins"` Score int `json:"score"` MinimumScore int `json:"minimumScore"` Passed bool `json:"passed"` }
func NewLinterResult ¶
func NewLinterResult(pluginResults []PluginResult, totalScore int, passed bool) LinterResult
type LinterRule ¶
type PluginResult ¶
type PluginResult struct { // metadata ID string `json:"id"` Name string `json:"name"` Description string `json:"description"` //results Passed bool `json:"passed"` Score int `json:"score"` Rules []RuleResult `json:"rules"` }
func (PluginResult) CalculateResults ¶
func (pr PluginResult) CalculateResults() PluginResult
type Repository ¶
type Repository struct {
// contains filtered or unexported fields
}
func NewRepository ¶
func NewRepository(db *sql.DB) *Repository
func (*Repository) GetDefault ¶
func (r *Repository) GetDefault(ctx context.Context) Linter
func (*Repository) Provision ¶
func (r *Repository) Provision(ctx context.Context, linter Linter) error
func (*Repository) SortingFields ¶
func (*Repository) SortingFields() []string
type RuleResult ¶
type RuleResult struct { // config ID string `json:"id"` Name string `json:"name"` Description string `json:"description"` ErrorDescription string `json:"errorDescription"` Tips []string `json:"tips"` Weight int `json:"weight"` Level string `json:"level"` // results Passed bool `json:"passed"` Results []Result `json:"results"` }
func NewRuleResult ¶
func NewRuleResult(config LinterRule, results EvalRuleResult) RuleResult
func SortRules ¶
func SortRules(rules []RuleResult, sortWeight map[string]int) []RuleResult
Click to show internal directories.
Click to hide internal directories.