diff --git a/config/map.json b/config/map.json new file mode 100644 index 00000000..cb35bded --- /dev/null +++ b/config/map.json @@ -0,0 +1,274 @@ +{ + "DELETE-/_ingest/pipeline/:id": "ingest.delete_pipeline", + "DELETE-/_scripts/:id": "script.delete", + "DELETE-/_search/scroll": "scroll.delete", + "DELETE-/_search/scroll/:scroll_id":"scroll.delete", + "DELETE-/_snapshot/:repository": "snapshot.delete_repository", + "DELETE-/_snapshot/:repository/:snapshot": "snapshot.delete", + "DELETE-/_template/:name": "indices.delete_template", + "DELETE-/:index": "indices.delete", + "DELETE-/:index/_alias/:name": "indices.delete_alias", + "DELETE-/:index/_aliases/:name": "indices.delete_alias", + "DELETE-/:index/_doc/:id": "doc.delete", + + "GET-/": "cluster.info", + "GET-/_alias": "indices.get_alias", + "GET-/_alias/:name": "indices.get_alias", + "GET-/_analyze": "indices.analyze", + "GET-/_cat": "cat.help", + "GET-/_cat/aliases": "cat.aliases", + "GET-/_cat/aliases/:name": "cat.aliases", + "GET-/_cat/allocation": "cat.allocation", + "GET-/_cat/allocation/:node_id": "cat.allocation", + "GET-/_cat/count": "cat.count", + "GET-/_cat/count/:index": "cat.count", + "GET-/_cat/fielddata": "cat.fielddata", + "GET-/_cat/fielddata/:fields": "cat.fielddata", + "GET-/_cat/health": "cat.health", + "GET-/_cat/indices": "cat.indices", + "GET-/_cat/indices/:index": "cat.indices", + "GET-/_cat/master": "cat.master", + "GET-/_cat/nodeattrs": "cat.nodeattrs", + "GET-/_cat/nodes": "cat.nodes", + "GET-/_cat/pending_tasks": "cat.pending_tasks", + "GET-/_cat/plugins": "cat.plugins", + "GET-/_cat/recovery": "cat.recovery", + "GET-/_cat/recovery/:index": "cat.recovery", + "GET-/_cat/repositories": "cat.repositories", + "GET-/_cat/segments": "cat.segments", + "GET-/_cat/segments/:index": "cat.segments", + "GET-/_cat/shards": "cat.shards", + "GET-/_cat/shards/:index": "cat.shards", + "GET-/_cat/snapshots": "cat.snapshots", + "GET-/_cat/snapshots/:repository": "cat.snapshots", + "GET-/_cat/tasks": "cat.tasks", + "GET-/_cat/templates": "cat.templates", + "GET-/_cat/templates/:name": "cat.templates", + "GET-/_cat/thread_pool": "cat.thread_pool", + "GET-/_cat/thread_pool/:thread_pool_patterns": "cat.thread_pool", + "GET-/_cluster/allocation/explain": "cluster.allocation_explain", + "GET-/_cluster/health": "cluster.health", + "GET-/_cluster/health/:index": "cluster.health", + "GET-/_cluster/nodes/hot_threads": "nodes.hot_threads", + "GET-/_cluster/nodes/hotthreads": "nodes.hot_threads", + "GET-/_cluster/nodes/:node_id/hot_threads": "nodes.hot_threads", + "GET-/_cluster/nodes/:node_id/hotthreads": "nodes.hot_threads", + "GET-/_cluster/pending_tasks": "cluster.pending_tasks", + "GET-/_cluster/settings": "cluster.get_settings", + "GET-/_cluster/state": "cluster.state", + "GET-/_cluster/state/:metric": "cluster.state", + "GET-/_cluster/state/:metric/:index": "cluster.state", + "GET-/_cluster/stats": "cluster.stats", + "GET-/_cluster/stats/nodes/:node_id": "cluster.stats", + "GET-/_count": "cluster.count", + + "GET-/_flush": "indices.flush", + "GET-/_flush/synced": "indices.flush_synced", + "GET-/_ingest/pipeline": "ingest.get_pipeline", + "GET-/_ingest/pipeline/_simulate": "ingest.simulate", + "GET-/_ingest/pipeline/:id": "ingest.get_pipeline", + "GET-/_ingest/pipeline/:id/_simulate": "ingest.simulate", + "GET-/_ingest/processor/grok": "ingest.processor_grok", + "GET-/_mapping": "indices.get_mapping", + + "GET-/_mget": "cluster.mget", + "GET-/_msearch": "cluster.msearch", + "GET-/_msearch/template": "cluster.msearch_template", + "GET-/_mtermvectors": "cluster.mtermvectors", + "GET-/_nodes": "nodes.info", + "GET-/_nodes/hot_threads": "nodes.hot_threads", + "GET-/_nodes/hotthreads": "nodes.hot_threads", + "GET-/_nodes/stats": "nodes.stats", + "GET-/_nodes/stats/:metric": "nodes.stats", + "GET-/_nodes/stats/:metric/:index_metric": "nodes.stats", + "GET-/_nodes/usage": "nodes.usage", + "GET-/_nodes/usage/:metric": "nodes.usage", + "GET-/_nodes/:metric": "nodes.info", + "GET-/_nodes/:node_id": "nodes.info", + "GET-/_nodes/:node_id/hot_threads": "nodes.hot_threads", + "GET-/_nodes/:node_id/hotthreads": "nodes.hot_threads", + "GET-/_nodes/:node_id/stats": "nodes.stats", + "GET-/_nodes/:node_id/stats/:metric": "nodes.stats", + "GET-/_nodes/:node_id/stats/:metric/:index_metric": "nodes.stats", + "GET-/_nodes/:node_id/usage": "nodes.usage", + "GET-/_nodes/:node_id/usage/:metric": "nodes.usage", + "GET-/_nodes/:node_id/:metric": "nodes.info", + "GET-/_rank_eval": "cluster.rank_eval", + "GET-/_recovery": "indices.recovery", + "GET-/_refresh": "indices.refresh", + "GET-/_remote/info": "cluster.remote_info", + "GET-/_render/template": "render_search_template", + "GET-/_render/template/:id": "render_search_template", + "GET-/_scripts/painless/_execute": "scripts.painless_execute", + "GET-/_scripts/:id": "scripts.get", + "GET-/_search": "cluster.search", + "GET-/_search/scroll": "scroll.get", + "GET-/_search/scroll/:scroll_id": "scroll.get", + "GET-/_search/template": "search_template", + "GET-/_search_shards": "cluster.search_shards", + "GET-/_segments": "indices.segments", + "GET-/_settings": "indices.get_settings", + "GET-/_settings/:name": "indices.get_settings", + "GET-/_shard_stores": "indices.shard_stores", + "GET-/_snapshot": "snapshot.get_repository", + "GET-/_snapshot/_status": "snapshot.status", + "GET-/_snapshot/:repository": "snapshot.get_repository", + "GET-/_snapshot/:repository/_status": "snapshot.status", + "GET-/_snapshot/:repository/:snapshot": "snapshot.get", + "GET-/_snapshot/:repository/:snapshot/_status": "snapshot.status", + "GET-/_stats": "indices.stats", + "GET-/_stats/:metric": "indices.stats", + "GET-/_tasks": "tasks.list", + "GET-/_tasks/:task_id": "tasks.get", + "GET-/_template": "indices.get_template", + "GET-/_template/:name": "indices.get_template", + "GET-/_upgrade": "indices.get_upgrade", + "GET-/_validate/query": "indices.validate_query", + "GET-/:index": "indices.get", + "GET-/:index/_alias": "indices.get_alias", + "GET-/:index/_alias/:name": "indices.get_alias", + "GET-/:index/_analyze": "indices.analyze", + "GET-/:index/_count": "indices.count", + "GET-/:index/_doc/:id": "doc.get", + "GET-/:index/_field_caps": "indices.field_caps", + "GET-/:index/_flush": "indices.flush", + "GET-/:index/_flush/synced": "indices.flush_synced", + "GET-/:index/_mapping": "indices.get_mapping", + "GET-/:index/_mappings": "indices.get_mapping", + "GET-/:index/_mapping/field/:fields": "indices.get_field_mapping", + + "GET-/:index/_mget": "indices.mget", + "GET-/:index/_msearch": "indices.msearch", + "GET-/:index/_msearch/template": "indices.msearch_template", + "GET-/:index/_mtermvectors": "indices.mtermvectors", + "GET-/:index/_rank_eval": "indices.rank_eval", + "GET-/:index/_recovery": "indices.recovery", + "GET-/:index/_refresh": "indices.refresh", + "GET-/:index/_search": "indices.search", + "GET-/:index/_search/template": "indices.search_template", + "GET-/:index/_search_shards": "indices.search_shards", + "GET-/:index/_segments": "indices.segments", + "GET-/:index/_settings": "indices.get_settings", + "GET-/:index/_settings/:name": "indices.get_settings", + "GET-/:index/_shard_stores": "indices.shard_stores", + "GET-/:index/_stats": "indices.stats", + "GET-/:index/_stats/:metric": "indices.stats", + "GET-/:index/_upgrade": "indices.get_upgrade", + "GET-/:index/_validate/query": "indices.validate_query", + + "HEAD-/": "cluster.info", + "HEAD-/_alias/:name": "indices.exists_alias", + "HEAD-/_template/:name": "indices.exists_template", + "HEAD-/:index": "indices.exists", + "HEAD-/:index/_alias/:name": "indices.exists_alias", + "HEAD-/:index/_analyze": "indices.analyze", + "HEAD-/:index/_mapping/{type}": "indices.exists_type", + + "HEAD-/:index/_doc/{id}": "doc.exists", + "HEAD-/:index/_doc/{id}/_source": "doc.exists_source", + + "POST-/_aliases": "indices.update_aliases", + "POST-/_analyze": "indices.analyze", + "POST-/_bulk": "cluster.bulk", + "POST-/_cache/clear": "indices.clear_cache", + "POST-/_cluster/allocation/explain": "cluster.allocation_explain", + "POST-/_cluster/reroute": "cluster.reroute", + "POST-/_count": "cluster.count", + "POST-/_delete_by_query/:task_id/_rethrottle": "reindex_rethrottle", + "POST-/_field_caps": "cluster.field_caps", + "POST-/_flush": "indices.flush", + "POST-/_flush/synced": "indices.flush_synced", + "POST-/_forcemerge": "indices.forcemerge", + "POST-/_ingest/pipeline/_simulate": "ingest.simulate", + "POST-/_ingest/pipeline/:id/_simulate": "ingest.simulate", + + "POST-/_mget": "cluster.mget", + "POST-/_msearch": "cluster.msearch", + "POST-/_msearch/template": "cluster.msearch_template", + "POST-/_mtermvectors": "cluster.mtermvectors", + "POST-/_nodes/reload_secure_settings": "nodes.reload_secure_settings", + "POST-/_nodes/:node_id/reload_secure_settings": "nodes.reload_secure_settings", + "POST-/_rank_eval": "cluster.rank_eval", + "POST-/_refresh": "indices.refresh", + "POST-/_reindex": "reindex", + "POST-/_reindex/:task_id/_rethrottle": "reindex_rethrottle", + "POST-/_render/template": "render_search_template.create", + "POST-/_render/template/:id": "render_search_template.get", + "POST-/_scripts/painless/_execute": "scripts_painless_execute", + "POST-/_scripts/:id": "scripts.put", + "POST-/_scripts/:id/:context": "scripts.put", + + "POST-/_search/scroll": "scroll.create", + "POST-/_search/scroll/:scroll_id": "scroll.create", + "POST-/_search/template": "search_template", + + "POST-/_snapshot/:repository": "snapshot.create_repository", + "POST-/_snapshot/:repository/_verify": "snapshot.verify_repository", + "POST-/_snapshot/:repository/:snapshot": "snapshot.create", + "POST-/_snapshot/:repository/:snapshot/_restore": "snapshot.restore", + "POST-/_tasks/_cancel": "tasks.cancel", + "POST-/_tasks/:task_id/_cancel": "tasks.cancel", + "POST-/_template/:name": "indices.put_template", + "POST-/_update_by_query/:task_id/_rethrottle": "reindex_rethrottle", + "POST-/_upgrade": "indices.upgrade", + "POST-/_validate/query": "indices.validate_query", + "POST-/:alias/_rollover": "indices.rollover", + "POST-/:alias/_rollover/:new_index": "indices.rollover", + "POST-/:index/_alias/:name": "indices.put_alias", + "POST-/:index/_aliases/:name": "indices.put_alias", + "POST-/:index/_analyze": "indices.analyze", + "POST-/:index/_bulk": "indices.bulk", + "POST-/:index/_cache/clear": "indices.clear_cache", + "POST-/:index/_close": "indices.close", + "POST-/:index/_count": "indices.count", + "POST-/:index/_delete_by_query": "indices.delete_by_query", + "POST-/:index/_doc": "doc.create", + "POST-/:index/_doc/:id": "doc.update", + "POST-/:index/_doc/:id/_update": "doc.update", + "POST-/:index/_field_caps": "indices.field_caps", + "POST-/:index/_flush": "indices.flush", + "POST-/:index/_flush/synced": "indices.flush_synced", + "POST-/:index/_forcemerge": "indices.forcemerge", + + "POST-/:index/_mget": "indices.mget", + "POST-/:index/_msearch": "indices.msearch", + "POST-/:index/_msearch/template": "indices.msearch_template", + "POST-/:index/_mtermvectors": "indices.mtermvectors", + "POST-/:index/_open": "indices.open", + "POST-/:index/_rank_eval": "indices.rank_eval", + "POST-/:index/_refresh": "indices.refresh", + "POST-/:index/_search": "indices.search", + "POST-/:index/_search/template": "indices.search_template", + "POST-/:index/_search_shards": "indices.search_shards", + "POST-/:index/_shrink/:target": "indices.shrink", + "POST-/:index/_split/:target": "indices.split", + "POST-/:index/_update_by_query": "indices.update_by_query", + "POST-/:index/_upgrade": "indices.upgrade", + "POST-/:index/_validate/query": "indices.validate_query", + + "POST-/:index/_mapping": "indices.put_mapping", + "POST-/:index/_mappings": "indices.put_mapping", + "PUT-/_bulk": "cluster.bulk", + "PUT-/_cluster/settings": "cluster.put_settings", + "PUT-/_ingest/pipeline/:id": "ingest.put_pipeline", + + "PUT-/_scripts/:id": "scripts.put", + "PUT-/_scripts/:id/:context": "scripts.put", + "PUT-/_settings": "cluster.settings_put", + "PUT-/_snapshot/:repository": "snapshot.create_repository", + "PUT-/_snapshot/:repository/:snapshot": "snapshot.create", + "PUT-/_template/:name": "indices.put_template", + "PUT-/:index": "indices.put", + "PUT-/:index/_alias/:name": "indices.put_alias", + "PUT-/:index/_aliases/:name": "indices.put_alias", + "PUT-/:index/_bulk": "indices.put_bulk", + + "PUT-/:index/_doc/:id": "doc.put", + + "PUT-/:index/_settings": "indices.put_settings", + "PUT-/:index/_shrink/:target": "indices.shrink", + "PUT-/:index/_split/:target": "indices.split", + + "PUT-/:index/_mapping": "indices.put_mapping", + "PUT-/:index/_mappings": "indices.put_mapping" +} \ No newline at end of file diff --git a/config/permission.json b/config/permission.json new file mode 100644 index 00000000..c5d94519 --- /dev/null +++ b/config/permission.json @@ -0,0 +1,186 @@ +{ + + "cat": [ + "cat.*", + "cat.indices", + "cat.help", + "cat.repositories", + "cat.pending_tasks", + "cat.tasks", + "cat.allocation", + "cat.count", + "cat.shards", + "cat.aliases", + "cat.nodeattrs", + "cat.templates", + "cat.thread_pool", + "cat.health", + "cat.recovery", + "cat.fielddata", + "cat.nodes", + "cat.plugins", + "cat.segments", + "cat.snapshots", + "cat.master" + ], + "cluster": [ + "cluster.*", + "cluster.health", + "cluster.get_settings", + "cluster.pending_tasks", + "cluster.stats", + "cluster.remote_info", + "cluster.allocation_explain", + "cluster.put_settings", + "cluster.reroute", + "cluster.count", + "cluster.state", + "cluster.info", + "cluster.bulk", + "cluster.mget", + "cluster.ping", + "cluster.msearch", + "cluster.msearch_template", + "cluster.mtermvectors", + "cluster.rank_eval", + "cluster.search", + "cluster.search_shards" + ], + + "doc": [ + "doc.*", + "doc.update", + + "doc.create", + "doc.delete", + "doc.get", + "doc.exists", + "doc.count", + "doc.exists_source", + "doc.bulk", + "doc.explain", + "doc.mget", + "doc.msearch", + "doc.msearch_template", + "doc.mtermvectors", + "doc.search" + ], + + "indices": [ + "indices.*", + "indices.exists_alias", + "indices.get_alias", + "indices.recovery", + "indices.delete", + "indices.put", + "indices.clear_cache", + "indices.update_by_query", + "indices.shrink", + "indices.forcemerge", + "indices.put_alias", + "indices.create", + "indices.split", + "indices.flush", + "indices.get_mapping", + "indices.upgrade", + "indices.validate_query", + "indices.exists_template", + "indices.get_upgrade", + "indices.update_aliases", + "indices.analyze", + "indices.exists", + "indices.close", + "indices.delete_template", + "indices.get_field_mapping", + "indices.delete_alias", + "indices.exists_type", + "indices.get_template", + "indices.put_template", + "indices.refresh", + "indices.segments", + "indices.termvectors", + "indices.flush_synced", + "indices.put_mapping", + "indices.get", + "indices.get_settings", + "indices.open", + "indices.put_settings", + "indices.stats", + "indices.delete_by_query", + "indices.rollover", + "indices.count", + "indices.shard_stores", + "indices.bulk", + "indices.mget", + "indices.msearch", + "indices.msearch_template", + "indices.mtermvectors", + "indices.rank_eval", + "indices.search", + "indices.search_shards", + "indices.field_caps" + ], + + "ingest": [ + "ingest.*", + "ingest.delete_pipeline", + "ingest.put_pipeline", + "ingest.simulate", + "ingest.get_pipeline", + "ingest.processor_grok" + ], + + "nodes": [ + "nodes.*", + "nodes.info", + "nodes.stats", + "nodes.reload_secure_settings", + "nodes.usage", + "nodes.hot_threads" + ], + + "reindex": [ + "reindex.*", + "reindex.rethrottle" + ], + + "render_search_template": [ + "render_search_template.*", + "render_search_template.create", + "render_search_template.*" + ], + "scripts": [ + "scripts.*", + "scripts.get", + "scripts.put", + "scripts.delete", + "scripts.painless_execute" + ], + + "scroll": [ + "scroll.*", + "scroll.delete", + "scroll.get", + "scroll.create" + ], + + "snapshot": [ + "snapshot.*", + "snapshot.get_repository", + "snapshot.create_repository", + "snapshot.create", + "snapshot.restore", + "snapshot.status", + "snapshot.delete", + "snapshot.delete_repository", + "snapshot.verify_repository", + "snapshot.get" + ], + + "tasks": [ + "tasks.*", + "tasks.list", + "tasks.cancel", + "tasks.get" + ] +} \ No newline at end of file diff --git a/console.yml b/console.yml index c0fe998d..e85401df 100644 --- a/console.yml +++ b/console.yml @@ -12,6 +12,8 @@ elasticsearch: web: enabled: true embedding_api: true + auth: + enabled: true ui: enabled: true path: .public diff --git a/main.go b/main.go index dbd69cd1..cb158c3d 100644 --- a/main.go +++ b/main.go @@ -51,7 +51,7 @@ func main() { terminalFooter := "" app := framework.NewApp("console", "INFINI Cloud Console, The easiest way to operate your own elasticsearch platform.", - config.Version,config.BuildNumber, config.LastCommitLog, config.BuildDate, config.EOLDate, terminalHeader, terminalFooter) + config.Version, config.BuildNumber, config.LastCommitLog, config.BuildDate, config.EOLDate, terminalHeader, terminalFooter) app.Init(nil) defer app.Shutdown() @@ -60,11 +60,10 @@ func main() { if app.Setup(func() { err := bootstrapRequirementCheck() - if err !=nil{ + if err != nil { panic(err) } - //load core modules first module.RegisterSystemModule(&elastic2.ElasticModule{}) module.RegisterSystemModule(&filter.FilterModule{}) @@ -76,6 +75,7 @@ func main() { module.RegisterSystemModule(&task.TaskModule{}) module.RegisterUserPlugin(&metrics.MetricsModule{}) + api.RegisterAPI("") appConfig = &config.AppConfig{ @@ -99,37 +99,19 @@ func main() { appUI = &UI{Config: appConfig} appUI.InitUI() - //uiConfig := ui.UIConfig{} - //env.ParseConfig("web", &uiConfig) - // - //if len(global.Env().SystemConfig.APIConfig.CrossDomain.AllowedOrigins)==0{ - // global.Env().SystemConfig.APIConfig.CrossDomain.AllowedOrigins= - // append(global.Env().SystemConfig.APIConfig.CrossDomain.AllowedOrigins,uiConfig.NetworkConfig.GetBindingAddr()) - //} - //apiConfig := global.Env().SystemConfig.APIConfig - //if len(apiConfig.CrossDomain.AllowedOrigins) == 0 { - // apiConfig.CrossDomain.AllowedOrigins = []string{ - // fmt.Sprintf("%s://%s", appConfig.GetSchema(), appConfig.Network.GetPublishAddr()), - // } - //} - - //start each module, with enabled provider - }, func() { module.Start() - orm.RegisterSchemaWithIndexName(model.Dict{}, "dict") orm.RegisterSchemaWithIndexName(model.Reindex{}, "reindex") orm.RegisterSchemaWithIndexName(elastic.View{}, "view") orm.RegisterSchemaWithIndexName(alerting.Alert{}, "alerting-alerts") orm.RegisterSchemaWithIndexName(elastic.CommonCommand{}, "commands") orm.RegisterSchemaWithIndexName(elastic.TraceTemplate{}, "trace-template") - orm.RegisterSchemaWithIndexName(gateway.Instance{} , "gateway-instance") - orm.RegisterSchemaWithIndexName(alerting.Rule{} , "alert-rule") - orm.RegisterSchemaWithIndexName(alerting.Alert{} , "alert-history") - + orm.RegisterSchemaWithIndexName(gateway.Instance{}, "gateway-instance") + orm.RegisterSchemaWithIndexName(alerting.Rule{}, "alert-rule") + orm.RegisterSchemaWithIndexName(alerting.Alert{}, "alert-history") api.RegisterSchema() go func() { @@ -138,6 +120,7 @@ func main() { log.Errorf("init alerting task error: %v", err) } }() + }, nil) { app.Run() } diff --git a/plugin/api/account/account.go b/plugin/api/account/account.go deleted file mode 100644 index 7ed4da78..00000000 --- a/plugin/api/account/account.go +++ /dev/null @@ -1,106 +0,0 @@ -package account - -import ( - "infini.sh/framework/core/api" - "infini.sh/framework/core/api/router" - "infini.sh/framework/core/global" - "infini.sh/framework/core/util" - "net/http" -) - -type Account struct { - api.Handler -} - -func init() { - account:=Account{} - api.HandleAPIMethod(api.POST, "/account/login", account.AccountLogin) - api.HandleAPIMethod(api.GET, "/account/current_user", account.CurrentUser) -} - -var userInSession string="user_in_session" - -func (handler Account)AccountLogin(w http.ResponseWriter, req *http.Request, ps httprouter.Params) { - - //{"userName":"admin","password":"111111","type":"account"} - - json,err:=handler.GetJSON(req) - if err!=nil{ - handler.Error(w,err) - return - } - userName,err:=json.String("userName") - if err!=nil{ - handler.Error(w,err) - return - } - password,err:=json.String("password") - if err!=nil{ - handler.Error(w,err) - return - } - - u,_:=global.Env().GetConfig("bootstrap.username","admin") - p,_:=global.Env().GetConfig("bootstrap.password","admin") - if u==userName&&p==password{ - data := util.MapStr{ - "status": "ok", - "type": "account", - "currentAuthority": "admin", - "userid": "10001", - } - api.SetSession(w,req, userInSession,userName) - handler.WriteJSON(w, data, http.StatusOK) - }else{ - data := util.MapStr{ - "status": "error", - "type": "account", - "currentAuthority": "guest", - } - handler.WriteJSON(w, data, http.StatusOK) - } -} - -func (handler Account)CurrentUser(w http.ResponseWriter, req *http.Request, ps httprouter.Params) { - - exists,user:=api.GetSession(w,req, userInSession) - if exists{ - data:=util.MapStr{ - "name": user, - "avatar": "", - "userid": "10001", - "email": "hello@infini.ltd", - "signature": "极限科技 - 专业的开源搜索与实时数据分析整体解决方案提供商。", - "title": "首席设计师", - "group": "INFINI Labs", - "tags": []util.MapStr{ - { - "key": "0", - "label": "很有想法的", - }}, - "notifyCount": 12, - "country": "China", - "geographic": util.MapStr{ - "province": util.MapStr{ - "label": "湖南省", - "key": "330000", - }, - "city": util.MapStr{ - "label": "长沙市", - "key": "330100", - }, - }, - "address": "岳麓区湘江金融中心", - "phone": "4001399200", - } - - handler.WriteJSON(w, data,200) - }else{ - data := util.MapStr{ - "status": "error", - "type": "account", - "currentAuthority": "guest", - } - handler.WriteJSON(w, data, 403) - } -} diff --git a/plugin/api/index_management/index.go b/plugin/api/index_management/index.go index 50e48c97..99ee9422 100644 --- a/plugin/api/index_management/index.go +++ b/plugin/api/index_management/index.go @@ -6,12 +6,12 @@ import ( "strings" "time" + "infini.sh/console/config" + model2 "infini.sh/console/model" "infini.sh/framework/core/api" httprouter "infini.sh/framework/core/api/router" "infini.sh/framework/core/orm" "infini.sh/framework/core/util" - "infini.sh/console/config" - model2 "infini.sh/console/model" ) type APIHandler struct { @@ -115,4 +115,4 @@ func (handler APIHandler) UpdateDictItemAction(w http.ResponseWriter, req *http. resp["payload"] = dict handler.WriteJSON(w, resp, http.StatusOK) -} +} \ No newline at end of file diff --git a/plugin/api/init.go b/plugin/api/init.go index c7f323aa..fdb60167 100644 --- a/plugin/api/init.go +++ b/plugin/api/init.go @@ -23,25 +23,26 @@ func Init(cfg *config.AppConfig) { //api.HandleAPIMethod(api.GET, "/api/dict/:id",handler.GetDictItemAction) api.HandleAPIMethod(api.DELETE, path.Join(pathPrefix, "dict/:id"), handler.DeleteDictItemAction) api.HandleAPIMethod(api.PUT, path.Join(pathPrefix, "dict/:id"), handler.UpdateDictItemAction) - api.HandleAPIMethod(api.POST, path.Join(esPrefix, "doc/:index/_search"), handler.HandleSearchDocumentAction) - api.HandleAPIMethod(api.POST, path.Join(esPrefix, "doc/:index"), handler.HandleAddDocumentAction) - api.HandleAPIMethod(api.PUT, path.Join(esPrefix, "doc/:index/:docId"), handler.HandleUpdateDocumentAction) - api.HandleAPIMethod(api.DELETE, path.Join(esPrefix, "doc/:index/:docId"), handler.HandleDeleteDocumentAction) + + api.HandleAPIMethod(api.POST, path.Join(esPrefix, "doc/:index/_search"), handler.IndexRequired(handler.HandleSearchDocumentAction, "doc.search")) + api.HandleAPIMethod(api.POST, path.Join(esPrefix, "doc/:index"), handler.IndexRequired(handler.HandleAddDocumentAction, "doc.create")) + api.HandleAPIMethod(api.PUT, path.Join(esPrefix, "doc/:index/:docId"), handler.IndexRequired(handler.HandleUpdateDocumentAction, "doc.update")) + api.HandleAPIMethod(api.DELETE, path.Join(esPrefix, "doc/:index/:docId"), handler.IndexRequired(handler.HandleDeleteDocumentAction, "doc.delete")) api.HandleAPIMethod(api.GET, path.Join(esPrefix, "doc/_validate"), handler.ValidateDocIDAction) api.HandleAPIMethod(api.POST, path.Join(pathPrefix, "rebuild/*id"), handler.HandleReindexAction) api.HandleAPIMethod(api.GET, path.Join(pathPrefix, "rebuild/_search"), handler.HandleGetRebuildListAction) api.HandleAPIMethod(api.DELETE, path.Join(pathPrefix, "rebuild/:id"), handler.HandleDeleteRebuildAction) - api.HandleAPIMethod(api.GET, path.Join(esPrefix, "_cat/indices"), handler.HandleGetIndicesAction) - api.HandleAPIMethod(api.GET, path.Join(esPrefix, "index/:index/_mappings"), handler.HandleGetMappingsAction) - api.HandleAPIMethod(api.GET, path.Join(esPrefix, "index/:index/_settings"), handler.HandleGetSettingsAction) - api.HandleAPIMethod(api.PUT, path.Join(esPrefix, "index/:index/_settings"), handler.HandleUpdateSettingsAction) - api.HandleAPIMethod(api.DELETE, path.Join(esPrefix, "index/:index"), handler.HandleDeleteIndexAction) - api.HandleAPIMethod(api.POST, path.Join(esPrefix, "index/:index"), handler.HandleCreateIndexAction) + api.HandleAPIMethod(api.GET, path.Join(esPrefix, "_cat/indices"), handler.ClusterRequired(handler.HandleGetIndicesAction, "cat.indices")) + api.HandleAPIMethod(api.GET, path.Join(esPrefix, "index/:index/_mappings"), handler.IndexRequired(handler.HandleGetMappingsAction, "indices.get_mapping")) + api.HandleAPIMethod(api.GET, path.Join(esPrefix, "index/:index/_settings"), handler.IndexRequired(handler.HandleGetSettingsAction, "indices.get_settings")) + api.HandleAPIMethod(api.PUT, path.Join(esPrefix, "index/:index/_settings"), handler.IndexRequired(handler.HandleUpdateSettingsAction, "indices.put_mapping")) + api.HandleAPIMethod(api.DELETE, path.Join(esPrefix, "index/:index"), handler.IndexRequired(handler.HandleDeleteIndexAction, "indices.delete")) + api.HandleAPIMethod(api.POST, path.Join(esPrefix, "index/:index"), handler.IndexRequired(handler.HandleCreateIndexAction, "indices.create")) - api.HandleAPIMethod(api.POST, path.Join(pathPrefix, "elasticsearch/command"), handler.HandleAddCommonCommandAction) - api.HandleAPIMethod(api.PUT, path.Join(pathPrefix, "elasticsearch/command/:cid"), handler.HandleSaveCommonCommandAction) + api.HandleAPIMethod(api.POST, path.Join(pathPrefix, "elasticsearch/command"), handler.HandleAddCommonCommandAction) + api.HandleAPIMethod(api.PUT, path.Join(pathPrefix, "elasticsearch/command/:cid"), handler.HandleSaveCommonCommandAction) api.HandleAPIMethod(api.GET, path.Join(pathPrefix, "elasticsearch/command"), handler.HandleQueryCommonCommandAction) api.HandleAPIMethod(api.DELETE, path.Join(pathPrefix, "elasticsearch/command/:cid"), handler.HandleDeleteCommonCommandAction) @@ -54,9 +55,11 @@ func Init(cfg *config.AppConfig) { // } // }, //}) + alertAPI := alerting.AlertAPI{ Config: cfg, } + alertAPI.Init() }