use credential to store email server auth info
This commit is contained in:
parent
fcf0179335
commit
0965256ecc
|
@ -6,6 +6,7 @@ package model
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"infini.sh/framework/core/elastic"
|
||||||
"infini.sh/framework/core/orm"
|
"infini.sh/framework/core/orm"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -15,11 +16,9 @@ type EmailServer struct {
|
||||||
Host string `json:"host" elastic_mapping:"host:{type:keyword}"`
|
Host string `json:"host" elastic_mapping:"host:{type:keyword}"`
|
||||||
Port int `json:"port" elastic_mapping:"port:{type:keyword}"`
|
Port int `json:"port" elastic_mapping:"port:{type:keyword}"`
|
||||||
TLS bool `json:"tls" elastic_mapping:"tls:{type:keyword}"`
|
TLS bool `json:"tls" elastic_mapping:"tls:{type:keyword}"`
|
||||||
Auth struct {
|
Auth *elastic.BasicAuth `json:"auth" elastic_mapping:"auth:{type:object}"`
|
||||||
Username string `json:"username" elastic_mapping:"username:{type:keyword}"`
|
|
||||||
Password string `json:"password" elastic_mapping:"password:{type:keyword}"`
|
|
||||||
} `json:"auth" elastic_mapping:"auth:{type:object}"`
|
|
||||||
Enabled bool `json:"enabled" elastic_mapping:"enabled:{type:boolean}"`
|
Enabled bool `json:"enabled" elastic_mapping:"enabled:{type:boolean}"`
|
||||||
|
CredentialID string `json:"credential_id" elastic_mapping:"credential_id:{type:keyword}"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (serv *EmailServer) Validate(requireName bool) error {
|
func (serv *EmailServer) Validate(requireName bool) error {
|
||||||
|
|
|
@ -36,6 +36,11 @@ func RefreshEmailServer() error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
auth, err := GetBasicAuth(&emailServer)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
emailServer.Auth = &auth
|
||||||
servers = append(servers, emailServer)
|
servers = append(servers, emailServer)
|
||||||
}
|
}
|
||||||
pipeCfgStr := GeneratePipelineConfig(servers)
|
pipeCfgStr := GeneratePipelineConfig(servers)
|
||||||
|
|
|
@ -293,17 +293,13 @@ func (h *EmailAPI) testEmailServer(w http.ResponseWriter, req *http.Request, ps
|
||||||
h.WriteError(w, err.Error(), http.StatusInternalServerError)
|
h.WriteError(w, err.Error(), http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if reqBody.Auth.Password == "" && reqBody.ID != "" {
|
if reqBody.Auth.Password == "" && reqBody.CredentialID != "" {
|
||||||
obj := model.EmailServer{}
|
auth, err := common.GetBasicAuth(&reqBody.EmailServer)
|
||||||
obj.ID = reqBody.ID
|
|
||||||
_, err := orm.Get(&obj)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
h.WriteError(w, err.Error(), http.StatusInternalServerError)
|
h.WriteError(w, err.Error(), http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if reqBody.Auth.Username == obj.Auth.Username {
|
reqBody.Auth = &auth
|
||||||
reqBody.Auth.Password = obj.Auth.Password
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
message := gomail.NewMessage()
|
message := gomail.NewMessage()
|
||||||
message.SetHeader("From", reqBody.Auth.Username)
|
message.SetHeader("From", reqBody.Auth.Username)
|
||||||
|
|
Loading…
Reference in New Issue