2018-01-11 15:23:41 -06:00
|
|
|
// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved.
|
|
|
|
|
// See License.txt for license information.
|
|
|
|
|
|
|
|
|
|
package app
|
|
|
|
|
|
|
|
|
|
import (
|
2018-02-07 11:05:46 -06:00
|
|
|
"crypto/ecdsa"
|
|
|
|
|
"crypto/elliptic"
|
2018-01-11 15:23:41 -06:00
|
|
|
"crypto/md5"
|
2018-02-07 11:05:46 -06:00
|
|
|
"crypto/rand"
|
|
|
|
|
"crypto/x509"
|
|
|
|
|
"encoding/base64"
|
2018-01-11 15:23:41 -06:00
|
|
|
"encoding/json"
|
|
|
|
|
"fmt"
|
2018-02-20 12:49:45 -08:00
|
|
|
"net/url"
|
2018-01-11 15:23:41 -06:00
|
|
|
"runtime/debug"
|
2018-03-05 07:18:22 -05:00
|
|
|
"strconv"
|
2018-02-22 18:23:32 -06:00
|
|
|
"strings"
|
2018-08-08 12:04:36 +02:00
|
|
|
"time"
|
2018-01-11 15:23:41 -06:00
|
|
|
|
2018-04-27 12:49:45 -07:00
|
|
|
"github.com/mattermost/mattermost-server/mlog"
|
2018-01-11 15:23:41 -06:00
|
|
|
"github.com/mattermost/mattermost-server/model"
|
|
|
|
|
"github.com/mattermost/mattermost-server/utils"
|
|
|
|
|
)
|
|
|
|
|
|
2018-09-26 20:49:22 +00:00
|
|
|
const (
|
|
|
|
|
ERROR_SERVICE_TERMS_NO_ROWS_FOUND = "store.sql_service_terms_store.get.no_rows.app_error"
|
|
|
|
|
)
|
|
|
|
|
|
2018-01-11 15:23:41 -06:00
|
|
|
func (a *App) Config() *model.Config {
|
2018-01-12 08:02:11 -06:00
|
|
|
if cfg := a.config.Load(); cfg != nil {
|
|
|
|
|
return cfg.(*model.Config)
|
|
|
|
|
}
|
|
|
|
|
return &model.Config{}
|
2018-01-11 15:23:41 -06:00
|
|
|
}
|
|
|
|
|
|
2018-04-09 12:16:11 -04:00
|
|
|
func (a *App) EnvironmentConfig() map[string]interface{} {
|
|
|
|
|
if a.envConfig != nil {
|
|
|
|
|
return a.envConfig
|
|
|
|
|
}
|
|
|
|
|
return map[string]interface{}{}
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-11 15:23:41 -06:00
|
|
|
func (a *App) UpdateConfig(f func(*model.Config)) {
|
2018-01-12 08:02:11 -06:00
|
|
|
old := a.Config()
|
|
|
|
|
updated := old.Clone()
|
|
|
|
|
f(updated)
|
|
|
|
|
a.config.Store(updated)
|
2018-03-05 07:18:22 -05:00
|
|
|
|
2018-01-12 08:02:11 -06:00
|
|
|
a.InvokeConfigListeners(old, updated)
|
2018-01-11 15:23:41 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (a *App) PersistConfig() {
|
|
|
|
|
utils.SaveConfig(a.ConfigFileName(), a.Config())
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-12 08:02:11 -06:00
|
|
|
func (a *App) LoadConfig(configFile string) *model.AppError {
|
|
|
|
|
old := a.Config()
|
|
|
|
|
|
2018-04-09 12:16:11 -04:00
|
|
|
cfg, configPath, envConfig, err := utils.LoadConfig(configFile)
|
2018-01-12 08:02:11 -06:00
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
a.configFile = configPath
|
|
|
|
|
|
|
|
|
|
a.config.Store(cfg)
|
2018-04-09 12:16:11 -04:00
|
|
|
a.envConfig = envConfig
|
2018-01-12 08:02:11 -06:00
|
|
|
|
2018-02-22 18:23:32 -06:00
|
|
|
a.siteURL = strings.TrimRight(*cfg.ServiceSettings.SiteURL, "/")
|
2018-01-12 08:02:11 -06:00
|
|
|
|
|
|
|
|
a.InvokeConfigListeners(old, cfg)
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (a *App) ReloadConfig() *model.AppError {
|
2018-01-11 15:23:41 -06:00
|
|
|
debug.FreeOSMemory()
|
2018-01-12 08:02:11 -06:00
|
|
|
if err := a.LoadConfig(a.configFile); err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
2018-01-11 15:23:41 -06:00
|
|
|
|
|
|
|
|
// start/restart email batching job if necessary
|
|
|
|
|
a.InitEmailBatching()
|
2018-01-12 08:02:11 -06:00
|
|
|
return nil
|
2018-01-11 15:23:41 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (a *App) ConfigFileName() string {
|
2018-01-12 08:02:11 -06:00
|
|
|
return a.configFile
|
2018-01-11 15:23:41 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (a *App) ClientConfig() map[string]string {
|
|
|
|
|
return a.clientConfig
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (a *App) ClientConfigHash() string {
|
|
|
|
|
return a.clientConfigHash
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-18 12:39:22 -04:00
|
|
|
func (a *App) LimitedClientConfig() map[string]string {
|
|
|
|
|
return a.limitedClientConfig
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-11 15:23:41 -06:00
|
|
|
func (a *App) EnableConfigWatch() {
|
|
|
|
|
if a.configWatcher == nil && !a.disableConfigWatch {
|
2018-01-12 08:02:11 -06:00
|
|
|
configWatcher, err := utils.NewConfigWatcher(a.ConfigFileName(), func() {
|
|
|
|
|
a.ReloadConfig()
|
|
|
|
|
})
|
2018-01-11 15:23:41 -06:00
|
|
|
if err != nil {
|
2018-04-27 12:49:45 -07:00
|
|
|
mlog.Error(fmt.Sprint(err))
|
2018-01-11 15:23:41 -06:00
|
|
|
}
|
|
|
|
|
a.configWatcher = configWatcher
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (a *App) DisableConfigWatch() {
|
|
|
|
|
if a.configWatcher != nil {
|
|
|
|
|
a.configWatcher.Close()
|
|
|
|
|
a.configWatcher = nil
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-12 08:02:11 -06:00
|
|
|
// Registers a function with a given to be called when the config is reloaded and may have changed. The function
|
|
|
|
|
// will be called with two arguments: the old config and the new config. AddConfigListener returns a unique ID
|
|
|
|
|
// for the listener that can later be used to remove it.
|
|
|
|
|
func (a *App) AddConfigListener(listener func(*model.Config, *model.Config)) string {
|
|
|
|
|
id := model.NewId()
|
|
|
|
|
a.configListeners[id] = listener
|
|
|
|
|
return id
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Removes a listener function by the unique ID returned when AddConfigListener was called
|
|
|
|
|
func (a *App) RemoveConfigListener(id string) {
|
|
|
|
|
delete(a.configListeners, id)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (a *App) InvokeConfigListeners(old, current *model.Config) {
|
|
|
|
|
for _, listener := range a.configListeners {
|
|
|
|
|
listener(old, current)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-07 11:05:46 -06:00
|
|
|
// EnsureAsymmetricSigningKey ensures that an asymmetric signing key exists and future calls to
|
|
|
|
|
// AsymmetricSigningKey will always return a valid signing key.
|
|
|
|
|
func (a *App) ensureAsymmetricSigningKey() error {
|
|
|
|
|
if a.asymmetricSigningKey != nil {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var key *model.SystemAsymmetricSigningKey
|
|
|
|
|
|
|
|
|
|
result := <-a.Srv.Store.System().GetByName(model.SYSTEM_ASYMMETRIC_SIGNING_KEY)
|
|
|
|
|
if result.Err == nil {
|
|
|
|
|
if err := json.Unmarshal([]byte(result.Data.(*model.System).Value), &key); err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// If we don't already have a key, try to generate one.
|
|
|
|
|
if key == nil {
|
|
|
|
|
newECDSAKey, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
newKey := &model.SystemAsymmetricSigningKey{
|
|
|
|
|
ECDSAKey: &model.SystemECDSAKey{
|
|
|
|
|
Curve: "P-256",
|
|
|
|
|
X: newECDSAKey.X,
|
|
|
|
|
Y: newECDSAKey.Y,
|
|
|
|
|
D: newECDSAKey.D,
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
system := &model.System{
|
|
|
|
|
Name: model.SYSTEM_ASYMMETRIC_SIGNING_KEY,
|
|
|
|
|
}
|
|
|
|
|
v, err := json.Marshal(newKey)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
system.Value = string(v)
|
|
|
|
|
if result = <-a.Srv.Store.System().Save(system); result.Err == nil {
|
|
|
|
|
// If we were able to save the key, use it, otherwise ignore the error.
|
|
|
|
|
key = newKey
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// If we weren't able to save a new key above, another server must have beat us to it. Get the
|
|
|
|
|
// key from the database, and if that fails, error out.
|
|
|
|
|
if key == nil {
|
|
|
|
|
result := <-a.Srv.Store.System().GetByName(model.SYSTEM_ASYMMETRIC_SIGNING_KEY)
|
|
|
|
|
if result.Err != nil {
|
|
|
|
|
return result.Err
|
2018-09-24 13:27:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if err := json.Unmarshal([]byte(result.Data.(*model.System).Value), &key); err != nil {
|
2018-02-07 11:05:46 -06:00
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var curve elliptic.Curve
|
|
|
|
|
switch key.ECDSAKey.Curve {
|
|
|
|
|
case "P-256":
|
|
|
|
|
curve = elliptic.P256()
|
|
|
|
|
default:
|
|
|
|
|
return fmt.Errorf("unknown curve: " + key.ECDSAKey.Curve)
|
|
|
|
|
}
|
|
|
|
|
a.asymmetricSigningKey = &ecdsa.PrivateKey{
|
|
|
|
|
PublicKey: ecdsa.PublicKey{
|
|
|
|
|
Curve: curve,
|
|
|
|
|
X: key.ECDSAKey.X,
|
|
|
|
|
Y: key.ECDSAKey.Y,
|
|
|
|
|
},
|
|
|
|
|
D: key.ECDSAKey.D,
|
|
|
|
|
}
|
|
|
|
|
a.regenerateClientConfig()
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-08 12:04:36 +02:00
|
|
|
func (a *App) ensureInstallationDate() error {
|
|
|
|
|
_, err := a.getSystemInstallDate()
|
|
|
|
|
if err == nil {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
result := <-a.Srv.Store.User().InferSystemInstallDate()
|
|
|
|
|
var installationDate int64
|
|
|
|
|
if result.Err == nil && result.Data.(int64) > 0 {
|
|
|
|
|
installationDate = result.Data.(int64)
|
|
|
|
|
} else {
|
|
|
|
|
installationDate = utils.MillisFromTime(time.Now())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
result = <-a.Srv.Store.System().SaveOrUpdate(&model.System{
|
|
|
|
|
Name: model.SYSTEM_INSTALLATION_DATE_KEY,
|
|
|
|
|
Value: strconv.FormatInt(installationDate, 10),
|
|
|
|
|
})
|
|
|
|
|
if result.Err != nil {
|
|
|
|
|
return result.Err
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-07 11:05:46 -06:00
|
|
|
// AsymmetricSigningKey will return a private key that can be used for asymmetric signing.
|
|
|
|
|
func (a *App) AsymmetricSigningKey() *ecdsa.PrivateKey {
|
|
|
|
|
return a.asymmetricSigningKey
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-11 15:23:41 -06:00
|
|
|
func (a *App) regenerateClientConfig() {
|
2018-02-09 10:04:48 -06:00
|
|
|
a.clientConfig = utils.GenerateClientConfig(a.Config(), a.DiagnosticId(), a.License())
|
2018-09-26 20:49:22 +00:00
|
|
|
|
|
|
|
|
if a.clientConfig["EnableCustomServiceTerms"] == "true" {
|
|
|
|
|
serviceTerms, err := a.GetLatestServiceTerms()
|
|
|
|
|
if err != nil {
|
|
|
|
|
mlog.Err(err)
|
|
|
|
|
} else {
|
|
|
|
|
a.clientConfig["CustomServiceTermsId"] = serviceTerms.Id
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-18 12:39:22 -04:00
|
|
|
a.limitedClientConfig = utils.GenerateLimitedClientConfig(a.Config(), a.DiagnosticId(), a.License())
|
|
|
|
|
|
2018-02-07 11:05:46 -06:00
|
|
|
if key := a.AsymmetricSigningKey(); key != nil {
|
|
|
|
|
der, _ := x509.MarshalPKIXPublicKey(&key.PublicKey)
|
|
|
|
|
a.clientConfig["AsymmetricSigningPublicKey"] = base64.StdEncoding.EncodeToString(der)
|
2018-06-18 12:39:22 -04:00
|
|
|
a.limitedClientConfig["AsymmetricSigningPublicKey"] = base64.StdEncoding.EncodeToString(der)
|
2018-02-07 11:05:46 -06:00
|
|
|
}
|
2018-06-18 12:39:22 -04:00
|
|
|
|
2018-01-11 15:23:41 -06:00
|
|
|
clientConfigJSON, _ := json.Marshal(a.clientConfig)
|
|
|
|
|
a.clientConfigHash = fmt.Sprintf("%x", md5.Sum(clientConfigJSON))
|
|
|
|
|
}
|
2018-01-12 08:02:11 -06:00
|
|
|
|
|
|
|
|
func (a *App) Desanitize(cfg *model.Config) {
|
|
|
|
|
actual := a.Config()
|
|
|
|
|
|
|
|
|
|
if cfg.LdapSettings.BindPassword != nil && *cfg.LdapSettings.BindPassword == model.FAKE_SETTING {
|
|
|
|
|
*cfg.LdapSettings.BindPassword = *actual.LdapSettings.BindPassword
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if *cfg.FileSettings.PublicLinkSalt == model.FAKE_SETTING {
|
|
|
|
|
*cfg.FileSettings.PublicLinkSalt = *actual.FileSettings.PublicLinkSalt
|
|
|
|
|
}
|
|
|
|
|
if cfg.FileSettings.AmazonS3SecretAccessKey == model.FAKE_SETTING {
|
|
|
|
|
cfg.FileSettings.AmazonS3SecretAccessKey = actual.FileSettings.AmazonS3SecretAccessKey
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if cfg.EmailSettings.InviteSalt == model.FAKE_SETTING {
|
|
|
|
|
cfg.EmailSettings.InviteSalt = actual.EmailSettings.InviteSalt
|
|
|
|
|
}
|
|
|
|
|
if cfg.EmailSettings.SMTPPassword == model.FAKE_SETTING {
|
|
|
|
|
cfg.EmailSettings.SMTPPassword = actual.EmailSettings.SMTPPassword
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if cfg.GitLabSettings.Secret == model.FAKE_SETTING {
|
|
|
|
|
cfg.GitLabSettings.Secret = actual.GitLabSettings.Secret
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if *cfg.SqlSettings.DataSource == model.FAKE_SETTING {
|
|
|
|
|
*cfg.SqlSettings.DataSource = *actual.SqlSettings.DataSource
|
|
|
|
|
}
|
|
|
|
|
if cfg.SqlSettings.AtRestEncryptKey == model.FAKE_SETTING {
|
|
|
|
|
cfg.SqlSettings.AtRestEncryptKey = actual.SqlSettings.AtRestEncryptKey
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if *cfg.ElasticsearchSettings.Password == model.FAKE_SETTING {
|
|
|
|
|
*cfg.ElasticsearchSettings.Password = *actual.ElasticsearchSettings.Password
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for i := range cfg.SqlSettings.DataSourceReplicas {
|
|
|
|
|
cfg.SqlSettings.DataSourceReplicas[i] = actual.SqlSettings.DataSourceReplicas[i]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for i := range cfg.SqlSettings.DataSourceSearchReplicas {
|
|
|
|
|
cfg.SqlSettings.DataSourceSearchReplicas[i] = actual.SqlSettings.DataSourceSearchReplicas[i]
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-02-20 12:49:45 -08:00
|
|
|
|
|
|
|
|
func (a *App) GetCookieDomain() string {
|
|
|
|
|
if *a.Config().ServiceSettings.AllowCookiesForSubdomains {
|
|
|
|
|
if siteURL, err := url.Parse(*a.Config().ServiceSettings.SiteURL); err == nil {
|
|
|
|
|
return siteURL.Hostname()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return ""
|
|
|
|
|
}
|
2018-02-22 18:23:32 -06:00
|
|
|
|
|
|
|
|
func (a *App) GetSiteURL() string {
|
|
|
|
|
return a.siteURL
|
|
|
|
|
}
|
2018-03-05 07:18:22 -05:00
|
|
|
|
Relax 4k post message limit (#8478)
* MM-9661: rename POST_MESSAGE_MAX_RUNES to \0_v1
* MM-9661: s/4000/POST_MESSAGE_MAX_RUNES_V1/ in tests
* MM-9661: introduce POST_MESSAGE_MAX_RUNES_V2
* MM-9661: migrate Postgres Posts.Message column to TEXT from VARCHAR(4000)
This is safe to do in a production instance since the underyling type is
not changing. We explicitly don't do this automatically for MySQL, but
also don't need to since the ORM would have already created a TEXT column
for MySQL in that case.
* MM-9661: emit MaxPostSize in client config
This value remains unconfigurable at this time, but exposes the current
limit to the client. The limit remains at 4k in this commit.
* MM-9661: introduce and use SqlPostStore.GetMaxPostSize
Enforce a byte limitation in the database, and use 1/4 of that value as
the rune count limitation (assuming a worst case UTF-8 representation).
* move maxPostSizeCached, lastPostsCache and lastPostTimeCache out of the global context and onto the SqlPostStore
* address feedback from code review:
* ensure sqlstore unit tests are actually being run
* move global caches into SqlPostStore
* leverage sync.Once to address a race condition
* modify upgrade semantics to match new db semantics
gorp's behaviour on creating columns with a maximum length on Postgres
differs from MySQL:
* Postgres
* gorp uses TEXT for string columns without a maximum length
* gorp uses VARCHAR(N) for string columns with a maximum length of N
* MySQL
* gorp uses TEXT for string columns with a maximum length >= 256
* gorp uses VARCHAR(N) for string columns with a maximum length of N
* gorp defaults to a maximum length of 255, implying VARCHAR(255)
So the Message column has been TEXT on MySQL but VARCHAR(4000) on
Postgres. With the new, longer limits of 65535, and without changes to
gorp, the expected behaviour is TEXT on MySQL and VARCHAR(65535) on
Postgres. This commit makes the upgrade semantics match the new database
semantics.
Ideally, we'd revisit the gorp behaviour at a later time.
* allow TestMaxPostSize test cases to actually run in parallel
* default maxPostSizeCached to POST_MESSAGE_MAX_RUNES_V1 in case the once initializer panics
* fix casting error
* MM-9661: skip the schema migration for Postgres
It turns out resizing VARCHAR requires a rewrite in some versions of
Postgres, but migrating VARCHAR to TEXT does not. Given the increasing
complexity, let's defer the migration to the enduser instead.
2018-03-26 17:55:35 -04:00
|
|
|
// ClientConfigWithComputed gets the configuration in a format suitable for sending to the client.
|
|
|
|
|
func (a *App) ClientConfigWithComputed() map[string]string {
|
2018-03-05 07:18:22 -05:00
|
|
|
respCfg := map[string]string{}
|
|
|
|
|
for k, v := range a.ClientConfig() {
|
|
|
|
|
respCfg[k] = v
|
|
|
|
|
}
|
|
|
|
|
|
Relax 4k post message limit (#8478)
* MM-9661: rename POST_MESSAGE_MAX_RUNES to \0_v1
* MM-9661: s/4000/POST_MESSAGE_MAX_RUNES_V1/ in tests
* MM-9661: introduce POST_MESSAGE_MAX_RUNES_V2
* MM-9661: migrate Postgres Posts.Message column to TEXT from VARCHAR(4000)
This is safe to do in a production instance since the underyling type is
not changing. We explicitly don't do this automatically for MySQL, but
also don't need to since the ORM would have already created a TEXT column
for MySQL in that case.
* MM-9661: emit MaxPostSize in client config
This value remains unconfigurable at this time, but exposes the current
limit to the client. The limit remains at 4k in this commit.
* MM-9661: introduce and use SqlPostStore.GetMaxPostSize
Enforce a byte limitation in the database, and use 1/4 of that value as
the rune count limitation (assuming a worst case UTF-8 representation).
* move maxPostSizeCached, lastPostsCache and lastPostTimeCache out of the global context and onto the SqlPostStore
* address feedback from code review:
* ensure sqlstore unit tests are actually being run
* move global caches into SqlPostStore
* leverage sync.Once to address a race condition
* modify upgrade semantics to match new db semantics
gorp's behaviour on creating columns with a maximum length on Postgres
differs from MySQL:
* Postgres
* gorp uses TEXT for string columns without a maximum length
* gorp uses VARCHAR(N) for string columns with a maximum length of N
* MySQL
* gorp uses TEXT for string columns with a maximum length >= 256
* gorp uses VARCHAR(N) for string columns with a maximum length of N
* gorp defaults to a maximum length of 255, implying VARCHAR(255)
So the Message column has been TEXT on MySQL but VARCHAR(4000) on
Postgres. With the new, longer limits of 65535, and without changes to
gorp, the expected behaviour is TEXT on MySQL and VARCHAR(65535) on
Postgres. This commit makes the upgrade semantics match the new database
semantics.
Ideally, we'd revisit the gorp behaviour at a later time.
* allow TestMaxPostSize test cases to actually run in parallel
* default maxPostSizeCached to POST_MESSAGE_MAX_RUNES_V1 in case the once initializer panics
* fix casting error
* MM-9661: skip the schema migration for Postgres
It turns out resizing VARCHAR requires a rewrite in some versions of
Postgres, but migrating VARCHAR to TEXT does not. Given the increasing
complexity, let's defer the migration to the enduser instead.
2018-03-26 17:55:35 -04:00
|
|
|
// These properties are not configurable, but nevertheless represent configuration expected
|
|
|
|
|
// by the client.
|
2018-03-05 07:18:22 -05:00
|
|
|
respCfg["NoAccounts"] = strconv.FormatBool(a.IsFirstUserAccount())
|
Relax 4k post message limit (#8478)
* MM-9661: rename POST_MESSAGE_MAX_RUNES to \0_v1
* MM-9661: s/4000/POST_MESSAGE_MAX_RUNES_V1/ in tests
* MM-9661: introduce POST_MESSAGE_MAX_RUNES_V2
* MM-9661: migrate Postgres Posts.Message column to TEXT from VARCHAR(4000)
This is safe to do in a production instance since the underyling type is
not changing. We explicitly don't do this automatically for MySQL, but
also don't need to since the ORM would have already created a TEXT column
for MySQL in that case.
* MM-9661: emit MaxPostSize in client config
This value remains unconfigurable at this time, but exposes the current
limit to the client. The limit remains at 4k in this commit.
* MM-9661: introduce and use SqlPostStore.GetMaxPostSize
Enforce a byte limitation in the database, and use 1/4 of that value as
the rune count limitation (assuming a worst case UTF-8 representation).
* move maxPostSizeCached, lastPostsCache and lastPostTimeCache out of the global context and onto the SqlPostStore
* address feedback from code review:
* ensure sqlstore unit tests are actually being run
* move global caches into SqlPostStore
* leverage sync.Once to address a race condition
* modify upgrade semantics to match new db semantics
gorp's behaviour on creating columns with a maximum length on Postgres
differs from MySQL:
* Postgres
* gorp uses TEXT for string columns without a maximum length
* gorp uses VARCHAR(N) for string columns with a maximum length of N
* MySQL
* gorp uses TEXT for string columns with a maximum length >= 256
* gorp uses VARCHAR(N) for string columns with a maximum length of N
* gorp defaults to a maximum length of 255, implying VARCHAR(255)
So the Message column has been TEXT on MySQL but VARCHAR(4000) on
Postgres. With the new, longer limits of 65535, and without changes to
gorp, the expected behaviour is TEXT on MySQL and VARCHAR(65535) on
Postgres. This commit makes the upgrade semantics match the new database
semantics.
Ideally, we'd revisit the gorp behaviour at a later time.
* allow TestMaxPostSize test cases to actually run in parallel
* default maxPostSizeCached to POST_MESSAGE_MAX_RUNES_V1 in case the once initializer panics
* fix casting error
* MM-9661: skip the schema migration for Postgres
It turns out resizing VARCHAR requires a rewrite in some versions of
Postgres, but migrating VARCHAR to TEXT does not. Given the increasing
complexity, let's defer the migration to the enduser instead.
2018-03-26 17:55:35 -04:00
|
|
|
respCfg["MaxPostSize"] = strconv.Itoa(a.MaxPostSize())
|
2018-08-08 12:04:36 +02:00
|
|
|
respCfg["InstallationDate"] = ""
|
|
|
|
|
if installationDate, err := a.getSystemInstallDate(); err == nil {
|
|
|
|
|
respCfg["InstallationDate"] = strconv.FormatInt(installationDate, 10)
|
|
|
|
|
}
|
2018-03-05 07:18:22 -05:00
|
|
|
|
|
|
|
|
return respCfg
|
|
|
|
|
}
|
2018-06-18 12:39:22 -04:00
|
|
|
|
|
|
|
|
// LimitedClientConfigWithComputed gets the configuration in a format suitable for sending to the client.
|
|
|
|
|
func (a *App) LimitedClientConfigWithComputed() map[string]string {
|
|
|
|
|
respCfg := map[string]string{}
|
|
|
|
|
for k, v := range a.LimitedClientConfig() {
|
|
|
|
|
respCfg[k] = v
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// These properties are not configurable, but nevertheless represent configuration expected
|
|
|
|
|
// by the client.
|
|
|
|
|
respCfg["NoAccounts"] = strconv.FormatBool(a.IsFirstUserAccount())
|
|
|
|
|
|
|
|
|
|
return respCfg
|
|
|
|
|
}
|