config

package
v0.0.0-...-0fd3e05 Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2026 License: Apache-2.0 Imports: 28 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ConfigFilePath specifies the path to the config file, this contains the default path
	ConfigFilePath = "config.file"
	// ConfigFilePathEnv specifies the environment variable name for the config file path
	ConfigFilePathEnv = "CONFIG_FILE_PATH"

	// ConfigEnvDev specifies if the service is running in development mode
	ConfigEnvDev = "env.dev"
	// ConfigEnvDisconnected specifies if the service is running in disconnected mode
	ConfigEnvDisconnected = "env.disconnected"

	// ConfigAPIName specifies the name of the API
	ConfigAPIName = "api.name"
	// ConfigAPIRouteVersion specifies the version of the API
	ConfigAPIRouteVersion = "api.route.version"

	// ConfigLogLevel specifies the log level
	ConfigLogLevel = "log.level"

	// ConfigSentryDSN is the DSN for Sentry
	ConfigSentryDSN = "log.sentry.dsn"

	// ConfigDBHost specifies the host of the database
	ConfigDBHost = "db.host"
	// ConfigDBPort specifies the port of the database
	ConfigDBPort = "db.port"
	// ConfigDBName specifies the name of the database
	ConfigDBName = "db.name"
	// ConfigDBUser specifies the user of the database
	ConfigDBUser = "db.user"
	// ConfigDBPasswordPath specifies the path for file containing password of the database
	ConfigDBPasswordPath = "db.passwordPath"
	// ConfigDBPassword specifies the password of the database, not read from config file, rather from file specified by db.passwordPath
	ConfigDBPassword = "db.password"

	// ConfigTemporalHost specifies the hostname for Temporal
	ConfigTemporalHost = "temporal.host"
	// ConfigTemporalPort specifies the port for Temporal
	ConfigTemporalPort = "temporal.port"
	// ConfigTemporalServerName specifies the server name for Temporal
	ConfigTemporalServerName = "temporal.serverName"
	// ConfigTemporalNamespace specifies the namespace for Temporal
	ConfigTemporalNamespace = "temporal.namespace"
	// ConfigTemporalQueue specifies the queue for Temporal
	ConfigTemporalQueue = "temporal.queue"
	// ConfigTemporalTlsEnabled specifies if TLS should be used with Temporal
	ConfigTemporalTlsEnabled = "temporal.tls.enabled"
	// ConfigTemporalCertPath specifies the path for client cert
	ConfigTemporalCertPath = "temporal.tls.certPath"
	// ConfigTemporalKeyPath specifies the path for client key
	ConfigTemporalKeyPath = "temporal.tls.keyPath"
	// ConfigTemporalCaPath specifies the path for server CA cert
	ConfigTemporalCaPath = "temporal.tls.caPath"
	// ConfigTemporalEncryptionKey specifies the data encryption key for Temporal
	ConfigTemporalEncryptionKey = "temporal.encryptionKey"
	// ConfigTemporalEncryptionKeyPath specifies the path for file containing data encryption key for Temporal
	ConfigTemporalEncryptionKeyPath = "temporal.encryptionKeyPath"

	// ConfigSiteManagerEnabled is a feature flag for site manager
	ConfigSiteManagerEnabled = "siteManager.enabled"
	// ConfigSiteManagerEndpoint is the service endpoint for site manager
	ConfigSiteManagerEndpoint = "siteManager.svcEndpoint"

	// ConfigSitePhoneHomeUrl is a phone home url from the site
	ConfigSitePhoneHomeUrl = "site.phoneHomeUrl"

	// ConfigMetricsEnabled is a feature flag for Prometheus metrics
	ConfigMetricsEnabled = "metrics.enabled"
	// ConfigMetricsPort specifies the port for Prometheus metrics
	ConfigMetricsPort = "metrics.port"
	// ConfigMetricsNamespace specifies the prefix for every exposed metric name
	ConfigMetricsNamespace = "metrics.namespace"

	// ConfigTracingEnabled is a feature flag for tracing
	ConfigTracingEnabled = "tracing.enabled"
	// ConfigTracingServiceName is the name of the tracing service
	ConfigTracingServiceName = "tracing.serviceName"

	// ConfigKeycloakEnabled is a feature flag for Keycloak authentication
	ConfigKeycloakEnabled = "keycloak.enabled"
	// ConfigKeycloakBaseURL is the base URL of the Keycloak server
	ConfigKeycloakBaseURL = "keycloak.baseURL"
	// ConfigKeycloakExternalBaseURL is the external base URL of the Keycloak server
	ConfigKeycloakExternalBaseURL = "keycloak.externalBaseURL"
	// ConfigKeycloakRealm is the Keycloak realm name
	ConfigKeycloakRealm = "keycloak.realm"
	// ConfigKeycloakClientID is the Keycloak client ID
	ConfigKeycloakClientID = "keycloak.clientID"
	// ConfigKeycloakClientSecretPath is the path to the file containing the client secret
	ConfigKeycloakClientSecretPath = "keycloak.clientSecretPath"
	// ConfigKeycloakClientSecret is the client secret, read from the secret file
	ConfigKeycloakClientSecret = "keycloak.clientSecret"
	// ConfigKeycloakServiceAccountEnabled is a feature flag for service account support
	ConfigKeycloakServiceAccountEnabled = "keycloak.serviceAccount"

	// ConfigRateLimiterEnabled is a feature flag for rate limiter
	ConfigRateLimiterEnabled = "rateLimiter.enabled"
	// ConfigRateLimiterRate specifies the rate limit (requests per second)
	ConfigRateLimiterRate = "rateLimiter.rate"
	// ConfigRateLimiterBurst specifies the burst size
	ConfigRateLimiterBurst = "rateLimiter.burst"
	// ConfigRateLimiterExpiresIn specifies the expiration time in seconds
	ConfigRateLimiterExpiresIn = "rateLimiter.expiresIn"

	// ConfigDPSEnabled controls whether NICo makes direct DPS calls.
	ConfigDPSEnabled = "powerProvisioning.dps.enabled"
	// ConfigDPSEndpoint is the remote DPS gRPC endpoint.
	ConfigDPSEndpoint = "powerProvisioning.dps.endpoint"
	// ConfigDPSRequestTimeout bounds each direct DPS operation.
	ConfigDPSRequestTimeout = "powerProvisioning.dps.requestTimeout"
	// ConfigDPSTokenPath specifies the bearer-token secret file.
	ConfigDPSTokenPath = "powerProvisioning.dps.tokenPath"
	// ConfigDPSCAPath specifies the CA bundle used to authenticate DPS.
	ConfigDPSCAPath = "powerProvisioning.dps.tls.caPath"
	// ConfigDPSServerName optionally overrides TLS server-name verification.
	ConfigDPSServerName = "powerProvisioning.dps.tls.serverName"
)
View Source
const DefaultMetricsNamespace = "nico_rest_api"

