Merge branch 'master' of ssh://git.infini.ltd:64221/infini/console
This commit is contained in:
commit
eb5b7b686c
|
@ -5,8 +5,13 @@
|
||||||
package email
|
package email
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
log "github.com/cihub/seelog"
|
||||||
|
"infini.sh/console/model"
|
||||||
"infini.sh/console/plugin/api/email/common"
|
"infini.sh/console/plugin/api/email/common"
|
||||||
"infini.sh/framework/core/api"
|
"infini.sh/framework/core/api"
|
||||||
|
"infini.sh/framework/core/credential"
|
||||||
|
"infini.sh/framework/core/orm"
|
||||||
|
"infini.sh/framework/core/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
type EmailAPI struct {
|
type EmailAPI struct {
|
||||||
|
@ -20,6 +25,46 @@ func InitAPI() {
|
||||||
api.HandleAPIMethod(api.PUT, "/email/server/:email_server_id", email.updateEmailServer)
|
api.HandleAPIMethod(api.PUT, "/email/server/:email_server_id", email.updateEmailServer)
|
||||||
api.HandleAPIMethod(api.DELETE, "/email/server/:email_server_id", email.deleteEmailServer)
|
api.HandleAPIMethod(api.DELETE, "/email/server/:email_server_id", email.deleteEmailServer)
|
||||||
api.HandleAPIMethod(api.GET, "/email/server/_search", email.searchEmailServer)
|
api.HandleAPIMethod(api.GET, "/email/server/_search", email.searchEmailServer)
|
||||||
|
|
||||||
|
credential.RegisterChangeEvent(func(cred *credential.Credential) {
|
||||||
|
query := util.MapStr{
|
||||||
|
"size": 1,
|
||||||
|
"query": util.MapStr{
|
||||||
|
"bool": util.MapStr{
|
||||||
|
"must": []util.MapStr{
|
||||||
|
{
|
||||||
|
"term": util.MapStr{
|
||||||
|
"credential_id": util.MapStr{
|
||||||
|
"value": cred.ID,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"term": util.MapStr{
|
||||||
|
"enabled": util.MapStr{
|
||||||
|
"value": true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
q := orm.Query{
|
||||||
|
RawQuery: util.MustToJSONBytes(query),
|
||||||
|
}
|
||||||
|
err, result := orm.Search(model.EmailServer{}, &q)
|
||||||
|
if err != nil {
|
||||||
|
log.Error(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if len(result.Result) > 0 {
|
||||||
|
err = common.RefreshEmailServer()
|
||||||
|
if err != nil {
|
||||||
|
log.Error("refresh email server pipeline error: ", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func InitEmailServer() error {
|
func InitEmailServer() error {
|
||||||
|
|
|
@ -14,6 +14,7 @@ import (
|
||||||
"infini.sh/framework/core/util"
|
"infini.sh/framework/core/util"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
const emailServerConfigFile = "send_email.yml"
|
const emailServerConfigFile = "send_email.yml"
|
||||||
|
@ -90,6 +91,7 @@ func GeneratePipelineConfig(servers []model.EmailServer) (string, error) {
|
||||||
"host": srv.Host,
|
"host": srv.Host,
|
||||||
"port": srv.Port,
|
"port": srv.Port,
|
||||||
"tls": srv.TLS,
|
"tls": srv.TLS,
|
||||||
|
"refresh_timestamp": time.Now().UnixMilli(),
|
||||||
},
|
},
|
||||||
"auth": util.MapStr{
|
"auth": util.MapStr{
|
||||||
"username": srv.Auth.Username,
|
"username": srv.Auth.Username,
|
||||||
|
|
Loading…
Reference in New Issue