[MM-59503] export: enable exporting configuration with mmctl (#28412)
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
ca72cdb445
Коммит
424ce2b8db
@@ -8,6 +8,7 @@ import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"reflect"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/mattermost/mattermost/server/public/model"
|
||||
@@ -66,19 +67,31 @@ func getConfig(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
filterMasked, _ := strconv.ParseBool(r.URL.Query().Get("remove_masked"))
|
||||
filterDefaults, _ := strconv.ParseBool(r.URL.Query().Get("remove_defaults"))
|
||||
auditRec.Success()
|
||||
|
||||
w.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate")
|
||||
|
||||
filterOpts := model.ConfigFilterOptions{
|
||||
GetConfigOptions: model.GetConfigOptions{
|
||||
RemoveDefaults: filterDefaults,
|
||||
RemoveMasked: filterMasked,
|
||||
},
|
||||
}
|
||||
if c.App.Channels().License().IsCloud() {
|
||||
js, jsonErr := cfg.ToJSONFiltered(model.ConfigAccessTagType, model.ConfigAccessTagCloudRestrictable)
|
||||
if jsonErr != nil {
|
||||
c.Err = model.NewAppError("getConfig", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(jsonErr)
|
||||
return
|
||||
}
|
||||
w.Write(js)
|
||||
filterOpts.TagFilters = append(filterOpts.TagFilters, model.FilterTag{
|
||||
TagType: model.ConfigAccessTagType,
|
||||
TagName: model.ConfigAccessTagCloudRestrictable,
|
||||
})
|
||||
}
|
||||
m, err := model.FilterConfig(cfg, filterOpts)
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("getConfig", "api.filter_config_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
return
|
||||
}
|
||||
if err := json.NewEncoder(w).Encode(cfg); err != nil {
|
||||
|
||||
if err := json.NewEncoder(w).Encode(m); err != nil {
|
||||
c.Logger.Warn("Error while writing response", mlog.Err(err))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"reflect"
|
||||
"strconv"
|
||||
|
||||
"github.com/mattermost/mattermost/server/public/model"
|
||||
"github.com/mattermost/mattermost/server/public/shared/mlog"
|
||||
@@ -27,10 +28,24 @@ func (api *API) InitConfigLocal() {
|
||||
func localGetConfig(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
auditRec := c.MakeAuditRecord("localGetConfig", audit.Fail)
|
||||
defer c.LogAuditRec(auditRec)
|
||||
cfg := c.App.GetSanitizedConfig()
|
||||
filterMasked, _ := strconv.ParseBool(r.URL.Query().Get("remove_masked"))
|
||||
filterDefaults, _ := strconv.ParseBool(r.URL.Query().Get("remove_defaults"))
|
||||
|
||||
filterOpts := model.ConfigFilterOptions{
|
||||
GetConfigOptions: model.GetConfigOptions{
|
||||
RemoveDefaults: filterDefaults,
|
||||
RemoveMasked: filterMasked,
|
||||
},
|
||||
}
|
||||
|
||||
m, err := model.FilterConfig(c.App.Config(), filterOpts)
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("getConfig", "api.filter_config_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
return
|
||||
}
|
||||
auditRec.Success()
|
||||
w.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate")
|
||||
if err := json.NewEncoder(w).Encode(cfg); err != nil {
|
||||
if err := json.NewEncoder(w).Encode(m); err != nil {
|
||||
c.Logger.Warn("Error while writing response", mlog.Err(err))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,8 +30,8 @@ func TestGetConfig(t *testing.T) {
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
|
||||
th.TestForSystemAdminAndLocal(t, func(t *testing.T, client *model.Client4) {
|
||||
cfg, _, err := client.GetConfig(context.Background())
|
||||
t.Run("Get config for system admin client", func(t *testing.T) {
|
||||
cfg, _, err := th.SystemAdminClient.GetConfig(context.Background())
|
||||
require.NoError(t, err)
|
||||
|
||||
require.NotEqual(t, "", cfg.TeamSettings.SiteName)
|
||||
@@ -59,6 +59,14 @@ func TestGetConfig(t *testing.T) {
|
||||
require.FailNow(t, "did not sanitize properly")
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("Get config for local client", func(t *testing.T) {
|
||||
cfg, _, err := th.LocalClient.GetConfig(context.Background())
|
||||
require.NoError(t, err)
|
||||
|
||||
require.NotEqual(t, model.FakeSetting, *cfg.SqlSettings.DataSource)
|
||||
require.NotEqual(t, model.FakeSetting, *cfg.FileSettings.PublicLinkSalt)
|
||||
})
|
||||
}
|
||||
|
||||
func TestGetConfigWithAccessTag(t *testing.T) {
|
||||
|
||||
Ссылка в новой задаче
Block a user