DefaultMetricsNamespace prefixes every metric this server exposes and matches its nico-rest-api Helm service name. Operators override it with metrics.namespace. Deliberately independent of api.name, which is the URL path segment callers route on and has no bearing on how these series are named.

View Source
const DefaultSitePhoneHomeUrl = "http://169.254.169.254/latest/meta-data/phone_home"

Variables

View Source
var (

	// ProjectRoot describes the folder path of this project
	ProjectRoot = filepath.Join(filepath.Dir(cur), "../..")
)

Functions

func ParseOriginString

func ParseOriginString(origin string) (string, error)

ParseOriginString converts a string origin to its string constant

func SetupTestCerts

func SetupTestCerts(t *testing.T) (string, string)

SetupTestCerts sets up a test key and cert

Types

type Config

type Config struct {
	sync.RWMutex

	TokenOriginConfig *cauth.TokenOriginConfig
	SiteConfig        *SiteConfig
	KeycloakConfig    *cauth.KeycloakConfig
	// contains filtered or unexported fields
}

Config represents configurations for the service

func NewConfig

func NewConfig() *Config

NewConfig creates a new config object

func (*Config) Close

func (c *Config) Close()

Close stops background tasks

func (*Config) GetAPIName

func (c *Config) GetAPIName() string

GetAPIName returns the name of the API

