-
Notifications
You must be signed in to change notification settings - Fork 6.9k
/
service_environment.go
45 lines (39 loc) · 1.85 KB
/
service_environment.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
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
package model
import (
"os"
"strings"
)
const (
// ServiceEnvironmentProduction represents the production self-managed or cloud
// environments. This can be configured explicitly with MM_SERVICEENVIRONMENT explicitly
// set to "production", but is also the default for any production builds.
ServiceEnvironmentProduction = "production"
// ServiceEnvironmentTest represents testing environments in which MM_SERVICEENVIRONMENT
// is set explicitly to "test".
ServiceEnvironmentTest = "test"
// ServiceEnvironmentDev represents development environments. This can be configured
// explicitly with MM_SERVICEENVIRONMENT set to "dev", but is also the default for any
// non-production builds.
ServiceEnvironmentDev = "dev"
)
// GetServiceEnvironment returns the currently configured external service environment,
// deciding which public key is used to validate enterprise licenses, which telemetry keys are
// active, and which Stripe keys are in use.
//
// To configure an environment other than default, set MM_SERVICEENVIRONMENT before
// starting the application. Production builds default to ServiceEnvironmentProduction, and
// non-production builds default to ServiceEnvironmentDev.
//
// Note that this configuration is explicitly not part of the model.Config data structure, as it
// should never be persisted to the config store nor accidentally configured in any other way than
// the MM_SERVICEENVIRONMENT variable.
func GetServiceEnvironment() string {
externalServiceEnvironment := strings.TrimSpace(strings.ToLower(os.Getenv("MM_SERVICEENVIRONMENT")))
switch externalServiceEnvironment {
case ServiceEnvironmentProduction, ServiceEnvironmentTest, ServiceEnvironmentDev:
return externalServiceEnvironment
}
return getDefaultServiceEnvironment()
}