mirror of
https://github.com/authelia/authelia.git
synced 2026-10-28 09:34:52 +08:00
Adds the `--config.filters.template.delimiter.left` and `--config.filters.template.delimiter.right` options which customize the delimiters used by the template file filter, allowing configuration files to remain valid for their own file type so they can be linted. This does not address validation against a schema. In addition the `--config.experimental.filters` flag is renamed to `--config.filters`, and the deprecated `expand-env` filter is removed in favor of the `template` filter. --------- Signed-off-by: James Elliott <james-d-elliott@users.noreply.github.com> Co-authored-by: Amir Zarrinkafsh <3339418+nightah@users.noreply.github.com>
78 lines
3.3 KiB
Go
78 lines
3.3 KiB
Go
// SPDX-FileCopyrightText: 2026 Authelia
|
|
//
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
package embed
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/authelia/authelia/v4/internal/configuration"
|
|
"github.com/authelia/authelia/v4/internal/configuration/schema"
|
|
"github.com/authelia/authelia/v4/internal/configuration/validator"
|
|
)
|
|
|
|
// NewConfiguration builds a new configuration given a list of paths and filters. The filters can either be nil or
|
|
// generated using NewNamedConfigFileFilters. This function essentially operates the same as Authelia does normally in
|
|
// configuration steps.
|
|
func NewConfiguration(paths []string, filters []configuration.BytesFilter) (keys []string, config *schema.Configuration, val *schema.StructValidator, err error) {
|
|
sources := configuration.NewDefaultSourcesWithDefaults(
|
|
paths,
|
|
filters,
|
|
configuration.DefaultEnvPrefix,
|
|
configuration.DefaultEnvDelimiter,
|
|
[]configuration.Source{configuration.NewMapSource(configuration.Defaults())})
|
|
|
|
val = schema.NewStructValidator()
|
|
|
|
var definitions *schema.Definitions
|
|
|
|
if definitions, err = configuration.LoadDefinitions(val, sources...); err != nil {
|
|
return nil, nil, nil, err
|
|
}
|
|
|
|
config = &schema.Configuration{}
|
|
|
|
if keys, err = configuration.LoadAdvanced(
|
|
val,
|
|
"",
|
|
config,
|
|
definitions,
|
|
sources...); err != nil {
|
|
return nil, nil, nil, err
|
|
}
|
|
|
|
return keys, config, val, nil
|
|
}
|
|
|
|
// ValidateConfigurationAndKeys performs all configuration validation steps. The provided *schema.StructValidator should
|
|
// at minimum be checked for errors before continuing.
|
|
func ValidateConfigurationAndKeys(config *schema.Configuration, keys []string, val *schema.StructValidator) {
|
|
ValidateConfigurationKeys(keys, val)
|
|
ValidateConfiguration(config, val)
|
|
}
|
|
|
|
// ValidateConfigurationKeys just the keys validation steps. The provided *schema.StructValidator should
|
|
// at minimum be checked for errors before continuing. This should be used prior to using ValidateConfiguration.
|
|
func ValidateConfigurationKeys(keys []string, val *schema.StructValidator) {
|
|
validator.ValidateKeys(keys, configuration.GetMultiKeyMappedDeprecationKeys(), configuration.DefaultEnvPrefix, val)
|
|
}
|
|
|
|
// ValidateConfiguration just the configuration validation steps. The provided *schema.StructValidator should
|
|
// at minimum be checked for errors before continuing. This should be used after using ValidateConfigurationKeys.
|
|
func ValidateConfiguration(config *schema.Configuration, val *schema.StructValidator) {
|
|
validator.ValidateConfiguration(config, val)
|
|
}
|
|
|
|
// NewNamedConfigFileFilters allows configuring a set of file filters. The officially supported filter is 'template'.
|
|
// The valuesFiles paths support .yml, .yaml, .json, and .toml; they are loaded in order and deep-merged on top of each
|
|
// other, and are only loaded if one of the named filters utilizes them. The leftDelim and rightDelim parameters override
|
|
// the default template delimiters used by the 'template' filter; pass empty strings to leave them at their defaults.
|
|
func NewNamedConfigFileFilters(valuesFiles []string, leftDelim, rightDelim string, names ...string) (filters []configuration.BytesFilter, err error) {
|
|
if filters, err = configuration.NewFileFilters(valuesFiles, leftDelim, rightDelim, names...); err != nil {
|
|
return nil, fmt.Errorf("error occurred loading filters: %w", err)
|
|
}
|
|
|
|
return filters, nil
|
|
}
|