settings

package
v1.6.1-0...-ba2f3a6 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2026 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package settings is the tool settings contract: what a scan tool lets an administrator configure, declared as a small JSON Schema in the "config" of its tool manifest, and the layered values a scan runs with.

The schema language is a closed subset of JSON Schema 2020-12 plus x-octm-* annotations. Anything outside the subset makes the schema invalid, so a schema cannot hide a field behind $ref, oneOf or a conditional. The platform validates what an administrator enters with this package and the sensor validates it again before a task uses it; both import the same code, so the two can never disagree.

Annotations:

  • x-octm-scope ("sensor" | "scan"): the lowest layer allowed to set the key;
  • x-octm-tier ("T0" | "T1" | "T2"): the safety class of a non-default value: T0 safe, T1 impact (more load or reach on the target), T2 dangerous (intrusive; needs the tenant's explicit enablement and a T2 scan);
  • x-octm-common: the property is one of the common tool options of package tooloption (its type and bounds are checked against it); a property named like a common option must declare it;
  • x-octm-flag: the tool's native flag the value maps to ("-rate-limit"), shown in the effective configuration of a job; the tool's adapter still builds the argv itself, from typed values;
  • x-octm-sensitive, x-octm-restart, x-octm-group, x-octm-order, x-octm-widget: presentation and handling.

Layers (Resolve): the tool's defaults, then the sensor's configuration, then a scan profile or workflow step, then the scan, then the platform's decision for one job. For a common option that narrows down (rate, concurrency, retries), a later layer may only lower what an earlier layer set; a raise is an error, never silently applied.

The test vectors in testdata/vectors pin the verdicts, error paths, defaults and digests.

Index

Constants

View Source
const (
	// MaxSchemaBytes bounds a schema document.
	MaxSchemaBytes = 32 << 10
	// MaxProperties bounds the properties of a schema, nested ones
	// included.
	MaxProperties = 64
	// MaxEnum bounds an enum.
	MaxEnum = 256
	// MaxPatternLen bounds a pattern's length.
	MaxPatternLen = 512
	// MaxStringLen bounds any string value (a maxLength, when set,
	// may only lower it).
	MaxStringLen = 4096
	// MaxItems bounds any array value (a maxItems, when set, may
	// only lower it).
	MaxItems = 256
)

Limits of a settings schema.

Variables

This section is empty.

Functions

func DocumentDigest

func DocumentDigest(raw []byte) (string, error)

DocumentDigest is the canonical digest of any JSON document (a values document, a settings document): "sha256:" + hex SHA-256 of its canonical JSON, as for Schema.Digest.

func ValidName

func ValidName(name string) bool

ValidName reports whether name is a well-formed setting key name (^[a-z][a-z0-9_]{0,63}$).

Types

type Error

type Error struct {
	Path    string
	Message string
}

Error is one invalid value. Path is a JSON pointer into the values document ("/rate_limit", "/group/key", "/tags/2").

type Errors

type Errors []Error

Errors is every problem of a values document, sorted by path.

func (Errors) Error

func (e Errors) Error() string

func (Errors) Paths

func (e Errors) Paths() []string

Paths returns the error paths.

type Layer

type Layer struct {
	Source Source
	Values map[string]any
}

Layer is one level of values, applied over the ones below it.

type Property

type Property struct {
	Name        string
	Title       string
	Description string
	// Type is "boolean", "integer", "number", "string", "array" or
	// "object" (a group of keys, one level deep); empty for a key that only
	// has enum or const.
	Type string
	// Items describes an array's elements.
	Items *Property
	// Properties are a group's keys, sorted by name.
	Properties []*Property
	Required   []string
	Enum       []any
	Const      any
	HasConst   bool
	Default    any
	HasDefault bool

	Minimum, Maximum                   *float64
	ExclusiveMinimum, ExclusiveMaximum *float64
	MultipleOf                         *float64
	MinLength, MaxLength               *int
	MinItems, MaxItems                 *int
	UniqueItems                        bool
	Pattern                            string
	Format                             string

	Deprecated bool
	WriteOnly  bool
	Scope      Scope
	// Tier is the minimum tier whose policy permits a non-default value
	// ("T0", "T1", "T2"); empty: any tier.
	Tier      string
	Sensitive bool
	Restart   bool
	Group     string
	Order     int
	Widget    string
	// Common is the common tool option (package tooloption) the key is,
	// "" for a key specific to the tool. Top-level keys only.
	Common string
	// Flag is the tool's native flag the value maps to ("-rate-limit"):
	// shown in a job's effective configuration, never used to build argv.
	Flag string
	// contains filtered or unexported fields
}

Property is one key of a schema.

type Schema

type Schema struct {
	// Raw is the schema document as declared.
	Raw json.RawMessage
	// Version is x-octm-schema-version: it increases when a key is removed
	// or narrowed.
	Version int
	// Title and Description describe the tool's settings.
	Title       string
	Description string
	// Properties are the top-level keys, sorted by name.
	Properties []*Property
	// Required are the keys that must have a value (given or default).
	Required []string
	// contains filtered or unexported fields
}

Schema is a tool's parsed settings schema.

func MustParseSchema

func MustParseSchema(raw string) *Schema

MustParseSchema is ParseSchema for a schema compiled into the program; it panics on an invalid one (a programming error).

func ParseSchema

func ParseSchema(raw []byte) (*Schema, error)

ParseSchema parses and checks a schema: the allowed keywords only, additionalProperties false on every object, one level of grouping, defaults and enums that satisfy their own constraints, RE2 patterns, and the size limits.

func (*Schema) Defaults

func (s *Schema) Defaults() map[string]any

Defaults returns every key that has a default, groups as nested objects. The map is the caller's.

func (*Schema) Digest

func (s *Schema) Digest() string

Digest is "sha256:" + the hex SHA-256 of the schema's canonical JSON (object members sorted, no insignificant whitespace, numbers as written, no HTML escaping). The manifest carries it; the platform stores schemas by it.

func (*Schema) Property

func (s *Schema) Property(path string) *Property

Property returns a key by its path ("rate_limit", "group.key"), or nil.

func (*Schema) Resolve

func (s *Schema) Resolve(layers ...Layer) (*Values, error)

Resolve computes the effective settings: the defaults, then each layer in order (sensor, then profile, then scan). Each layer must be valid on its own, and a profile or scan layer may set only keys whose scope is "scan". A nil schema gives empty settings (the tool's own defaults).

func (*Schema) Validate

func (s *Schema) Validate(values map[string]any) error

Validate checks a values document: every key known, every value of the right type and within its constraints, sensitive keys absent (secrets never travel as plain values), and every required key given or defaulted. The error is Errors with every problem.

func (*Schema) ValidateJSON

func (s *Schema) ValidateJSON(raw []byte) error

ValidateJSON is Validate for a JSON object (numbers kept exact).

type SchemaError

type SchemaError struct {
	Path    string
	Message string
}

SchemaError is why a schema is invalid. Path is a JSON pointer into the schema document.

func (*SchemaError) Error

func (e *SchemaError) Error() string

type Scope

type Scope string

Scope is the lowest level allowed to set a key.

const (
	// ScopeSensor: only the sensor's own settings may set the key
	// (the default).
	ScopeSensor Scope = "sensor"
	// ScopeScan: the sensor's settings, a scan profile and a scan may
	// set the key.
	ScopeScan Scope = "scan"
)

Setting scopes (x-octm-scope).

type Source

type Source string

Source is where an effective value came from.

const (
	SourceDefault Source = "default"
	// SourceTenant: the tenant's policy for every sensor.
	SourceTenant  Source = "tenant"
	SourceSensor  Source = "sensor"
	SourceProfile Source = "profile"
	SourceScan    Source = "scan"
	// SourceJob: the platform's decision for one job (learned budgets).
	SourceJob Source = "job"
	// SourceLocal: the sensor's local policy, applied last; it only ever
	// lowers a value (its host owner's caps).
	SourceLocal Source = "local"
)

Setting sources, from lowest to highest precedence.

type Values

type Values struct {
	// contains filtered or unexported fields
}

Values are a tool's effective settings for one scan. A nil *Values has no values: every getter reports false and the tool uses its own defaults. Keys of a group are addressed as "group.key".

func (*Values) Bool

func (t *Values) Bool(key string) (bool, bool)

Bool returns a boolean value.

func (*Values) Duration

func (t *Values) Duration(key string) (time.Duration, bool)

Duration returns a string value of format "duration" as a time.Duration.

func (*Values) Float

func (t *Values) Float(key string) (float64, bool)

Float returns a number (or integer) value.

func (*Values) Int

func (t *Values) Int(key string) (int64, bool)

Int returns an integer value.

func (*Values) Keys

func (t *Values) Keys() []string

Keys returns the keys that have a value, sorted.

func (*Values) SchemaDigest

func (t *Values) SchemaDigest() string

SchemaDigest and SchemaVersion identify the schema the settings were resolved against.

func (*Values) SchemaVersion

func (t *Values) SchemaVersion() int

SchemaVersion is the schema's x-octm-schema-version.

func (*Values) Secret

func (t *Values) Secret(string) ([]byte, bool)

Secret returns a sensitive value. Secret settings are not delivered yet, so it always reports false; a tool that asks for one keeps working when they are.

func (*Values) Source

func (t *Values) Source(key string) Source

Source returns where a key's value came from; empty when it has none.

func (*Values) String

func (t *Values) String(key string) (string, bool)

String returns a string value.

func (*Values) Strings

func (t *Values) Strings(key string) ([]string, bool)

Strings returns an array of strings (a copy).

func (*Values) Values

func (t *Values) Values() map[string]any

Values returns a copy of the effective values by key (numbers as json.Number), for a tool that takes its settings as one document (the tool contract's task configuration). nil for nil settings.

Jump to

Keyboard shortcuts

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