1// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
2// See LICENSE.txt for license information.
3
4package model
5
6import (
7	"net/http"
8	"unicode/utf8"
9)
10
11const (
12	KeyValuePluginIdMaxRunes = 190
13	KeyValueKeyMaxRunes      = 50
14)
15
16type PluginKeyValue struct {
17	PluginId string `json:"plugin_id"`
18	Key      string `json:"key" db:"PKey"`
19	Value    []byte `json:"value" db:"PValue"`
20	ExpireAt int64  `json:"expire_at"`
21}
22
23func (kv *PluginKeyValue) IsValid() *AppError {
24	if kv.PluginId == "" || utf8.RuneCountInString(kv.PluginId) > KeyValuePluginIdMaxRunes {
25		return NewAppError("PluginKeyValue.IsValid", "model.plugin_key_value.is_valid.plugin_id.app_error", map[string]interface{}{"Max": KeyValueKeyMaxRunes, "Min": 0}, "key="+kv.Key, http.StatusBadRequest)
26	}
27
28	if kv.Key == "" || utf8.RuneCountInString(kv.Key) > KeyValueKeyMaxRunes {
29		return NewAppError("PluginKeyValue.IsValid", "model.plugin_key_value.is_valid.key.app_error", map[string]interface{}{"Max": KeyValueKeyMaxRunes, "Min": 0}, "key="+kv.Key, http.StatusBadRequest)
30	}
31
32	return nil
33}
34