Help us shape the future of Go! Take the 2026 Go Developer Survey

settings

package
v0.6.2 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TypeString  string = "string"
	TypeBoolean string = "boolean"
	TypeInteger string = "integer"
)

Types of settings values

View Source
const (
	ScriptEnroll string = "enroll"
	ScriptRemove string = "remove"
)

Types of script

View Source
const (
	ActionExpire    string = "expire"
	ActionExtend    string = "extend"
	ActionRotate    string = "rotate"
	ActionNotexpire string = "notexpire"
	SetMacPackage   string = "set_pkg"
	SetMsiPackage   string = "set_msi"
	SetDebPackage   string = "set_deb"
	SetRpmPackage   string = "set_rpm"
)

Types of enroll/remove actions

View Source
const (
	QueryDelete   string = "delete"
	QueryExpire   string = "expire"
	QueryComplete string = "complete"
	CarveDelete   string = QueryDelete
	CarveExpire   string = QueryExpire
	CarveComplete string = QueryComplete
)

Types of query/carve actions

View Source
const (
	PackageDeb string = "deb"
	PackageRpm string = "rpm"
	PackagePkg string = "pkg"
	PackageMsi string = "msi"
)

Types of package

View Source
const (
	DownloadSecret       string = "secret"
	DownloadCert         string = "cert"
	DownloadFlags        string = "flags"
	DownloadFlagsMac     string = "flagsMac"
	DownloadFlagsWin     string = "flagsWindows"
	DownloadFlagsLinux   string = "flagsLinux"
	DownloadFlagsFreeBSD string = "flagsFreeBSD"
)

Types of download target

View Source
const (
	PlatformDarwin  string = "darwin"
	PlatformLinux   string = "linux"
	PlatformWindows string = "windows"
)

Types of platform

View Source
const (
	RefreshSettings    string = "refresh_settings"
	ServiceMetrics     string = "service_metrics"
	InactiveHours      string = "inactive_hours"
	AcceleratedSeconds string = "accelerated_seconds"
	OnelinerExpiration string = "oneliner_expiration"
	// AlertHistoryRetentionDays bounds how long dispatched-alert rows
	// stay in alert_history before the periodic prune deletes them.
	AlertHistoryRetentionDays string = "alert_history_retention_days"
)

Names for all possible settings values for services

View Source
const AuditLogRetentionDays = "audit_log_retention_days"
View Source
const DefaultAlertHistoryRetentionDays int64 = 30

DefaultAlertHistoryRetentionDays is the fallback retention (in days) for alert_history rows when the alert_history_retention_days setting is absent or invalid. 30 days balances audit trail depth against table growth; 0 (disable pruning) is rejected so the table can never grow unbounded by accident.

View Source
const DefaultAuditLogRetentionDays int64 = 90
View Source
const DefaultInactiveHours int64 = 72

DefaultInactiveHours is the fallback threshold (in hours) for classifying nodes as active vs inactive when no valid environment or global value exists.

View Source
const MaxInactiveHours int64 = math.MaxInt64 / int64(time.Hour)
View Source
const (
	NoEnvironmentID = iota
)

Values for generic IDs

Variables

View Source
var ValidServices = map[string]struct{}{
	config.ServiceTLS: {},
	config.ServiceAPI: {},
}

ValidServices to check validity of settings service

Functions

func ValidateAuditLogRetentionDays added in v0.6.0

func ValidateAuditLogRetentionDays(days int64) error

func ValidateInactiveHours added in v0.6.0

func ValidateInactiveHours(hours int64) error

func ValidateIntegerSetting added in v0.6.2

func ValidateIntegerSetting(service, name string, value int64) error

ValidateIntegerSetting applies the range check owned by a setting, if any. Shared by the API PATCH handler and the CLI so both modes reject the same values.

Types

type InactivityPolicy added in v0.6.0

type InactivityPolicy struct {
	OverrideHours *int64 `json:"override_hours" extensions:"x-nullable" minimum:"1" maximum:"2562047"`
	InactiveHours int64  `json:"inactive_hours" minimum:"1" maximum:"2562047"`
	Source        string `json:"source" enums:"environment,global,default"`
}

type MapSettings

type MapSettings map[string]SettingValue

MapSettings to hold all values by service

type RedisSettingsCache added in v0.5.5

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

RedisSettingsCache caches a service/env settings map in Redis.

func NewRedisSettingsCache added in v0.5.5

func NewRedisSettingsCache(settings *Settings, client *redis.Client, service string, envID uint, ttl time.Duration) *RedisSettingsCache

NewRedisSettingsCache creates a Redis-backed cache for settings.GetMap.

func (*RedisSettingsCache) GetMap added in v0.5.5

GetMap returns the cached settings map, refetching from DB on Redis miss/error.

func (*RedisSettingsCache) Invalidate added in v0.5.5

func (c *RedisSettingsCache) Invalidate(ctx context.Context) error

Invalidate removes the cached settings map.