func (*Config) GetAPIRouteVersion

func (c *Config) GetAPIRouteVersion() string

GetAPIRouteVersion returns the version of the API

func (*Config) GetDBConfig

func (c *Config) GetDBConfig() *cconfig.DBConfig
Get sub-configurations

GetDBConfig returns the database config

func (*Config) GetDBHost

func (c *Config) GetDBHost() string

GetDBHost returns the host of the database

func (*Config) GetDBName

func (c *Config) GetDBName() string

GetDBName returns the name of the database

func (*Config) GetDBPassword

func (c *Config) GetDBPassword() string

GetDBPassword returns the password of the database

func (*Config) GetDBPasswordPath

func (c *Config) GetDBPasswordPath() string

GetDBPasswordPath returns the path for file containing password of the database

func (*Config) GetDBPort

func (c *Config) GetDBPort() int

GetDBPort returns the port of the database

func (*Config) GetDBUser

func (c *Config) GetDBUser() string

GetDBUser returns the user of the database

func (*Config) GetDPSConfig

func (c *Config) GetDPSConfig() dpsclient.Config

GetDPSConfig returns connection settings for direct DPS calls.

func (*Config) GetDPSEnabled

func (c *Config) GetDPSEnabled() bool

GetDPSEnabled reports whether NICo makes direct DPS calls.

func (*Config) GetEnvDev

func (c *Config) GetEnvDev() bool

GetEnvDev returns if the service is running in development mode

func (*Config) GetEnvDisconnected

func (c *Config) GetEnvDisconnected() bool

GetEnvDisconnected returns if the service is running in disconnected mode

func (*Config) GetIssuersConfig

func (c *Config) GetIssuersConfig() ([]IssuerConfig, error)

GetIssuersConfig returns the issuer configurations from the config file

func (*Config) GetKeycloakBaseURL

func (c *Config) GetKeycloakBaseURL() string

GetKeycloakBaseURL gets the base URL for Keycloak

func (*Config) GetKeycloakClientID

func (c *Config) GetKeycloakClientID() string

GetKeycloakClientID gets the client ID for Keycloak

func (*Config) GetKeycloakClientSecret

func (c *Config) GetKeycloakClientSecret() string

GetKeycloakClientSecret gets the client secret for Keycloak

func (*Config) GetKeycloakClientSecretPath

func (c *Config) GetKeycloakClientSecretPath() string

GetKeycloakClientSecretPath gets the client secret path for Keycloak

func (*Config) GetKeycloakEnabled

func (c *Config) GetKeycloakEnabled() bool

GetKeycloakEnabled gets the enabled field for Keycloak

func (*Config) GetKeycloakExternalBaseURL

func (c *Config) GetKeycloakExternalBaseURL() string

GetKeycloakExternalBaseURL gets the external base URL for Keycloak

func (*Config) GetKeycloakRealm

func (c *Config) GetKeycloakRealm() string

GetKeycloakRealm gets the realm for Keycloak

func (*Config) GetKeycloakServiceAccountEnabled

func (c *Config) GetKeycloakServiceAccountEnabled() bool

GetKeycloakServiceAccountEnabled gets the service account enabled flag for Keycloak

func (*Config) GetLogLevel

func (c *Config) GetLogLevel() string

GetLogLevel returns the log level

func (*Config) GetMetricsConfig

func (c *Config) GetMetricsConfig() *MetricsConfig

GetMetricsConfig returns the Metrics config

func (*Config) GetMetricsEnabled

func (c *Config) GetMetricsEnabled() bool

GetMetricsEnabled gets the enabled field for Metrics

func (*Config) GetMetricsNamespace

func (c *Config) GetMetricsNamespace() string

GetMetricsNamespace gets the prefix applied to every exposed metric name. An explicitly empty value falls back to the default, since echoprometheus substitutes its own "echo" prefix for an empty one.

func (*Config) GetMetricsPort

func (c *Config) GetMetricsPort() int

GetZincSearchPort gets the port for Metrics

