Implement client config/license endpoints for APIv4 (#5867)
Этот коммит содержится в:
коммит произвёл
Christopher Speller
родитель
d145c35838
Коммит
a0d5c01dfd
@@ -17,8 +17,12 @@ func InitSystem() {
|
|||||||
|
|
||||||
BaseRoutes.System.Handle("/ping", ApiHandler(getSystemPing)).Methods("GET")
|
BaseRoutes.System.Handle("/ping", ApiHandler(getSystemPing)).Methods("GET")
|
||||||
BaseRoutes.ApiRoot.Handle("/config", ApiSessionRequired(getConfig)).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", 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("/audits", ApiSessionRequired(getAudits)).Methods("GET")
|
||||||
BaseRoutes.ApiRoot.Handle("/email/test", ApiSessionRequired(testEmail)).Methods("POST")
|
BaseRoutes.ApiRoot.Handle("/email/test", ApiSessionRequired(testEmail)).Methods("POST")
|
||||||
BaseRoutes.ApiRoot.Handle("/database/recycle", ApiSessionRequired(databaseRecycle)).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)))
|
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())))
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package api4
|
package api4
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
@@ -129,6 +130,58 @@ func TestUpdateConfig(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestGetOldClientConfig(t *testing.T) {
|
||||||
|
th := Setup().InitBasic().InitSystemAdmin()
|
||||||
|
defer TearDown()
|
||||||
|
Client := th.Client
|
||||||
|
|
||||||
|
config, resp := Client.GetOldClientConfig("")
|
||||||
|
CheckNoError(t, resp)
|
||||||
|
|
||||||
|
if len(config["Version"]) == 0 {
|
||||||
|
t.Fatal("config not returned correctly")
|
||||||
|
}
|
||||||
|
|
||||||
|
Client.Logout()
|
||||||
|
|
||||||
|
_, resp = Client.GetOldClientConfig("")
|
||||||
|
CheckNoError(t, resp)
|
||||||
|
|
||||||
|
if _, err := Client.DoApiGet("/config/client", ""); err == nil || err.StatusCode != http.StatusNotImplemented {
|
||||||
|
t.Fatal("should have errored with 501")
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, err := Client.DoApiGet("/config/client?format=junk", ""); err == nil || err.StatusCode != http.StatusBadRequest {
|
||||||
|
t.Fatal("should have errored with 400")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestGetOldClientLicense(t *testing.T) {
|
||||||
|
th := Setup().InitBasic().InitSystemAdmin()
|
||||||
|
defer TearDown()
|
||||||
|
Client := th.Client
|
||||||
|
|
||||||
|
license, resp := Client.GetOldClientLicense("")
|
||||||
|
CheckNoError(t, resp)
|
||||||
|
|
||||||
|
if len(license["IsLicensed"]) == 0 {
|
||||||
|
t.Fatal("license not returned correctly")
|
||||||
|
}
|
||||||
|
|
||||||
|
Client.Logout()
|
||||||
|
|
||||||
|
_, resp = Client.GetOldClientLicense("")
|
||||||
|
CheckNoError(t, resp)
|
||||||
|
|
||||||
|
if _, err := Client.DoApiGet("/license/client", ""); err == nil || err.StatusCode != http.StatusNotImplemented {
|
||||||
|
t.Fatal("should have errored with 501")
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, err := Client.DoApiGet("/license/client?format=junk", ""); err == nil || err.StatusCode != http.StatusBadRequest {
|
||||||
|
t.Fatal("should have errored with 400")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestGetAudits(t *testing.T) {
|
func TestGetAudits(t *testing.T) {
|
||||||
th := Setup().InitBasic().InitSystemAdmin()
|
th := Setup().InitBasic().InitSystemAdmin()
|
||||||
defer TearDown()
|
defer TearDown()
|
||||||
|
|||||||
@@ -47,6 +47,14 @@
|
|||||||
"id": "September",
|
"id": "September",
|
||||||
"translation": "September"
|
"translation": "September"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"id": "api.config.client.old_format.app_error",
|
||||||
|
"translation": "New format for the client configuration is not supported yet. Please specify format=old in the query string."
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "api.license.client.old_format.app_error",
|
||||||
|
"translation": "New format for the client license is not supported yet. Please specify format=old in the query string."
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"id": "api.admin.add_certificate.no_file.app_error",
|
"id": "api.admin.add_certificate.no_file.app_error",
|
||||||
"translation": "No file under 'certificate' in request"
|
"translation": "No file under 'certificate' in request"
|
||||||
|
|||||||
@@ -130,6 +130,10 @@ func (c *Client4) GetConfigRoute() string {
|
|||||||
return fmt.Sprintf("/config")
|
return fmt.Sprintf("/config")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *Client4) GetLicenseRoute() string {
|
||||||
|
return fmt.Sprintf("/license")
|
||||||
|
}
|
||||||
|
|
||||||
func (c *Client4) GetPostRoute(postId string) string {
|
func (c *Client4) GetPostRoute(postId string) string {
|
||||||
return fmt.Sprintf(c.GetPostsRoute()+"/%v", postId)
|
return fmt.Sprintf(c.GetPostsRoute()+"/%v", postId)
|
||||||
}
|
}
|
||||||
@@ -1344,6 +1348,7 @@ func (c *Client4) GetPing() (bool, *Response) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TestEmail will attempt to connect to the configured SMTP server.
|
||||||
func (c *Client4) TestEmail() (bool, *Response) {
|
func (c *Client4) TestEmail() (bool, *Response) {
|
||||||
if r, err := c.DoApiPost(c.GetTestEmailRoute(), ""); err != nil {
|
if r, err := c.DoApiPost(c.GetTestEmailRoute(), ""); err != nil {
|
||||||
return false, &Response{StatusCode: r.StatusCode, Error: err}
|
return false, &Response{StatusCode: r.StatusCode, Error: err}
|
||||||
@@ -1373,6 +1378,28 @@ func (c *Client4) ReloadConfig() (bool, *Response) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetOldClientConfig will retrieve the parts of the server configuration needed by the
|
||||||
|
// client, formatted in the old format.
|
||||||
|
func (c *Client4) GetOldClientConfig(etag string) (map[string]string, *Response) {
|
||||||
|
if r, err := c.DoApiGet(c.GetConfigRoute()+"/client?format=old", etag); err != nil {
|
||||||
|
return nil, &Response{StatusCode: r.StatusCode, Error: err}
|
||||||
|
} else {
|
||||||
|
defer closeBody(r)
|
||||||
|
return MapFromJson(r.Body), BuildResponse(r)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetOldClientLicense will retrieve the parts of the server license needed by the
|
||||||
|
// client, formatted in the old format.
|
||||||
|
func (c *Client4) GetOldClientLicense(etag string) (map[string]string, *Response) {
|
||||||
|
if r, err := c.DoApiGet(c.GetLicenseRoute()+"/client?format=old", etag); err != nil {
|
||||||
|
return nil, &Response{StatusCode: r.StatusCode, Error: err}
|
||||||
|
} else {
|
||||||
|
defer closeBody(r)
|
||||||
|
return MapFromJson(r.Body), BuildResponse(r)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// DatabaseRecycle will recycle the connections. Discard current connection and get new one.
|
// DatabaseRecycle will recycle the connections. Discard current connection and get new one.
|
||||||
func (c *Client4) DatabaseRecycle() (bool, *Response) {
|
func (c *Client4) DatabaseRecycle() (bool, *Response) {
|
||||||
if r, err := c.DoApiPost(c.GetDatabaseRoute()+"/recycle", ""); err != nil {
|
if r, err := c.DoApiPost(c.GetDatabaseRoute()+"/recycle", ""); err != nil {
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user