generated from mattermost/mattermost-plugin-starter-template
/
debug_store_pollute.go
75 lines (66 loc) · 1.91 KB
/
debug_store_pollute.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// Copyright (c) 2019-present Mattermost, Inc. All Rights Reserved.
// See License for license information.
package builtin
import (
"fmt"
"strconv"
"time"
"github.com/nicksnyder/go-i18n/v2/i18n"
"github.com/mattermost/mattermost-plugin-apps/apps"
"github.com/mattermost/mattermost-plugin-apps/server/incoming"
"github.com/mattermost/mattermost-plugin-apps/server/store"
)
func (a *builtinApp) debugStorePolluteCommandBinding(loc *i18n.Localizer) apps.Binding {
return apps.Binding{
Location: "list",
Label: a.conf.I18N().LocalizeDefaultMessage(loc, &i18n.Message{
ID: "command.debug.store.pollute.label",
Other: "pollute",
}),
Description: a.conf.I18N().LocalizeDefaultMessage(loc, &i18n.Message{
ID: "command.debug.store.pollute.description",
Other: "Add garbage records to the store.",
}),
Form: &apps.Form{
Submit: newUserCall(PathDebugStorePollute),
Fields: []apps.Field{
a.debugCountField(loc),
},
},
}
}
func (a *builtinApp) debugStorePollute(r *incoming.Request, creq apps.CallRequest) apps.CallResponse {
var err error
c := 1000
countStr := creq.GetValue(fCount, "")
if countStr != "" {
c, err = strconv.Atoi(countStr)
if err != nil {
return apps.NewErrorResponse(err)
}
}
keys := []string{}
for i := 0; i < c; i++ {
key := fmt.Sprintf("%s-%v-%d", store.KVDebugPrefix, time.Now().UnixMilli(), i)
_, err = a.conf.MattermostAPI().KV.Set(key, []byte("garbage"))
if err != nil {
return apps.NewErrorResponse(err)
}
keys = append(keys, key)
}
loc := a.newLocalizer(creq)
message := a.conf.I18N().LocalizeWithConfig(loc, &i18n.LocalizeConfig{
DefaultMessage: &i18n.Message{
ID: "command.debug.store.pollute.submit.message",
Other: "Created {{.Count}} garbage keys",
},
TemplateData: map[string]string{
"Count": strconv.Itoa(len(keys)),
},
})
return apps.CallResponse{
Type: apps.CallResponseTypeOK,
Data: keys,
Text: message,
}
}