func (*Config) GetOrInitKeycloakConfig

func (c *Config) GetOrInitKeycloakConfig() (*cauth.KeycloakConfig, error)

GetOrInitKeycloakConfig gets the Keycloak configuration

func (*Config) GetOrInitTokenOriginConfig

func (c *Config) GetOrInitTokenOriginConfig() *cauth.TokenOriginConfig

GetOrInitTokenOriginConfig returns the token origin config with all configured auth providers

func (*Config) GetPathToConfig

func (c *Config) GetPathToConfig() string

GetPathToConfig returns the path to the config file

func (*Config) GetRateLimiterBurst

func (c *Config) GetRateLimiterBurst() int

GetRateLimiterBurst gets the burst size

func (*Config) GetRateLimiterConfig

func (c *Config) GetRateLimiterConfig() *RateLimiterConfig

GetRateLimiterConfig returns the rate limiter config

func (*Config) GetRateLimiterEnabled

func (c *Config) GetRateLimiterEnabled() bool

GetRateLimiterEnabled gets the enabled field for rate limiter

func (*Config) GetRateLimiterExpiresIn

func (c *Config) GetRateLimiterExpiresIn() int

GetRateLimiterExpiresIn gets the expiration time in seconds

func (*Config) GetRateLimiterRate

func (c *Config) GetRateLimiterRate() float64

GetRateLimiterRate gets the rate limit (requests per second)

func (*Config) GetSentryDSN

func (c *Config) GetSentryDSN() string

GetSentryDSN returns the DSN for Sentry

func (*Config) GetSiteConfig

func (c *Config) GetSiteConfig() *SiteConfig

GetSiteConfig returns the Site config

func (*Config) GetSiteManagerEnabled

func (c *Config) GetSiteManagerEnabled() bool

GetSiteManagerEnabled sets the enabled field

func (*Config) GetSiteManagerEndpoint

func (c *Config) GetSiteManagerEndpoint() string

GetSiteManagerEndpoint gets the path for site manager service endpoint

func (*Config) GetSitePhoneHomeUrl

func (c *Config) GetSitePhoneHomeUrl() string

GetSitePhoneHomeUrl gets the url for PhoneHome

func (*Config) GetTemporalCaPath

func (c *Config) GetTemporalCaPath() string

GetTemporalCaPath returns the path for ca cert for Temporal

func (*Config) GetTemporalCertPath

func (c *Config) GetTemporalCertPath() string

GetTemporalCertPath returns the path for client cert for Temporal

func (*Config) GetTemporalConfig

func (c *Config) GetTemporalConfig() (*cconfig.TemporalConfig, error)

GetTemporalConfig returns the temporal config

func (*Config) GetTemporalEncryptionKey

func (c *Config) GetTemporalEncryptionKey() string

GetTemporalEncryptionKey returns the encryption key for Temporal

func (*Config) GetTemporalEncryptionKeyPath

func (c *Config) GetTemporalEncryptionKeyPath() string

GetTemporalEncryptionKeyPath returns the path for file containing encryption key for Temporal

func (*Config) GetTemporalHost

func (c *Config) GetTemporalHost() string

GetTemporalHost returns the hostname for Temporal

func (*Config) GetTemporalKeyPath

func (c *Config) GetTemporalKeyPath() string

GetTemporalKeyPath returns the path for client key for Temporal

func (*Config) GetTemporalNamespace

func (c *Config) GetTemporalNamespace() string

GetTemporalNamespace returns the namespace for Temporal

func (*Config) GetTemporalPort

func (c *Config) GetTemporalPort() int

GetTemporalPort returns the port for Temporal

func (*Config) GetTemporalQueue

func (c *Config) GetTemporalQueue() string

GetTemporalQueue returns the queue for Temporal

func (*Config) GetTemporalServerName

func (c *Config) GetTemporalServerName() string

GetTemporalServerName returns the server name for Temporal

func (*Config) GetTemporalTlsEnabled

func (c *Config) GetTemporalTlsEnabled() bool

GetTemporalTlsEnabled returns true if TLS is enabled for Temporal connection

