Skip to content

Commit

Permalink
Avoid crash if configuration is nil (#538)
Browse files Browse the repository at this point in the history
* Avoid crash if configuration is nil

* feedback review

* clone the config so that is immutable
  • Loading branch information
enahum authored Apr 16, 2024
1 parent 783364a commit 7aa7aea
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions server/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 7aa7aea

Please sign in to comment.