[plugin] fix naming (#42)
[plugin] fix naming Co-authored-by: Kassian Sun <kassiansun@outlook.com>
This commit is contained in:
parent
24ca0c91a5
commit
08a1673c1a
|
@ -5,6 +5,14 @@ import (
|
||||||
"crypto/md5"
|
"crypto/md5"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"net/http"
|
||||||
|
uri2 "net/url"
|
||||||
|
"path"
|
||||||
|
"path/filepath"
|
||||||
|
"runtime"
|
||||||
|
"time"
|
||||||
|
|
||||||
log "github.com/cihub/seelog"
|
log "github.com/cihub/seelog"
|
||||||
"github.com/valyala/fasttemplate"
|
"github.com/valyala/fasttemplate"
|
||||||
"golang.org/x/crypto/bcrypt"
|
"golang.org/x/crypto/bcrypt"
|
||||||
|
@ -27,13 +35,6 @@ import (
|
||||||
elastic1 "infini.sh/framework/modules/elastic/common"
|
elastic1 "infini.sh/framework/modules/elastic/common"
|
||||||
"infini.sh/framework/modules/security"
|
"infini.sh/framework/modules/security"
|
||||||
"infini.sh/framework/plugins/replay"
|
"infini.sh/framework/plugins/replay"
|
||||||
"io"
|
|
||||||
"net/http"
|
|
||||||
uri2 "net/url"
|
|
||||||
"path"
|
|
||||||
"path/filepath"
|
|
||||||
"runtime"
|
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type Module struct {
|
type Module struct {
|
||||||
|
@ -60,6 +61,7 @@ func (module *Module) Setup() {
|
||||||
}
|
}
|
||||||
|
|
||||||
var setupFinishedCallback = []func(){}
|
var setupFinishedCallback = []func(){}
|
||||||
|
|
||||||
func RegisterSetupCallback(f func()) {
|
func RegisterSetupCallback(f func()) {
|
||||||
setupFinishedCallback = append(setupFinishedCallback, f)
|
setupFinishedCallback = append(setupFinishedCallback, f)
|
||||||
}
|
}
|
||||||
|
@ -169,7 +171,6 @@ func (module *Module) validate(w http.ResponseWriter, r *http.Request, ps httpro
|
||||||
module.WriteJSON(w, result, code)
|
module.WriteJSON(w, result, code)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
|
||||||
err, client, _ := module.initTempClient(r)
|
err, client, _ := module.initTempClient(r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
|
@ -177,7 +178,7 @@ func (module *Module) validate(w http.ResponseWriter, r *http.Request, ps httpro
|
||||||
|
|
||||||
//validate version
|
//validate version
|
||||||
verInfo, err := adapter.ClusterVersion(elastic.GetMetadata(cfg.ID))
|
verInfo, err := adapter.ClusterVersion(elastic.GetMetadata(cfg.ID))
|
||||||
if verInfo.Version.Distribution == elastic.Elasticsarch {
|
if verInfo.Version.Distribution == elastic.Elasticsearch {
|
||||||
if verInfo.Version.Number != "" {
|
if verInfo.Version.Number != "" {
|
||||||
ver := &util.Version{}
|
ver := &util.Version{}
|
||||||
ver, err = util.ParseSemantic(verInfo.Version.Number)
|
ver, err = util.ParseSemantic(verInfo.Version.Number)
|
||||||
|
@ -243,7 +244,9 @@ func (module *Module) validate(w http.ResponseWriter, r *http.Request, ps httpro
|
||||||
|
|
||||||
success = true
|
success = true
|
||||||
}
|
}
|
||||||
|
|
||||||
var cfg elastic.ElasticsearchConfig
|
var cfg elastic.ElasticsearchConfig
|
||||||
|
|
||||||
func (module *Module) initTempClient(r *http.Request) (error, elastic.API, SetupRequest) {
|
func (module *Module) initTempClient(r *http.Request) (error, elastic.API, SetupRequest) {
|
||||||
request := SetupRequest{}
|
request := SetupRequest{}
|
||||||
err := module.DecodeJSON(r, &request)
|
err := module.DecodeJSON(r, &request)
|
||||||
|
@ -280,7 +283,6 @@ func (module *Module) initTempClient(r *http.Request) (error, elastic.API,SetupR
|
||||||
cfg.Schema = uri.Scheme
|
cfg.Schema = uri.Scheme
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
cfg.ID = GlobalSystemElasticsearchID
|
cfg.ID = GlobalSystemElasticsearchID
|
||||||
cfg.Name = "INFINI_SYSTEM (" + util.PickRandomName() + ")"
|
cfg.Name = "INFINI_SYSTEM (" + util.PickRandomName() + ")"
|
||||||
elastic.InitMetadata(&cfg, true)
|
elastic.InitMetadata(&cfg, true)
|
||||||
|
@ -402,7 +404,7 @@ func (module *Module) initialize(w http.ResponseWriter, r *http.Request, ps http
|
||||||
//INDEX_PREFIX
|
//INDEX_PREFIX
|
||||||
ver := elastic.GetClient(GlobalSystemElasticsearchID).GetVersion()
|
ver := elastic.GetClient(GlobalSystemElasticsearchID).GetVersion()
|
||||||
dslTplFileName := "initialization.tpl"
|
dslTplFileName := "initialization.tpl"
|
||||||
if ver.Distribution == "" || ver.Distribution == elastic.Elasticsarch { //elasticsearch distribution
|
if ver.Distribution == "" || ver.Distribution == elastic.Elasticsearch { //elasticsearch distribution
|
||||||
majorVersion := elastic.GetClient(GlobalSystemElasticsearchID).GetMajorVersion()
|
majorVersion := elastic.GetClient(GlobalSystemElasticsearchID).GetMajorVersion()
|
||||||
if majorVersion == 6 {
|
if majorVersion == 6 {
|
||||||
dslTplFileName = "initialization_v6.tpl"
|
dslTplFileName = "initialization_v6.tpl"
|
||||||
|
@ -411,7 +413,6 @@ func (module *Module) initialize(w http.ResponseWriter, r *http.Request, ps http
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
dslTplFile := path.Join(global.Env().GetConfigDir(), dslTplFileName)
|
dslTplFile := path.Join(global.Env().GetConfigDir(), dslTplFileName)
|
||||||
dslFile := path.Join(global.Env().GetConfigDir(), "initialization.dsl")
|
dslFile := path.Join(global.Env().GetConfigDir(), "initialization.dsl")
|
||||||
|
|
||||||
|
@ -480,7 +481,6 @@ func (module *Module) initialize(w http.ResponseWriter, r *http.Request, ps http
|
||||||
//init security
|
//init security
|
||||||
security.InitSecurity()
|
security.InitSecurity()
|
||||||
|
|
||||||
|
|
||||||
toSaveCfg := cfg
|
toSaveCfg := cfg
|
||||||
if request.Cluster.Username != "" || request.Cluster.Password != "" {
|
if request.Cluster.Username != "" || request.Cluster.Password != "" {
|
||||||
cred := credential.Credential{
|
cred := credential.Credential{
|
||||||
|
@ -545,7 +545,6 @@ func (module *Module) initialize(w http.ResponseWriter, r *http.Request, ps http
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//save to local file
|
//save to local file
|
||||||
file := path.Join(global.Env().GetConfigDir(), "system_config.yml")
|
file := path.Join(global.Env().GetConfigDir(), "system_config.yml")
|
||||||
_, err = util.FilePutContent(file, fmt.Sprintf("configs.template:\n - name: \"system\"\n path: ./config/system_config.tpl\n variable:\n "+
|
_, err = util.FilePutContent(file, fmt.Sprintf("configs.template:\n - name: \"system\"\n path: ./config/system_config.tpl\n variable:\n "+
|
||||||
|
|
Loading…
Reference in New Issue