func (*RedisSettingsCache) SetDBHealth added in v0.5.5

func (c *RedisSettingsCache) SetDBHealth(h backend.DegradedReader)

SetDBHealth wires a DB health monitor. When the monitor reports the database as degraded, GetMap serves a stale cached entry on a DB miss instead of returning an error, and writes during degradation use settingsCacheDegradedTTL. Pass nil to disable (the default).

type SettingValue

type SettingValue struct {
	gorm.Model
	Name          string `gorm:"index"`
	Service       string
	EnvironmentID uint
	Type          string
	String        string
	Boolean       bool
	Integer       int64
	Info          string
}

SettingValue to hold each value for settings

type Settings

type Settings struct {
	DB *gorm.DB
}

Settings keeps all settings values

func NewSettings

func NewSettings(backend *gorm.DB) *Settings

NewSettings to initialize the access to settings and table

func (*Settings) AlertHistoryRetentionDays added in v0.5.8

func (conf *Settings) AlertHistoryRetentionDays() int64

AlertHistoryRetentionDays gets how long dispatched-alert rows are kept before pruning. Returns DefaultAlertHistoryRetentionDays when the setting is absent, invalid, or zero (a zero would disable pruning and let the table grow unbounded, so it is treated as "use the default").

func (*Settings) AuditLogRetentionDays added in v0.6.0

func (conf *Settings) AuditLogRetentionDays() (int64, error)

AuditLogRetentionDays is shared by all services' audit rows. Invalid settings and database failures stop pruning rather than applying a shorter fallback.

func (*Settings) DeleteValue

func (conf *Settings) DeleteValue(service, name string, envID uint) error

DeleteValue deletes an existing settings value

func (*Settings) EmptyValue

func (conf *Settings) EmptyValue(service, name, typeValue string, envID uint) SettingValue

EmptyValue creates an empty value

func (*Settings) GetInteger

func (conf *Settings) GetInteger(service, name string, envID uint) (int64, error)

GetInteger gets a numeric settings value by service and name

func (*Settings) GetMap

func (conf *Settings) GetMap(service string, envID uint) (MapSettings, error)

GetMap returns the map of values by service

func (*Settings) InactiveHours

func (conf *Settings) InactiveHours(envID uint) int64

InactiveHours resolves an environment override, then the global setting.

func (*Settings) InactivityPolicy added in v0.6.0

func (conf *Settings) InactivityPolicy(envID uint) (InactivityPolicy, error)

InactivityPolicy reads both scopes together; invalid legacy rows inherit.

func (*Settings) IsValue

func (conf *Settings) IsValue(service, name string, envID uint) bool

IsValue checks if a settings value exists by service and name

func (*Settings) NewBooleanValue

func (conf *Settings) NewBooleanValue(service, name string, value bool, envID uint) error

NewBooleanValue creates a new settings value

func (*Settings) NewIntegerValue

func (conf *Settings) NewIntegerValue(service, name string, value int64, envID uint) error

NewIntegerValue creates a new settings value

func (*Settings) NewStringValue

func (conf *Settings) NewStringValue(service, name, value string, envID uint) error

NewStringValue creates a new settings value

func (*Settings) NewValue

func (conf *Settings) NewValue(service, name, typeValue string, value interface{}, envID uint) error

NewValue creates a new settings value

func (*Settings) OnelinerExpiration

func (conf *Settings) OnelinerExpiration(envID uint) bool

OnelinerExpiration checks if enrolling links will expire

func (*Settings) RefreshSettings

func (conf *Settings) RefreshSettings(service string) int64

RefreshSettings gets the interval in seconds to refresh settings by service

func (*Settings) RetrieveAllValues

func (conf *Settings) RetrieveAllValues() ([]SettingValue, error)

RetrieveAllValues retrieves and returns all values from backend

func (*Settings) RetrieveValue

func (conf *Settings) RetrieveValue(service, name string, envID uint) (SettingValue, error)

RetrieveValue retrieves one value from settings by service and name from backend

func (*Settings) RetrieveValues

func (conf *Settings) RetrieveValues(service string, envID uint) ([]SettingValue, error)

RetrieveValues retrieves and returns all values from backend

func (*Settings) SetBoolean

func (conf *Settings) SetBoolean(boolValue bool, service, name string, envID uint) error

SetBoolean sets a boolean settings value by service and name

func (*Settings) SetInfo

func (conf *Settings) SetInfo(info string, service, name string, envID uint) error

SetInfo sets the info of a setting

func (*Settings) SetInteger

func (conf *Settings) SetInteger(intValue int64, service, name string, envID uint) error

SetInteger sets a numeric settings value by service and name

func (*Settings) SetString

func (conf *Settings) SetString(strValue string, service, name string, envID uint) error

SetString sets a boolean settings value by service and name

func (*Settings) VerifyService

func (conf *Settings) VerifyService(sType string) bool

VerifyService to make sure service is valid

Jump to

Keyboard shortcuts

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