func (*Config) GetTracingEnabled

func (c *Config) GetTracingEnabled() bool

GetTracingEnabled gets the enabled field for tracing

func (*Config) GetTracingServiceName

func (c *Config) GetTracingServiceName() string

GetTracingServiceName gets the service name for tracing

func (*Config) SetKeycloakBaseURL

func (c *Config) SetKeycloakBaseURL(value string)

SetKeycloakBaseURL sets the base URL for Keycloak

func (*Config) SetKeycloakClientID

func (c *Config) SetKeycloakClientID(value string)

SetKeycloakClientID sets the client ID for Keycloak

func (*Config) SetKeycloakClientSecret

func (c *Config) SetKeycloakClientSecret()

SetKeycloakClientSecret sets the client secret for Keycloak

func (*Config) SetKeycloakClientSecretPath

func (c *Config) SetKeycloakClientSecretPath(value string)

SetKeycloakClientSecretPath sets the client secret path for Keycloak

func (*Config) SetKeycloakEnabled

func (c *Config) SetKeycloakEnabled(value bool)

SetKeycloakEnabled sets the enabled field for Keycloak

func (*Config) SetKeycloakExternalBaseURL

func (c *Config) SetKeycloakExternalBaseURL(value string)

SetKeycloakExternalBaseURL sets the external base URL for Keycloak

func (*Config) SetKeycloakRealm

func (c *Config) SetKeycloakRealm(value string)

SetKeycloakRealm sets the realm for Keycloak

func (*Config) SetKeycloakServiceAccountEnabled

func (c *Config) SetKeycloakServiceAccountEnabled(value bool)

SetKeycloakServiceAccountEnabled sets the service account enabled flag for Keycloak

func (*Config) SetRateLimiterBurst

func (c *Config) SetRateLimiterBurst(value int)

SetRateLimiterBurst sets the burst size

func (*Config) SetRateLimiterEnabled

func (c *Config) SetRateLimiterEnabled(value bool)

SetRateLimiterEnabled sets the enabled field for rate limiter

func (*Config) SetRateLimiterExpiresIn

func (c *Config) SetRateLimiterExpiresIn(value int)

SetRateLimiterExpiresIn sets the expiration time in seconds

func (*Config) SetRateLimiterRate

func (c *Config) SetRateLimiterRate(value float64)

SetRateLimiterRate sets the rate limit (requests per second)

func (*Config) SetSiteManagerEnabled

func (c *Config) SetSiteManagerEnabled(value bool)

SetSiteManagerEnabled sets the enabled field

func (*Config) SetSiteManagerEndpoint

func (c *Config) SetSiteManagerEndpoint(value string)

SetSiteManagerEndpoint sets the endpoint

func (*Config) SetSitePhoneHomeUrl

func (c *Config) SetSitePhoneHomeUrl(value string)

SetSitePhoneHomeUrl sets the url for PhoneHome

func (*Config) SetTemporalCaPath

func (c *Config) SetTemporalCaPath(value string)

SetTemporalCaPath sets the path for ca for Temporal

func (*Config) SetTemporalCertPath

func (c *Config) SetTemporalCertPath(value string)

SetTemporalCertPath set the path for client cert for Temporal

func (*Config) SetTemporalEncryptionKey

func (c *Config) SetTemporalEncryptionKey()

SetTemporalEncryptionKey sets the encryption key for Temporal

func (*Config) SetTemporalEncryptionKeyPath

func (c *Config) SetTemporalEncryptionKeyPath(value string)

SetTemporalEncryptionKeyPath sets the path for file containing encryption key for Temporal

func (*Config) SetTemporalKeyPath

func (c *Config) SetTemporalKeyPath(value string)

SetTemporalKeyPath set the path for client key for Temporal

func (*Config) Validate

func (c *Config) Validate()

Validate validates the config

func (*Config) ValidateIssuersConfig

func (c *Config) ValidateIssuersConfig(issuers []IssuerConfig) error

ValidateIssuersConfig validates the issuer configurations

func (*Config) ValidateKeycloakConfig

