config

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2025 License: GPL-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const NoRulesVersion = ""

NoRulesVersion is a source.RulesInfo version implying that no rules are available for this source.

Setting this to the empty string lets comparisons with an empty rule version evaluate to true, which conveniently reduces the amount of rule exchanges between a source and this daemon on a clean setup.

Variables

This section is empty.

Functions

This section is empty.

Types

type ConfigSet

type ConfigSet struct {
	Channels         map[int64]*channel.Channel
	Contacts         map[int64]*recipient.Contact
	ContactAddresses map[int64]*recipient.Address
	Groups           map[int64]*recipient.Group
	TimePeriods      map[int64]*timeperiod.TimePeriod
	Schedules        map[int64]*recipient.Schedule
	Sources          map[int64]*Source
	Rules            map[int64]*rule.Rule

	// RulesBySource maps source IDs to their rules and version information.
	RulesBySource map[int64]*SourceRulesInfo
	// contains filtered or unexported fields
}

type IncrementalConfigurable

type IncrementalConfigurable[PK comparable] interface {
	zapcore.ObjectMarshaler

	// GetPrimaryKey returns the primary key value.
	GetPrimaryKey() PK

	// GetChangedAt returns the changed_at value.
	GetChangedAt() types.UnixMilli

	// IsDeleted returns if this entry was marked as deleted.
	IsDeleted() bool
}

IncrementalConfigurable specifies Getter methods required for types supporting incremental configuration loading.

type IncrementalConfigurableInitAndValidatable

type IncrementalConfigurableInitAndValidatable interface {
	// IncrementalInitAndValidate allows both to initialize and validates with an optional error.
	//
	// If an error is returned, the incrementalFetch function aborts the element in question.
	IncrementalInitAndValidate() error
}

IncrementalConfigurableInitAndValidatable defines a single method for new and updated elements to allow both initialization and validation, to be used within incrementalFetch.

type RuntimeConfig

type RuntimeConfig struct {
	// ConfigSet is the current live config. It is embedded to allow direct access to its members.
	// Accessing it requires a lock that is obtained with RLock() and released with RUnlock().
	ConfigSet
	// contains filtered or unexported fields
}

RuntimeConfig stores the runtime representation of the configuration present in the database.

func NewRuntimeConfig

func NewRuntimeConfig(
	logs *logging.Logging,
	db *database.DB,
) *RuntimeConfig

func (*RuntimeConfig) GetContact

func (r *RuntimeConfig) GetContact(username string) *recipient.Contact

GetContact returns *recipient.Contact by the given username (case-insensitive). Returns nil when the given username doesn't exist.

func (*RuntimeConfig) GetRecipient

func (r *RuntimeConfig) GetRecipient(k recipient.Key) recipient.Recipient

func (*RuntimeConfig) GetRuleEscalation

func (r *RuntimeConfig) GetRuleEscalation(escalationID int64) *rule.Escalation

GetRuleEscalation returns a *rule.Escalation by the given id. Returns nil if there is no rule escalation with given id.

func (*RuntimeConfig) GetRulesVersionFor added in v0.2.0

func (r *RuntimeConfig) GetRulesVersionFor(srcId int64) string

GetRulesVersionFor retrieves the version of the rules for a specific source.

If either no rules or no rule for this source exist, NoRulesVersion is returned.

May not be called while holding the write lock on the RuntimeConfig.

func (*RuntimeConfig) GetSourceFromCredentials

func (r *RuntimeConfig) GetSourceFromCredentials(user, pass string, logger *logging.Logger) *Source

GetSourceFromCredentials verifies a credential pair against known Sources.

This method returns either a *Source or a nil pointer and logs the cause to the given logger. This is in almost all cases a debug logging message, except when something server-side is wrong, e.g., the hash is invalid.

func (*RuntimeConfig) PeriodicUpdates

func (r *RuntimeConfig) PeriodicUpdates(ctx context.Context, interval time.Duration)

func (*RuntimeConfig) RLock

func (r *RuntimeConfig) RLock()

RLock locks the config for reading.

func (*RuntimeConfig) RUnlock

func (r *RuntimeConfig) RUnlock()

RUnlock releases a lock obtained by RLock().

func (*RuntimeConfig) UpdateFromDatabase

func (r *RuntimeConfig) UpdateFromDatabase(ctx context.Context) error

type Source

type Source struct {
	baseconf.IncrementalPkDbEntry[int64] `db:",inline"`

	Type string `db:"type"`
	Name string `db:"name"`

	ListenerUsername     types.String `db:"listener_username"`
	ListenerPasswordHash types.String `db:"listener_password_hash"`
	// contains filtered or unexported fields
}

Source entry within the ConfigSet to describe a source.

func (*Source) MarshalLogObject

func (source *Source) MarshalLogObject(encoder zapcore.ObjectEncoder) error

MarshalLogObject implements the zapcore.ObjectMarshaler interface.

func (*Source) PasswordCompare added in v0.2.0

func (source *Source) PasswordCompare(password []byte) error

PasswordCompare checks if a password matches this Source's password with a cache.

This method returns nil if the password is correct, bcrypt.ErrMismatchedHashAndPassword in case of an invalid password and another error if something else went wrong.

This cache might be necessary as, for the moment, bcrypt is used to hash the passwords. By design, bcrypt is expensive, resulting in unnecessary delays when excessively using the API.

If either PHP's PASSWORD_DEFAULT changes or Icinga Web 2 starts using something else, e.g., Argon2id, this will return a descriptive error as the identifier does no longer match the bcrypt "$2y$".

If a Source changes, it will be recreated - RuntimeConfig.applyPendingSources has a nil updateFn - and the cache is automatically purged.

type SourceRuleVersion added in v0.2.0

type SourceRuleVersion struct {
	Major int64
	Minor int64
}

SourceRuleVersion for SourceRulesInfo, consisting of two numbers, one static and one incrementable.

func NewSourceRuleVersion added in v0.2.0

func NewSourceRuleVersion() SourceRuleVersion

NewSourceRuleVersion creates a new source version based on the current timestamp and a zero counter.

func (*SourceRuleVersion) Increment added in v0.2.0

func (sourceVersion *SourceRuleVersion) Increment()

Increment the version counter.

func (*SourceRuleVersion) String added in v0.2.0

func (sourceVersion *SourceRuleVersion) String() string

String implements fmt.Stringer and returns a pretty-printable representation.

type SourceRulesInfo added in v0.2.0

type SourceRulesInfo struct {
	// Version is the version of the rules for the source.
	//
	// Multiple source's versions are independent of another.
	Version SourceRuleVersion

	// RuleIDs is a list of rule IDs associated with a specific source.
	//
	// It is used to quickly access the rules for a specific source without iterating over all rules.
	RuleIDs []int64
}

SourceRulesInfo holds information about the rules associated with a specific source.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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