Renderer: Fix regression on callback URL in plugin mode (#103787)

* Renderer: Fix regression on callback URL in plugin mode

* cleanup

* refactor to not mutate cfg object

* apply review feedback
This commit is contained in:
Agnès Toulet
2025-04-11 15:34:10 +02:00
committed by GitHub
parent f1625d9e56
commit d7c554c25e
6 changed files with 133 additions and 74 deletions
+4 -22
View File
@@ -144,7 +144,7 @@ type Cfg struct {
ImagesDir string
CSVsDir string
PDFsDir string
RendererUrl string
RendererServerUrl string
RendererCallbackUrl string
RendererAuthToken string
RendererConcurrentRequestLimit int
@@ -1168,9 +1168,7 @@ func (cfg *Cfg) parseINIFile(iniFile *ini.File) error {
cfg.readZanzanaSettings()
if err := cfg.readRenderingSettings(iniFile); err != nil {
return err
}
cfg.readRenderingSettings(iniFile)
cfg.TempDataLifetime = iniFile.Section("paths").Key("temp_data_lifetime").MustDuration(time.Second * 3600 * 24)
cfg.MetricsEndpointEnabled = iniFile.Section("metrics").Key("enabled").MustBool(true)
@@ -1796,26 +1794,12 @@ func readServiceAccountSettings(iniFile *ini.File, cfg *Cfg) error {
return nil
}
func (cfg *Cfg) readRenderingSettings(iniFile *ini.File) error {
func (cfg *Cfg) readRenderingSettings(iniFile *ini.File) {
renderSec := iniFile.Section("rendering")
cfg.RendererUrl = valueAsString(renderSec, "server_url", "")
cfg.RendererServerUrl = valueAsString(renderSec, "server_url", "")
cfg.RendererCallbackUrl = valueAsString(renderSec, "callback_url", "")
cfg.RendererAuthToken = valueAsString(renderSec, "renderer_token", "-")
if cfg.RendererCallbackUrl == "" {
cfg.RendererCallbackUrl = AppUrl
} else {
if cfg.RendererCallbackUrl[len(cfg.RendererCallbackUrl)-1] != '/' {
cfg.RendererCallbackUrl += "/"
}
_, err := url.Parse(cfg.RendererCallbackUrl)
if err != nil {
// XXX: Should return an error?
cfg.Logger.Error("Invalid callback_url.", "url", cfg.RendererCallbackUrl, "error", err)
os.Exit(1)
}
}
cfg.RendererConcurrentRequestLimit = renderSec.Key("concurrent_render_request_limit").MustInt(30)
cfg.RendererRenderKeyLifeTime = renderSec.Key("render_key_lifetime").MustDuration(5 * time.Minute)
cfg.RendererDefaultImageWidth = renderSec.Key("default_image_width").MustInt(1000)
@@ -1824,8 +1808,6 @@ func (cfg *Cfg) readRenderingSettings(iniFile *ini.File) error {
cfg.ImagesDir = filepath.Join(cfg.DataPath, "png")
cfg.CSVsDir = filepath.Join(cfg.DataPath, "csv")
cfg.PDFsDir = filepath.Join(cfg.DataPath, "pdf")
return nil
}
func (cfg *Cfg) readAlertingSettings(iniFile *ini.File) error {
+1 -12
View File
@@ -33,7 +33,7 @@ func TestLoadingSettings(t *testing.T) {
require.Nil(t, err)
require.Equal(t, "admin", cfg.AdminUser)
require.Equal(t, "http://localhost:3000/", cfg.RendererCallbackUrl)
require.Equal(t, "", cfg.RendererCallbackUrl)
require.Equal(t, "TLS1.2", cfg.MinTLSVersion)
})
@@ -255,17 +255,6 @@ func TestLoadingSettings(t *testing.T) {
require.Equal(t, hostname, cfg.InstanceName)
})
t.Run("Reading callback_url should add trailing slash", func(t *testing.T) {
cfg := NewCfg()
err := cfg.Load(CommandLineArgs{
HomePath: "../../",
Args: []string{"cfg:rendering.callback_url=http://myserver/renderer"},
})
require.Nil(t, err)
require.Equal(t, "http://myserver/renderer/", cfg.RendererCallbackUrl)
})
t.Run("Only sync_ttl should return the value sync_ttl", func(t *testing.T) {
cfg := NewCfg()
err := cfg.Load(CommandLineArgs{