From a0d5c01dfd97b45478353ccff777de677f088d0f Mon Sep 17 00:00:00 2001 From: Joram Wilander Date: Mon, 27 Mar 2017 09:19:53 -0400 Subject: Implement client config/license endpoints for APIv4 (#5867) --- api4/system.go | 44 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) (limited to 'api4/system.go') diff --git a/api4/system.go b/api4/system.go index 972d526da..098f7e4b7 100644 --- a/api4/system.go +++ b/api4/system.go @@ -17,8 +17,12 @@ func InitSystem() { BaseRoutes.System.Handle("/ping", ApiHandler(getSystemPing)).Methods("GET") BaseRoutes.ApiRoot.Handle("/config", ApiSessionRequired(getConfig)).Methods("GET") - BaseRoutes.ApiRoot.Handle("/config/reload", ApiSessionRequired(configReload)).Methods("POST") BaseRoutes.ApiRoot.Handle("/config", ApiSessionRequired(updateConfig)).Methods("PUT") + BaseRoutes.ApiRoot.Handle("/config/reload", ApiSessionRequired(configReload)).Methods("POST") + BaseRoutes.ApiRoot.Handle("/config/client", ApiHandler(getClientConfig)).Methods("GET") + + BaseRoutes.ApiRoot.Handle("/license/client", ApiHandler(getClientLicense)).Methods("GET") + BaseRoutes.ApiRoot.Handle("/audits", ApiSessionRequired(getAudits)).Methods("GET") BaseRoutes.ApiRoot.Handle("/email/test", ApiSessionRequired(testEmail)).Methods("POST") BaseRoutes.ApiRoot.Handle("/database/recycle", ApiSessionRequired(databaseRecycle)).Methods("POST") @@ -155,3 +159,41 @@ func getLogs(c *Context, w http.ResponseWriter, r *http.Request) { w.Write([]byte(model.ArrayToJson(lines))) } + +func getClientConfig(c *Context, w http.ResponseWriter, r *http.Request) { + format := r.URL.Query().Get("format") + + if format == "" { + c.Err = model.NewAppError("getClientConfig", "api.config.client.old_format.app_error", nil, "", http.StatusNotImplemented) + return + } + + if format != "old" { + c.SetInvalidParam("format") + return + } + + w.Write([]byte(model.MapToJson(utils.ClientCfg))) +} + +func getClientLicense(c *Context, w http.ResponseWriter, r *http.Request) { + format := r.URL.Query().Get("format") + + if format == "" { + c.Err = model.NewAppError("getClientLicense", "api.license.client.old_format.app_error", nil, "", http.StatusNotImplemented) + return + } + + if format != "old" { + c.SetInvalidParam("format") + return + } + + etag := utils.GetClientLicenseEtag(true) + if HandleEtag(etag, "Get Client License", w, r) { + return + } + + w.Header().Set(model.HEADER_ETAG_SERVER, etag) + w.Write([]byte(model.MapToJson(utils.GetSanitizedClientLicense()))) +} -- cgit v1.2.3-1-g7c22