func (c *Config) ValidateKeycloakConfig() error

ValidateKeycloakConfig validates the Keycloak configuration

func (*Config) ValidatePowerProvisioningConfig

func (c *Config) ValidatePowerProvisioningConfig() error

ValidatePowerProvisioningConfig validates settings required for direct DPS integration. DPS connection fields are ignored when integration is disabled.

func (*Config) ValidateSiteConfig

func (c *Config) ValidateSiteConfig() error

ValidateSiteConfig validates Site configs

func (*Config) WatchConfigFile

func (c *Config) WatchConfigFile()

WatchConfigFile starts watching the config file for reloadable setting changes.

func (*Config) WatchSecretFilePaths

func (c *Config) WatchSecretFilePaths()

WatchSecretFilePaths starts watching secret files for changes.

type IssuerConfig

type IssuerConfig struct {
	Name                         string               `mapstructure:"name"`
	Origin                       string               `mapstructure:"origin"` // String: "kas-legacy", "kas-ssa", "keycloak", "custom", "kas"
	JWKS                         string               `mapstructure:"jwks"`
	Issuer                       string               `mapstructure:"issuer"`
	ServiceAccount               bool                 `mapstructure:"serviceAccount"`
	Audiences                    []string             `mapstructure:"audiences"`
	Scopes                       []string             `mapstructure:"scopes"`
	JWKSTimeout                  string               `mapstructure:"jwksTimeout"` // e.g. "5s", "1m"
	ClaimMappings                []cauth.ClaimMapping `mapstructure:"claimMappings"`
	AllowDuplicateStaticOrgNames bool                 `mapstructure:"allowDuplicateStaticOrgNames"` // When true, allows duplicate static org names across issuers
}

IssuerConfig represents a single issuer configuration entry This is the preferred configuration format that supports claim mappings

func (*IssuerConfig) GetAllowDuplicateStaticOrgNames

func (ic *IssuerConfig) GetAllowDuplicateStaticOrgNames() bool

GetAllowDuplicateStaticOrgNames returns whether duplicate static org names are allowed Defaults to false (duplicates not allowed) if not specified

func (*IssuerConfig) GetJWKSTimeout

func (ic *IssuerConfig) GetJWKSTimeout() (time.Duration, error)

GetJWKSTimeout parses and returns the JWKS timeout duration

func (*IssuerConfig) GetOrigin

func (ic *IssuerConfig) GetOrigin() (string, error)

GetOrigin parses the origin and returns it as a string constant

func (*IssuerConfig) ValidateKasOrigin

func (ic *IssuerConfig) ValidateKasOrigin() error

ValidateKasOrigin validates a KAS issuer configuration. The issuer carries the NGC API base URL the processor calls, so it is required rather than defaulted.

type MetricsConfig

type MetricsConfig struct {
	Enabled   bool
	Port      int
	Namespace string
}

MetricsConfig holds configuration of Metrics

func NewMetricsConfig

func NewMetricsConfig(enabled bool, port int, namespace string) *MetricsConfig

NewMetricsConfig initializes and returns a configuration object for managing Metrics

func (*MetricsConfig) GetListenAddr

func (mcfg *MetricsConfig) GetListenAddr() string

GetListenAddr returns the local address for listen socket.

type RateLimiterConfig

type RateLimiterConfig struct {
	Enabled   bool
	Rate      float64 // requests per second
	Burst     int     // maximum burst size
	ExpiresIn int     // expiration time in seconds
}

RateLimiterConfig holds configuration for rate limiting

func NewRateLimiterConfig

func NewRateLimiterConfig(enabled bool, rate float64, burst int, expiresIn int) *RateLimiterConfig

NewRateLimiterConfig initializes and returns a configuration object for rate limiting

type SiteConfig

type SiteConfig struct {
	Disconnected bool
	PhoneHomeUrl string
}

SiteConfig holds configuration for components and services running from site

func NewSiteConfig

func NewSiteConfig(disconnected bool, phoneHomeUrl string) *SiteConfig

NewSiteConfig initializes and returns a configuration object for site

Jump to

Keyboard shortcuts

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