Pull request 2456: 7985-fix-contol-profile

Updates #7985.

Squashed commit of the following:

commit 1d5a3e66cc046ac8be6c0ebe7f5e06bc3e2a5e72
Merge: bdc76b1b1 52398e27e
Author: Stanislav Chzhen <s.chzhen@adguard.com>
Date:   Thu Aug 28 19:05:51 2025 +0300

    Merge branch 'master' into 7985-fix-contol-profile

commit bdc76b1b10
Author: Stanislav Chzhen <s.chzhen@adguard.com>
Date:   Tue Aug 26 15:47:07 2025 +0300

    home: imp code

commit aef012ed02
Author: Stanislav Chzhen <s.chzhen@adguard.com>
Date:   Tue Aug 26 13:14:39 2025 +0300

    home: add tests

commit 799e8b49a1
Author: Stanislav Chzhen <s.chzhen@adguard.com>
Date:   Mon Aug 25 16:59:06 2025 +0300

    all: fix control profile
This commit is contained in:
Stanislav Chzhen
2025-08-28 19:17:24 +03:00
parent 52398e27ec
commit 146b6dd094
8 changed files with 167 additions and 20 deletions

View File

@@ -629,8 +629,8 @@ func validateBindHosts(conf *configuration) (err error) {
}
// parseConfig loads configuration from the YAML file, upgrading it if
// necessary.
func parseConfig() (err error) {
// necessary. l must not be nil.
func parseConfig(ctx context.Context, l *slog.Logger) (err error) {
// Do the upgrade if necessary.
config.fileData, err = readConfigFile()
if err != nil {
@@ -652,7 +652,7 @@ func parseConfig() (err error) {
return err
} else if upgraded {
confPath := configFilePath()
log.Debug("writing config file %q after config upgrade", confPath)
l.DebugContext(ctx, "writing config file after config upgrade", "path", confPath)
err = maybe.WriteFile(confPath, config.fileData, aghos.DefaultPermFile)
if err != nil {
@@ -666,7 +666,7 @@ func parseConfig() (err error) {
return err
}
err = validateConfig()
err = validateConfig(ctx, l)
if err != nil {
return err
}
@@ -679,8 +679,9 @@ func parseConfig() (err error) {
return validateTLSCipherIDs(config.TLS.OverrideTLSCiphers)
}
// validateConfig returns error if the configuration is invalid.
func validateConfig() (err error) {
// validateConfig returns error if the configuration is invalid. l must not be
// nil.
func validateConfig(ctx context.Context, l *slog.Logger) (err error) {
err = validateBindHosts(config)
if err != nil {
// Don't wrap the error since it's informative enough as is.
@@ -716,6 +717,10 @@ func validateConfig() (err error) {
config.Filtering.FiltersUpdateIntervalHours = 24
}
if len(config.Users) == 0 {
l.WarnContext(ctx, "no users in the configuration file; authentication is disabled")
}
return nil
}