From 5d002145b9071292588151928c9af934f3d19c6a Mon Sep 17 00:00:00 2001 From: liugq Date: Tue, 21 Feb 2023 15:39:26 +0800 Subject: [PATCH] add credential change callback for updating password of system cluster --- plugin/setup/setup.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/plugin/setup/setup.go b/plugin/setup/setup.go index 365bc26c..fa6f15a0 100644 --- a/plugin/setup/setup.go +++ b/plugin/setup/setup.go @@ -70,6 +70,27 @@ func InvokeSetupCallback() { } func (module *Module) Start() error { + credential.RegisterChangeEvent(func(cred *credential.Credential) { + if cred == nil { + return + } + sysClusterID := global.MustLookupString(elastic.GlobalSystemElasticsearchID) + conf := elastic.GetConfig(sysClusterID) + if conf.CredentialID != cred.ID { + return + } + bv, err := cred.Decode() + if err != nil { + log.Error(err) + return + } + if basicAuth, ok := bv.(elastic.BasicAuth); ok { + err = keystore.SetValue("SYSTEM_CLUSTER_PASS", []byte(basicAuth.Password)) + if err != nil { + log.Error(err) + } + } + }) return nil } func (module *Module) Stop() error {