diff --git a/Makefile b/Makefile index 08f3718e..0b6e5d2c 100755 --- a/Makefile +++ b/Makefile @@ -4,7 +4,7 @@ SHELL=/bin/bash APP_NAME := console APP_VERSION := 1.0.0_SNAPSHOT APP_CONFIG := $(APP_NAME).yml -APP_EOLDate ?= "2023-12-31T10:10:10Z" +APP_EOLDate ?= "2024-12-31T10:10:10Z" APP_STATIC_FOLDER := .public APP_STATIC_PACKAGE := public APP_UI_FOLDER := ui diff --git a/plugin/api/gateway/api.go b/plugin/api/gateway/api.go deleted file mode 100644 index ad6d5b09..00000000 --- a/plugin/api/gateway/api.go +++ /dev/null @@ -1,60 +0,0 @@ -/* Copyright © INFINI Ltd. All rights reserved. - * web: https://infinilabs.com - * mail: hello#infini.ltd */ - -package gateway - -import ( - "infini.sh/framework/core/api" -) - -type GatewayAPI struct { - api.Handler -} - -func InitAPI() { - //gateway:=GatewayAPI{} - //api.HandleAPIMethod(api.POST, "/gateway/instance/try_connect", gateway.RequireLogin(gateway.tryConnect)) - //api.HandleAPIMethod(api.GET, "/gateway/instance/:instance_id", gateway.RequirePermission(gateway.getInstance, enum.PermissionGatewayInstanceRead)) - //api.HandleAPIMethod(api.POST, "/gateway/instance", gateway.RequirePermission(gateway.createInstance, enum.PermissionGatewayInstanceWrite)) - //api.HandleAPIMethod(api.PUT, "/gateway/instance/:instance_id", gateway.RequirePermission(gateway.updateInstance, enum.PermissionGatewayInstanceWrite)) - //api.HandleAPIMethod(api.DELETE, "/gateway/instance/:instance_id", gateway.RequirePermission(gateway.deleteInstance, enum.PermissionGatewayInstanceWrite)) - //api.HandleAPIMethod(api.GET, "/gateway/instance/_search", gateway.RequirePermission(gateway.searchInstance, enum.PermissionGatewayInstanceRead)) - //api.HandleAPIMethod(api.POST, "/gateway/instance/status", gateway.RequirePermission(gateway.getInstanceStatus, enum.PermissionGatewayInstanceRead)) - // - //api.HandleAPIMethod(api.POST, "/gateway/instance/:instance_id/_proxy", gateway.RequirePermission(gateway.proxy, enum.PermissionGatewayInstanceRead)) - - //api.HandleAPIMethod(api.GET, "/_platform/nodes", gateway.getExecutionNodes) - // - //api.HandleAPIFunc("/ws_proxy", func(w http.ResponseWriter, req *http.Request) { - // log.Debug(req.RequestURI) - // endpoint := req.URL.Query().Get("endpoint") - // path := req.URL.Query().Get("path") - // var tlsConfig = &tls.Config{ - // InsecureSkipVerify: true, - // } - // target, err := url.Parse(endpoint) - // if err != nil { - // log.Error(err) - // return - // } - // newURL, err := url.Parse(path) - // if err != nil { - // log.Error(err) - // return - // } - // req.URL.Path = newURL.Path - // req.URL.RawPath = newURL.RawPath - // req.URL.RawQuery = "" - // req.RequestURI = req.URL.RequestURI() - // req.Header.Set("HOST", target.Host) - // req.Host = target.Host - // wsProxy := NewSingleHostReverseProxy(target) - // wsProxy.Dial = (&net.Dialer{ - // Timeout: 30 * time.Second, - // KeepAlive: 30 * time.Second, - // }).Dial - // wsProxy.TLSClientConfig = tlsConfig - // wsProxy.ServeHTTP(w, req) - //}) -} \ No newline at end of file diff --git a/plugin/api/gateway/instance.go b/plugin/api/gateway/instance.go deleted file mode 100644 index 3ffe59df..00000000 --- a/plugin/api/gateway/instance.go +++ /dev/null @@ -1,455 +0,0 @@ -///* Copyright © INFINI Ltd. All rights reserved. -// * web: https://infinilabs.com -// * mail: hello#infini.ltd */ -// -package gateway -// -//import ( -// "fmt" -// log "github.com/cihub/seelog" -// "github.com/segmentio/encoding/json" -// "infini.sh/console/model" -// httprouter "infini.sh/framework/core/api/router" -// elastic2 "infini.sh/framework/core/elastic" -// "infini.sh/framework/core/model" -// "infini.sh/framework/core/orm" -// "infini.sh/framework/core/proxy" -// "infini.sh/framework/core/task" -// "infini.sh/framework/core/util" -// "infini.sh/framework/modules/elastic" -// "net/http" -// "net/url" -// "strconv" -// "strings" -// "time" -//) -// - -//func (h *GatewayAPI) getInstance(w http.ResponseWriter, req *http.Request, ps httprouter.Params) { -// id := ps.MustGetParameter("instance_id") -// -// obj := model.Instance{} -// obj.ID = id -// -// exists, err := orm.Get(&obj) -// if !exists || err != nil { -// h.WriteJSON(w, util.MapStr{ -// "_id": id, -// "found": false, -// }, http.StatusNotFound) -// return -// } -// if err != nil { -// h.WriteError(w, err.Error(), http.StatusInternalServerError) -// log.Error(err) -// return -// } -// -// h.WriteJSON(w, util.MapStr{ -// "found": true, -// "_id": id, -// "_source": obj, -// }, 200) -//} -// -//func (h *GatewayAPI) updateInstance(w http.ResponseWriter, req *http.Request, ps httprouter.Params) { -// id := ps.MustGetParameter("instance_id") -// obj := model.Instance{} -// -// obj.ID = id -// exists, err := orm.Get(&obj) -// if !exists || err != nil { -// h.WriteJSON(w, util.MapStr{ -// "_id": id, -// "result": "not_found", -// }, http.StatusNotFound) -// return -// } -// -// id = obj.ID -// create := obj.Created -// obj = model.Instance{} -// err = h.DecodeJSON(req, &obj) -// if err != nil { -// h.WriteError(w, err.Error(), http.StatusInternalServerError) -// log.Error(err) -// return -// } -// -// //protect -// obj.ID = id -// obj.Created = create -// err = orm.Update(nil, &obj) -// if err != nil { -// h.WriteError(w, err.Error(), http.StatusInternalServerError) -// log.Error(err) -// return -// } -// -// h.WriteJSON(w, util.MapStr{ -// "_id": obj.ID, -// "result": "updated", -// }, 200) -//} -// -//func (h *GatewayAPI) deleteInstance(w http.ResponseWriter, req *http.Request, ps httprouter.Params) { -// id := ps.MustGetParameter("instance_id") -// -// obj := model.Instance{} -// obj.ID = id -// -// exists, err := orm.Get(&obj) -// if !exists || err != nil { -// h.WriteJSON(w, util.MapStr{ -// "_id": id, -// "result": "not_found", -// }, http.StatusNotFound) -// return -// } -// -// //check reference -// query := util.MapStr{ -// "size": 1, -// "query": util.MapStr{ -// "bool": util.MapStr{ -// "must": []util.MapStr{ -// { -// "term": util.MapStr{ -// "metadata.labels.permit_nodes.id": util.MapStr{ -// "value": id, -// }, -// }, -// }, -// { -// "terms": util.MapStr{ -// "metadata.type": []string{"cluster_migration", "cluster_comparison"}, -// }, -// }, -// }, -// "must_not": []util.MapStr{ -// { -// "terms": util.MapStr{ -// "status": []string{task.StatusError, task.StatusComplete}, -// }, -// }, -// }, -// }, -// }, -// } -// q := &orm.Query{ -// RawQuery: util.MustToJSONBytes(query), -// } -// err, result := orm.Search(task.Task{}, q) -// if err != nil { -// h.WriteError(w, err.Error(), http.StatusInternalServerError) -// log.Error(err) -// return -// } -// if len(result.Result) > 0 { -// var taskId interface{} -// if m, ok := result.Result[0].(map[string]interface{}); ok { -// taskId = m["id"] -// } -// h.WriteError(w, fmt.Sprintf("failed to delete gateway instance [%s] since it is used by task [%v]", id, taskId), http.StatusInternalServerError) -// return -// } -// -// err = orm.Delete(nil, &obj) -// if err != nil { -// h.WriteError(w, err.Error(), http.StatusInternalServerError) -// log.Error(err) -// return -// } -// -// h.WriteJSON(w, util.MapStr{ -// "_id": obj.ID, -// "result": "deleted", -// }, 200) -//} -// -//func (h *GatewayAPI) searchInstance(w http.ResponseWriter, req *http.Request, ps httprouter.Params) { -// -// var ( -// keyword = h.GetParameterOrDefault(req, "keyword", "") -// queryDSL = `{"query":{"bool":{"must":[%s]}}, "size": %d, "from": %d}` -// strSize = h.GetParameterOrDefault(req, "size", "20") -// strFrom = h.GetParameterOrDefault(req, "from", "0") -// mustBuilder = &strings.Builder{} -// ) -// if keyword != "" { -// mustBuilder.WriteString(fmt.Sprintf(`{"query_string":{"default_field":"*","query": "%s"}}`, keyword)) -// } -// size, _ := strconv.Atoi(strSize) -// if size <= 0 { -// size = 20 -// } -// from, _ := strconv.Atoi(strFrom) -// if from < 0 { -// from = 0 -// } -// -// q := orm.Query{} -// queryDSL = fmt.Sprintf(queryDSL, mustBuilder.String(), size, from) -// q.RawQuery = []byte(queryDSL) -// -// err, res := orm.Search(&model.Instance{}, &q) -// if err != nil { -// log.Error(err) -// h.WriteError(w, err.Error(), http.StatusInternalServerError) -// return -// } -// h.Write(w, res.Raw) -//} -// -//func (h *GatewayAPI) getInstanceStatus(w http.ResponseWriter, req *http.Request, ps httprouter.Params) { -// var instanceIDs = []string{} -// err := h.DecodeJSON(req, &instanceIDs) -// if err != nil { -// log.Error(err) -// h.WriteError(w, err.Error(), http.StatusInternalServerError) -// return -// } -// if len(instanceIDs) == 0 { -// h.WriteJSON(w, util.MapStr{}, http.StatusOK) -// return -// } -// q := orm.Query{} -// queryDSL := util.MapStr{ -// "query": util.MapStr{ -// "terms": util.MapStr{ -// "_id": instanceIDs, -// }, -// }, -// } -// q.RawQuery = util.MustToJSONBytes(queryDSL) -// -// err, res := orm.Search(&model.Instance{}, &q) -// if err != nil { -// log.Error(err) -// h.WriteError(w, err.Error(), http.StatusInternalServerError) -// return -// } -// result := util.MapStr{} -// for _, item := range res.Result { -// instance := util.MapStr(item.(map[string]interface{})) -// if err != nil { -// log.Error(err) -// continue -// } -// endpoint, _ := instance.GetValue("endpoint") -// username, _ := instance.GetValue("basic_auth.username") -// if username == nil { -// username = "" -// } -// password, _ := instance.GetValue("basic_auth.password") -// if password == nil { -// password = "" -// } -// gid, _ := instance.GetValue("id") -// res, err := proxy.DoProxyRequest(&proxy.Request{ -// Endpoint: endpoint.(string), -// Method: http.MethodGet, -// Path: "/stats", -// BasicAuth: instance.BasicAuth{ -// Username: username.(string), -// Password: password.(string), -// }, -// }) -// if err != nil { -// log.Error(err) -// result[gid.(string)] = util.MapStr{} -// continue -// } -// var resMap = util.MapStr{} -// err = util.FromJSONBytes(res.Body, &resMap) -// if err != nil { -// result[gid.(string)] = util.MapStr{} -// log.Errorf("get stats of %v error: %v", endpoint, err) -// continue -// } -// -// result[gid.(string)] = resMap -// } -// h.WriteJSON(w, result, http.StatusOK) -//} -//func (h *GatewayAPI) proxy(w http.ResponseWriter, req *http.Request, ps httprouter.Params) { -// var ( -// method = h.Get(req, "method", "GET") -// path = h.Get(req, "path", "") -// ) -// instanceID := ps.MustGetParameter("instance_id") -// -// obj := model.Instance{} -// obj.ID = instanceID -// -// exists, err := orm.Get(&obj) -// if err != nil { -// h.WriteError(w, err.Error(), http.StatusInternalServerError) -// log.Error(err) -// return -// } -// if !exists { -// h.WriteJSON(w, util.MapStr{ -// "error": "gateway instance not found", -// }, http.StatusNotFound) -// return -// } -// res, err := proxy.DoProxyRequest(&proxy.Request{ -// Method: method, -// Endpoint: obj.Endpoint, -// Path: path, -// Body: req.Body, -// BasicAuth: obj.BasicAuth, -// ContentLength: int(req.ContentLength), -// }) -// if err != nil { -// h.WriteError(w, err.Error(), http.StatusInternalServerError) -// log.Error(err) -// return -// } -// h.WriteHeader(w, res.StatusCode) -// h.Write(w, res.Body) -//} -// -//type GatewayConnectResponse struct { -// ID string `json:"id"` -// Name string `json:"name"` -// Tagline string `json:"tagline"` -// Version struct { -// BuildDate string `json:"build_date"` -// BuildHash string `json:"build_hash"` -// EOLDate string `json:"eol_date"` -// Number string `json:"number"` -// } `json:"version"` -// -//} -//func (h *GatewayAPI) doConnect(endpoint string, basicAuth model.BasicAuth) (*GatewayConnectResponse, error) { -// res, err := proxy.DoProxyRequest(&proxy.Request{ -// Method: http.MethodGet, -// Endpoint: endpoint, -// Path: "/_info", -// BasicAuth: basicAuth, -// }) -// if err != nil { -// return nil, err -// } -// if res.StatusCode == http.StatusNotFound { -// return nil, fmt.Errorf("unknow gateway version") -// } -// b := res.Body -// gres := &GatewayConnectResponse{} -// err = json.Unmarshal(b, gres) -// return gres, err -// -//} -// -//func (h *GatewayAPI) tryConnect(w http.ResponseWriter, req *http.Request, ps httprouter.Params) { -// var reqBody = struct { -// Endpoint string `json:"endpoint"` -// BasicAuth model.BasicAuth -// }{} -// err := h.DecodeJSON(req, &reqBody) -// if err != nil { -// h.WriteError(w, err.Error(), http.StatusInternalServerError) -// return -// } -// connectRes, err := h.doConnect(reqBody.Endpoint, reqBody.BasicAuth) -// if err != nil { -// h.WriteError(w, err.Error(), http.StatusInternalServerError) -// return -// } -// h.WriteJSON(w, connectRes, http.StatusOK) -//} -// -//func (h *GatewayAPI) getExecutionNodes(w http.ResponseWriter, req *http.Request, ps httprouter.Params){ -// var ( -// keyword = h.GetParameterOrDefault(req, "keyword", "") -// strSize = h.GetParameterOrDefault(req, "size", "10") -// strFrom = h.GetParameterOrDefault(req, "from", "0") -// ) -// size, _ := strconv.Atoi(strSize) -// if size <= 0 { -// size = 10 -// } -// from, _ := strconv.Atoi(strFrom) -// if from < 0 { -// from = 0 -// } -// gatewayIndexName := orm.GetIndexName(model.Instance{}) -// -// query := util.MapStr{ -// "size": size, -// "from": from, -// "sort": []util.MapStr{ -// { -// "created": util.MapStr{ -// "order": "desc", -// }, -// }, -// }, -// } -// if keyword != "" { -// query["query"] = util.MapStr{ -// "bool": util.MapStr{ -// "must": []util.MapStr{ -// { -// "prefix": util.MapStr{ -// "name": util.MapStr{ -// "value": keyword, -// }, -// }, -// }, -// }, -// }, -// } -// } -// q := orm.Query{ -// IndexName: gatewayIndexName, -// RawQuery: util.MustToJSONBytes(query), -// } -// err, result := orm.Search(nil, &q) -// if err != nil { -// h.WriteError(w, err.Error(), http.StatusInternalServerError) -// return -// } -// -// searchRes := elastic2.SearchResponse{} -// err = util.FromJSONBytes(result.Raw, &searchRes) -// if err != nil||searchRes.ESError!=nil { -// msg:=fmt.Sprintf("%v,%v",err,searchRes.ESError) -// h.WriteError(w, msg, http.StatusInternalServerError) -// return -// } -// var nodes = []util.MapStr{} -// -// for _, hit := range searchRes.Hits.Hits { -// buf := util.MustToJSONBytes(hit.Source) -// inst := model.Instance{} -// err = util.FromJSONBytes(buf, &inst) -// if err != nil { -// log.Error(err) -// continue -// } -// node := util.MapStr{ -// "id": inst.ID, -// "name": inst.Name, -// "available": false, -// "type": "gateway", -// } -// ul, err := url.Parse(inst.Endpoint) -// if err != nil { -// log.Error(err) -// continue -// } -// node["host"] = ul.Host -// err = inst.TryConnectWithTimeout(time.Second) -// if err != nil { -// log.Error(err) -// }else{ -// node["available"] = true -// } -// -// nodes = append(nodes, node) -// } -// h.WriteJSON(w, nodes, http.StatusOK) -//} diff --git a/plugin/api/init.go b/plugin/api/init.go index a76fb5fa..dc3cb319 100644 --- a/plugin/api/init.go +++ b/plugin/api/init.go @@ -9,7 +9,6 @@ import ( "infini.sh/console/config" "infini.sh/console/plugin/api/alerting" - "infini.sh/console/plugin/api/gateway" "infini.sh/console/plugin/api/index_management" "infini.sh/console/plugin/api/insight" "infini.sh/console/plugin/api/layout" @@ -72,7 +71,6 @@ func Init(cfg *config.AppConfig) { alertAPI.Init() - gateway.InitAPI() insight.InitAPI() layout.InitAPI() notification.InitAPI() diff --git a/plugin/setup/setup.go b/plugin/setup/setup.go index 25614c76..53c17bdc 100644 --- a/plugin/setup/setup.go +++ b/plugin/setup/setup.go @@ -767,7 +767,7 @@ func (module *Module) initializeTemplate(w http.ResponseWriter, r *http.Request, defer fasthttp.ReleaseRequest(req) defer fasthttp.ReleaseResponse(res) - _, err, _ = replay.ReplayLines(req,res,pipeline.AcquireContext(pipeline.PipelineConfigV2{}), lines, request.Cluster.Schema, request.Cluster.Host, request.Cluster.Username, request.Cluster.Password) + _, err, _ = replay.ReplayLines(pipeline.AcquireContext(pipeline.PipelineConfigV2{}), lines, request.Cluster.Schema, request.Cluster.Host, request.Cluster.Username, request.Cluster.Password) if err != nil { module.WriteJSON(w, util.MapStr{ "success": false,