MM-54275 : Add Giphy production key to LDFlags (#24397)

Этот коммит содержится в:
M-ZubairAhmed
2023-08-31 20:29:04 +05:30
коммит произвёл GitHub
родитель 2c6179a0a6
Коммит 66e5d5fffa
4 изменённых файлов: 33 добавлений и 9 удалений

Просмотреть файл

@@ -213,6 +213,7 @@ include build/*.mk
include public/Makefile
LDFLAGS += -X "github.com/mattermost/mattermost/server/public/model.MockCWS=$(MM_ENABLE_CWS_MOCK)"
LDFLAGS += -X "github.com/mattermost/mattermost/server/public/model.MattermostGiphySdkKey=$(MM_GIPHY_SDK_KEY)"
RUN_IN_BACKGROUND ?=
ifeq ($(RUN_SERVER_IN_BACKGROUND),true)

Просмотреть файл

@@ -81,7 +81,7 @@ func GenerateClientConfig(c *model.Config, telemetryID string, license *model.Li
props["EnableGifPicker"] = strconv.FormatBool(*c.ServiceSettings.EnableGifPicker)
props["GfycatApiKey"] = *c.ServiceSettings.GfycatAPIKey
props["GfycatApiSecret"] = *c.ServiceSettings.GfycatAPISecret
props["GiphySdkKey"] = *c.ServiceSettings.GiphySdkKey
props["GiphySdkKey"] = getGiphySdkKey(c.ServiceSettings)
props["MaxFileSize"] = strconv.FormatInt(*c.FileSettings.MaxFileSize, 10)
props["MaxNotificationsPerChannel"] = strconv.FormatInt(*c.TeamSettings.MaxNotificationsPerChannel, 10)
@@ -378,3 +378,17 @@ func GenerateLimitedClientConfig(c *model.Config, telemetryID string, license *m
return props
}
func getGiphySdkKey(ss model.ServiceSettings) string {
if model.GetServiceEnvironment() == model.ServiceEnvironmentProduction {
if *ss.GiphySdkKey != "" {
return *ss.GiphySdkKey
}
return model.MattermostGiphySdkKey
} else if model.GetServiceEnvironment() == model.ServiceEnvironmentDev || model.GetServiceEnvironment() == model.ServiceEnvironmentTest {
return model.ServiceSettingsDefaultGiphySdkKeyTest
}
return ""
}

Просмотреть файл

@@ -293,6 +293,19 @@ func TestGetClientConfig(t *testing.T) {
"EnableJoinLeaveMessageByDefault": "false",
},
},
{
"test key for GiphySdkKey",
&model.Config{
ServiceSettings: model.ServiceSettings{
GiphySdkKey: model.NewString(""),
},
},
"",
nil,
map[string]string{
"GiphySdkKey": model.ServiceSettingsDefaultGiphySdkKeyTest,
},
},
}
for _, testCase := range testCases {

Просмотреть файл

@@ -111,7 +111,6 @@ const (
ServiceSettingsDefaultListenAndAddress = ":8065"
ServiceSettingsDefaultGfycatAPIKey = "2_KtH_W5"
ServiceSettingsDefaultGfycatAPISecret = "3wLVZPiswc3DnaiaFoLkDvB4X0IV6CpMkj4tf2inJRsBY6-FnkT08zGmppWFgeof"
ServiceSettingsDefaultGiphySdkKey = "yaRojIWaxmKhtSMBaT3uLCAHm0kpMLKw"
ServiceSettingsDefaultGiphySdkKeyTest = "s0glxvzVg9azvPipKxcPLpXV0q1x1fVP"
ServiceSettingsDefaultDeveloperFlags = ""
@@ -400,6 +399,8 @@ type ServiceSettings struct {
AllowSyncedDrafts *bool `access:"site_posts"`
}
var MattermostGiphySdkKey string
func (s *ServiceSettings) SetDefaults(isUpdate bool) {
if s.EnableEmailInvitations == nil {
// If the site URL is also not present then assume this is a clean install
@@ -743,13 +744,8 @@ func (s *ServiceSettings) SetDefaults(isUpdate bool) {
s.GfycatAPISecret = NewString(ServiceSettingsDefaultGfycatAPISecret)
}
if s.GiphySdkKey == nil {
switch GetServiceEnvironment() {
case ServiceEnvironmentProduction:
s.GiphySdkKey = NewString(ServiceSettingsDefaultGiphySdkKey)
case ServiceEnvironmentTest, ServiceEnvironmentDev:
s.GiphySdkKey = NewString(ServiceSettingsDefaultGiphySdkKeyTest)
}
if s.GiphySdkKey == nil || *s.GiphySdkKey == "" {
s.GiphySdkKey = NewString("")
}
if s.ExperimentalEnableAuthenticationTransfer == nil {