From 785a410936daff5db7fba07dc5735bd74dd158bb Mon Sep 17 00:00:00 2001 From: Joram Wilander Date: Mon, 27 Nov 2017 18:49:28 -0500 Subject: Decrease plugin key value store table index name size (#7910) --- i18n/en.json | 4 ++-- model/plugin_key_value.go | 14 ++++++++++---- store/sqlstore/plugin_store.go | 2 ++ 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/i18n/en.json b/i18n/en.json index 4caa952b3..f252ebe08 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -4248,11 +4248,11 @@ }, { "id": "model.plugin_key_value.is_valid.plugin_id.app_error", - "translation": "Invalid plugin ID" + "translation": "Invalid plugin ID, must be more than {{.Min}} and a of maximum {{.Max}} characters long." }, { "id": "model.plugin_key_value.is_valid.key.app_error", - "translation": "Invalid key" + "translation": "Invalid key, must be more than {{.Min}} and a of maximum {{.Max}} characters long." }, { "id": "model.access.is_valid.access_token.app_error", diff --git a/model/plugin_key_value.go b/model/plugin_key_value.go index b25b4c170..ceb216c2a 100644 --- a/model/plugin_key_value.go +++ b/model/plugin_key_value.go @@ -5,6 +5,12 @@ package model import ( "net/http" + "unicode/utf8" +) + +const ( + KEY_VALUE_PLUGIN_ID_MAX_RUNES = 100 + KEY_VALUE_KEY_MAX_RUNES = 100 ) type PluginKeyValue struct { @@ -14,12 +20,12 @@ type PluginKeyValue struct { } func (kv *PluginKeyValue) IsValid() *AppError { - if len(kv.PluginId) == 0 { - return NewAppError("PluginKeyValue.IsValid", "model.plugin_key_value.is_valid.plugin_id.app_error", nil, "key="+kv.Key, http.StatusBadRequest) + if len(kv.PluginId) == 0 || utf8.RuneCountInString(kv.PluginId) > KEY_VALUE_PLUGIN_ID_MAX_RUNES { + return NewAppError("PluginKeyValue.IsValid", "model.plugin_key_value.is_valid.plugin_id.app_error", map[string]interface{}{"Max": KEY_VALUE_KEY_MAX_RUNES, "Min": 0}, "key="+kv.Key, http.StatusBadRequest) } - if len(kv.Key) == 0 { - return NewAppError("PluginKeyValue.IsValid", "model.plugin_key_value.is_valid.key.app_error", nil, "key="+kv.Key, http.StatusBadRequest) + if len(kv.Key) == 0 || utf8.RuneCountInString(kv.Key) > KEY_VALUE_KEY_MAX_RUNES { + return NewAppError("PluginKeyValue.IsValid", "model.plugin_key_value.is_valid.key.app_error", map[string]interface{}{"Max": KEY_VALUE_KEY_MAX_RUNES, "Min": 0}, "key="+kv.Key, http.StatusBadRequest) } return nil diff --git a/store/sqlstore/plugin_store.go b/store/sqlstore/plugin_store.go index c7c075d8a..a4b49cb27 100644 --- a/store/sqlstore/plugin_store.go +++ b/store/sqlstore/plugin_store.go @@ -21,6 +21,8 @@ func NewSqlPluginStore(sqlStore SqlStore) store.PluginStore { for _, db := range sqlStore.GetAllConns() { table := db.AddTableWithName(model.PluginKeyValue{}, "PluginKeyValueStore").SetKeys(false, "PluginId", "Key") + table.ColMap("PluginId").SetMaxSize(100) + table.ColMap("Key").SetMaxSize(100) table.ColMap("Value").SetMaxSize(8192) } -- cgit v1.2.3-1-g7c22