generated from mattermost/mattermost-plugin-starter-template
/
config.go
112 lines (93 loc) · 3.39 KB
/
config.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
package config
import (
"fmt"
"path"
"github.com/mattermost/mattermost-server/v6/model"
"github.com/mattermost/mattermost-plugin-apps/apps"
appspath "github.com/mattermost/mattermost-plugin-apps/apps/path"
)
// StoredConfig represents the data stored in and managed with the Mattermost
// config.
//
// StoredConfig should be abbreviated as sc.
type StoredConfig struct {
// InstalledApps is a list of all apps installed on the Mattermost instance.
//
// For each installed app, an entry of string(AppID) -> sha1(App) is added,
// and the App struct is stored in KV under app_<sha1(App)>. Implementation
// in `store.App`.
InstalledApps map[string]string `json:"installed_apps,omitempty"`
// LocalManifests is a list of locally-stored manifests. Local is in
// contrast to the "global" list of manifests which in the initial version
// is loaded from S3.
//
// For each installed app, an entry of string(AppID) -> sha1(Manifest) is
// added, and the Manifest struct is stored in KV under
// manifest_<sha1(Manifest)>. Implementation in `store.Manifest`.
LocalManifests map[string]string `json:"local_manifests,omitempty"`
DeveloperModeOverride *bool `json:"developer_mode"`
AllowHTTPAppsOverride *bool `json:"allow_http_apps"`
LogChannelID string `json:"log_channel_id,omitempty"`
LogChannelLevel int `json:"log_channel_level,omitempty"`
LogChannelJSON bool `json:"log_channel_json,omitempty"`
}
var BuildDate string
var BuildHash string
var BuildHashShort string
// Config represents the the metadata handed to all request runners (command,
// http).
//
// Config should be abbreviated as `conf`.
type Config struct {
StoredConfig
PluginManifest model.Manifest
BuildDate string
BuildHash string
BuildHashShort string
MattermostCloudMode bool
DeveloperMode bool
AllowHTTPApps bool
BotUserID string
MattermostSiteURL string
MattermostLocalURL string
PluginURL string
PluginURLPath string
// Maximum size of incoming remote webhook messages
MaxWebhookSize int
AWSRegion string
AWSAccessKey string
AWSSecretKey string
AWSS3Bucket string
}
func (conf Config) AppURL(appID apps.AppID) string {
return conf.PluginURL + path.Join(appspath.Apps, string(appID))
}
// StaticURL returns the URL to a static asset.
func (conf Config) StaticURL(appID apps.AppID, name string) string {
return conf.AppURL(appID) + "/" + path.Join(appspath.StaticFolder, name)
}
func (conf Config) GetPluginVersionInfo() map[string]interface{} {
return map[string]interface{}{
"version": conf.PluginManifest.Version,
}
}
func (conf *Config) InfoTemplateData() map[string]string {
return map[string]string{
"Version": conf.PluginManifest.Version,
"URL": fmt.Sprintf("[%s](https://github.com/mattermost/%s/commit/%s)", conf.BuildHashShort, Repository, conf.BuildHash),
"BuildDate": conf.BuildDate,
"CloudMode": fmt.Sprintf("%t", conf.MattermostCloudMode),
"DeveloperMode": fmt.Sprintf("%t", conf.DeveloperMode),
"AllowHTTPApps": fmt.Sprintf("%t", conf.AllowHTTPApps),
}
}
func (conf Config) Loggable() []interface{} {
return append([]interface{}{},
"version", conf.PluginManifest.Version,
"commit", conf.BuildHashShort,
"build_date", conf.BuildDate,
"cloud_mode", fmt.Sprintf("%t", conf.MattermostCloudMode),
"developer_mode", fmt.Sprintf("%t", conf.DeveloperMode),
"allow_http_apps", fmt.Sprintf("%t", conf.AllowHTTPApps),
)
}