From 7aa7aea550e694891f3b9c407ed440d08b26b7e1 Mon Sep 17 00:00:00 2001 From: Elias Nahum Date: Wed, 17 Apr 2024 07:25:47 +0800 Subject: [PATCH] Avoid crash if configuration is nil (#538) * Avoid crash if configuration is nil * feedback review * clone the config so that is immutable --- server/plugin.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/server/plugin.go b/server/plugin.go index 3254ab824..e3214b99b 100644 --- a/server/plugin.go +++ b/server/plugin.go @@ -420,29 +420,31 @@ func (p *Plugin) restart() { func (p *Plugin) generatePluginSecrets() error { needSaveConfig := false - if p.configuration.WebhookSecret == "" { + cfg := p.getConfiguration().Clone() + if cfg.WebhookSecret == "" { secret, err := generateSecret() if err != nil { return err } - p.configuration.WebhookSecret = secret + cfg.WebhookSecret = secret needSaveConfig = true } - if p.configuration.EncryptionKey == "" { + if cfg.EncryptionKey == "" { secret, err := generateSecret() if err != nil { return err } - p.configuration.EncryptionKey = secret + cfg.EncryptionKey = secret needSaveConfig = true } if needSaveConfig { - configMap, err := p.configuration.ToMap() + configMap, err := cfg.ToMap() if err != nil { return err } + p.setConfiguration(cfg) if appErr := p.API.SavePluginConfig(configMap); appErr != nil { return appErr }