home: imp code

This commit is contained in:
Stanislav Chzhen 2025-03-17 15:42:59 +03:00
parent 3c985959de
commit 986aebff79
2 changed files with 12 additions and 15 deletions
internal/home

View file

@ -664,7 +664,8 @@ func run(opts options, clientBuildFS fs.FS, done chan struct{}, sigHdlr *signalH
globalContext.auth, err = initUsers()
fatalOnError(err)
tlsMgr, err := newTLSManager(ctx, slogLogger, config.TLS, config.DNS.ServePlainDNS)
tlsMgrLogger := slogLogger.With(slogutil.KeyPrefix, "tls_manager")
tlsMgr, err := newTLSManager(ctx, tlsMgrLogger, config.TLS, config.DNS.ServePlainDNS)
if err != nil {
log.Error("initializing tls: %s", err)
onConfigModified()

View file

@ -50,16 +50,16 @@ type tlsManager struct {
// newTLSManager initializes the manager of TLS configuration. m is always
// non-nil while any returned error indicates that the TLS configuration isn't
// valid. Thus TLS may be initialized later, e.g. via the web UI. baseLogger
// must not be nil.
// valid. Thus TLS may be initialized later, e.g. via the web UI. logger must
// not be nil.
func newTLSManager(
ctx context.Context,
baseLogger *slog.Logger,
logger *slog.Logger,
conf tlsConfigSettings,
servePlainDNS bool,
) (m *tlsManager, err error) {
m = &tlsManager{
logger: baseLogger.With(slogutil.KeyPrefix, "tls_manager"),
logger: logger,
status: &tlsConfigStatus{},
conf: conf,
servePlainDNS: servePlainDNS,
@ -142,23 +142,18 @@ func (m *tlsManager) reload(ctx context.Context) {
certPath := tlsConf.CertificatePath
fi, err := os.Stat(certPath)
if err != nil {
m.logger.ErrorContext(
ctx,
"no certificate file at path",
"cert_path", certPath,
slogutil.KeyError, err,
)
m.logger.ErrorContext(ctx, "checking certificate file", slogutil.KeyError, err)
return
}
if fi.ModTime().UTC().Equal(m.certLastMod) {
m.logger.DebugContext(ctx, "certificate file isn't modified")
m.logger.InfoContext(ctx, "certificate file is not modified")
return
}
m.logger.DebugContext(ctx, "certificate file is modified")
m.logger.InfoContext(ctx, "certificate file is modified")
m.confLock.Lock()
err = m.load(ctx)
@ -573,11 +568,12 @@ func (m *tlsManager) validateCertChain(
pool.AddCert(cert)
}
if len(others) > 0 {
othersLen := len(others)
if othersLen > 0 {
m.logger.InfoContext(
ctx,
"verifying certificate chain: got an intermediate cert",
"num", len(others),
"num", othersLen,
)
}