add credential change callback for updating password of system cluster

This commit is contained in:
liugq 2023-02-21 15:39:26 +08:00
parent cc4f824ff5
commit 5d002145b9
1 changed files with 21 additions and 0 deletions

View File

@ -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 {