2019-11-29 06:59:40 -05:00
|
|
|
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
|
|
|
// See LICENSE.txt for license information.
|
2017-11-27 17:23:35 -05:00
|
|
|
|
|
|
|
|
package model
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"net/http"
|
2017-11-27 18:49:28 -05:00
|
|
|
"unicode/utf8"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
const (
|
2021-07-12 14:05:36 -04:00
|
|
|
KeyValuePluginIdMaxRunes = 190
|
2021-12-20 07:13:50 -05:00
|
|
|
KeyValueKeyMaxRunes = 150
|
2017-11-27 17:23:35 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type PluginKeyValue struct {
|
|
|
|
|
PluginId string `json:"plugin_id"`
|
|
|
|
|
Key string `json:"key" db:"PKey"`
|
|
|
|
|
Value []byte `json:"value" db:"PValue"`
|
2018-10-10 13:55:12 -04:00
|
|
|
ExpireAt int64 `json:"expire_at"`
|
2017-11-27 17:23:35 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (kv *PluginKeyValue) IsValid() *AppError {
|
2021-07-12 14:05:36 -04:00
|
|
|
if kv.PluginId == "" || utf8.RuneCountInString(kv.PluginId) > KeyValuePluginIdMaxRunes {
|
2022-07-05 02:46:50 -04:00
|
|
|
return NewAppError("PluginKeyValue.IsValid", "model.plugin_key_value.is_valid.plugin_id.app_error", map[string]any{"Max": KeyValueKeyMaxRunes, "Min": 0}, "key="+kv.Key, http.StatusBadRequest)
|
2017-11-27 17:23:35 -05:00
|
|
|
}
|
|
|
|
|
|
2021-07-12 14:05:36 -04:00
|
|
|
if kv.Key == "" || utf8.RuneCountInString(kv.Key) > KeyValueKeyMaxRunes {
|
2022-07-05 02:46:50 -04:00
|
|
|
return NewAppError("PluginKeyValue.IsValid", "model.plugin_key_value.is_valid.key.app_error", map[string]any{"Max": KeyValueKeyMaxRunes, "Min": 0}, "key="+kv.Key, http.StatusBadRequest)
|
2017-11-27 17:23:35 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
}
|