Skip to content

Commit 9400a89

Browse files
authored
Clean up TLS default path logic. Use convention if config isn't present. (#1049)
Move cert/key path defaulting into LoadConfig and remove the redundant fallback from ensureTLSCertificate. 1. Use local constants instead of the deprecated `tlsbuilder.CertPEMFile`/`KeyPEMFile`. 2. Nest the two path checks under a single `if tls.Generate` guard. Signed-off-by: Sebastian (Tiedtke) Huckleberry <sebastiantiedtke@gmail.com>
1 parent 0a46774 commit 9400a89

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

pkg/agent/application/app.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ import (
2525
"github.com/runmedev/runme/v3/pkg/agent/config"
2626
)
2727

28+
const (
29+
defaultCertFile = "cert.pem"
30+
defaultKeyFile = "key.pem"
31+
)
32+
2833
type App struct {
2934
AppName string
3035
AppConfig *config.AppConfig
@@ -49,6 +54,17 @@ func (a *App) LoadConfig(cmd *cobra.Command) error {
4954
return err
5055
}
5156
cfg := ac.GetConfig()
57+
if cfg.AssistantServer != nil && cfg.AssistantServer.TLSConfig != nil {
58+
tls := cfg.AssistantServer.TLSConfig
59+
if tls.Generate {
60+
if tls.CertFile == "" {
61+
tls.CertFile = filepath.Join(ac.GetConfigDir(), defaultCertFile)
62+
}
63+
if tls.KeyFile == "" {
64+
tls.KeyFile = filepath.Join(ac.GetConfigDir(), defaultKeyFile)
65+
}
66+
}
67+
}
5268
if problems := cfg.IsValid(); len(problems) > 0 {
5369
_, _ = fmt.Fprintf(os.Stdout, "Invalid configuration; %s\n", strings.Join(problems, "\n"))
5470
return fmt.Errorf("invalid configuration; fix the problems and then try again")

pkg/agent/cmd/certificate_check.go

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package cmd
22

33
import (
4-
"path/filepath"
5-
64
"github.com/go-logr/zapr"
75
"github.com/spf13/cobra"
86
"go.uber.org/zap"
@@ -21,13 +19,6 @@ func ensureTLSCertificate(app *application.App) error {
2119
return nil
2220
}
2321

24-
if tlsConfig.KeyFile == "" {
25-
tlsConfig.KeyFile = filepath.Join(app.AppConfig.GetConfigDir(), tlsbuilder.KeyPEMFile)
26-
}
27-
if tlsConfig.CertFile == "" {
28-
tlsConfig.CertFile = filepath.Join(app.AppConfig.GetConfigDir(), tlsbuilder.CertPEMFile)
29-
}
30-
3122
_, err := tlsbuilder.LoadOrGenerateConfig(tlsConfig.CertFile, tlsConfig.KeyFile, zap.L())
3223
return err
3324
}

0 commit comments

Comments
 (0)