2022-11-13 19:17:07 +01:00
|
|
|
package server
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/rs/zerolog/log"
|
|
|
|
"os"
|
2022-11-18 21:25:40 +01:00
|
|
|
"time"
|
2022-11-13 19:17:07 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
type Config struct {
|
2022-11-20 17:19:11 +01:00
|
|
|
Namespace string
|
|
|
|
GinDebug bool
|
|
|
|
ServerIP string
|
|
|
|
ServerPort string
|
|
|
|
DBFile string
|
|
|
|
RequestTimeout time.Duration
|
|
|
|
ReturnRawErrors bool
|
|
|
|
FirebaseProjectID string
|
|
|
|
FirebaseTokenURI string
|
|
|
|
FirebasePrivKeyID string
|
|
|
|
FirebaseClientMail string
|
|
|
|
FirebasePrivateKey string
|
2022-11-13 19:17:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
var Conf Config
|
|
|
|
|
2022-11-20 03:41:38 +01:00
|
|
|
var configLocHost = Config{
|
2022-11-20 17:19:11 +01:00
|
|
|
Namespace: "local-host",
|
|
|
|
GinDebug: true,
|
|
|
|
ServerIP: "0.0.0.0",
|
|
|
|
ServerPort: "8080",
|
|
|
|
DBFile: ".run-data/db.sqlite3",
|
|
|
|
RequestTimeout: 16 * time.Second,
|
|
|
|
ReturnRawErrors: true,
|
|
|
|
FirebaseProjectID: "simplecloudnotifier-ea7ef",
|
|
|
|
FirebaseTokenURI: "https://oauth2.googleapis.com/token",
|
|
|
|
FirebasePrivKeyID: "5bfab19fca25034e87c5b3bd1a4334499d2d1f85",
|
|
|
|
FirebaseClientMail: "firebase-adminsdk-42grv@simplecloudnotifier-ea7ef.iam.gserviceaccount.com",
|
|
|
|
FirebasePrivateKey: "-----BEGIN PRIVATE KEY-----\nMIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQD2NWOQDcalRdkp\nHtQHABLlu3GMBQBJrGiCxzOZhi/lLwrw2MJEmg1VFz6TVkX2z3SCzXCPOgGriM70\nuWCNLyZQvU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51jF8ndzBS1pkuwVEfY94dsvZ\nYM1vednJKXT7On696h5C6DBzKPAqUf3Yh88mqvMLDHkQnE6daLv7vykxAoGAOPmA\ndDx1NO48E1+OIwgRyqv9PUZmDB3Qit5L4biN6lvgJqlJOV+PeRokZ2wOKLLZVkeF\nh2BTrhFgXDJfESEz6rT0eljsTHVIUK/E8On5Ttd5z1SrYUII3NfpAhP9mWaVr6tC\nxX1hMYWAr+Ho9PM23iFoL5U+IdqSLvqdkPVYfPcCgYB1ANKNYPIJNx/wLxYWNS0r\nI98HwKfv2TxxE/l+2459NMMHY5wlpFl7MNoeK2SdY+ghWPlxC6u5Nxpnk+bZ8TJe\np7U2nY0SQDLCmPgGWs3KBb/zR49X2b7JS3CXXqQSrLxBe2phZg6kE5nB6NPUDc/i\n6WG8tG20rCfgwlXeXl0+Ow==\n-----END PRIVATE KEY-----\n",
|
2022-11-13 19:17:07 +01:00
|
|
|
}
|
|
|
|
|
2022-11-20 03:41:38 +01:00
|
|
|
var configLocDocker = Config{
|
2022-11-20 17:19:11 +01:00
|
|
|
Namespace: "local-docker",
|
|
|
|
GinDebug: true,
|
|
|
|
ServerIP: "0.0.0.0",
|
|
|
|
ServerPort: "80",
|
|
|
|
DBFile: "/data/scn_docker.sqlite3",
|
|
|
|
RequestTimeout: 16 * time.Second,
|
|
|
|
ReturnRawErrors: true,
|
|
|
|
FirebaseProjectID: "simplecloudnotifier-ea7ef",
|
|
|
|
FirebaseTokenURI: "https://oauth2.googleapis.com/token",
|
|
|
|
FirebasePrivKeyID: "5bfab19fca25034e87c5b3bd1a4334499d2d1f85",
|
|
|
|
FirebaseClientMail: "firebase-adminsdk-42grv@simplecloudnotifier-ea7ef.iam.gserviceaccount.com",
|
|
|
|
FirebasePrivateKey: "TODO",
|
2022-11-20 03:41:38 +01:00
|
|
|
}
|
|
|
|
|
2022-11-13 19:17:07 +01:00
|
|
|
var configDev = Config{
|
2022-11-20 17:19:11 +01:00
|
|
|
Namespace: "develop",
|
|
|
|
GinDebug: true,
|
|
|
|
ServerIP: "0.0.0.0",
|
|
|
|
ServerPort: "80",
|
|
|
|
DBFile: "/data/scn.sqlite3",
|
|
|
|
RequestTimeout: 16 * time.Second,
|
|
|
|
ReturnRawErrors: true,
|
|
|
|
FirebaseProjectID: "simplecloudnotifier-ea7ef",
|
|
|
|
FirebaseTokenURI: "https://oauth2.googleapis.com/token",
|
|
|
|
FirebasePrivKeyID: "5bfab19fca25034e87c5b3bd1a4334499d2d1f85",
|
|
|
|
FirebaseClientMail: "firebase-adminsdk-42grv@simplecloudnotifier-ea7ef.iam.gserviceaccount.com",
|
|
|
|
FirebasePrivateKey: "TODO",
|
2022-11-13 19:17:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
var configStag = Config{
|
2022-11-20 17:19:11 +01:00
|
|
|
Namespace: "staging",
|
|
|
|
GinDebug: true,
|
|
|
|
ServerIP: "0.0.0.0",
|
|
|
|
ServerPort: "80",
|
|
|
|
DBFile: "/data/scn.sqlite3",
|
|
|
|
RequestTimeout: 16 * time.Second,
|
|
|
|
ReturnRawErrors: true,
|
|
|
|
FirebaseProjectID: "simplecloudnotifier-ea7ef",
|
|
|
|
FirebaseTokenURI: "https://oauth2.googleapis.com/token",
|
|
|
|
FirebasePrivKeyID: "5bfab19fca25034e87c5b3bd1a4334499d2d1f85",
|
|
|
|
FirebaseClientMail: "firebase-adminsdk-42grv@simplecloudnotifier-ea7ef.iam.gserviceaccount.com",
|
|
|
|
FirebasePrivateKey: "TODO",
|
2022-11-13 19:17:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
var configProd = Config{
|
2022-11-20 17:19:11 +01:00
|
|
|
Namespace: "production",
|
|
|
|
GinDebug: false,
|
|
|
|
ServerIP: "0.0.0.0",
|
|
|
|
ServerPort: "80",
|
|
|
|
DBFile: "/data/scn.sqlite3",
|
|
|
|
RequestTimeout: 16 * time.Second,
|
|
|
|
ReturnRawErrors: false,
|
|
|
|
FirebaseProjectID: "simplecloudnotifier-ea7ef",
|
|
|
|
FirebaseTokenURI: "https://oauth2.googleapis.com/token",
|
|
|
|
FirebasePrivKeyID: "5bfab19fca25034e87c5b3bd1a4334499d2d1f85",
|
|
|
|
FirebaseClientMail: "firebase-adminsdk-42grv@simplecloudnotifier-ea7ef.iam.gserviceaccount.com",
|
|
|
|
FirebasePrivateKey: "TODO",
|
2022-11-13 19:17:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
var allConfig = []Config{
|
2022-11-20 03:41:38 +01:00
|
|
|
configLocHost,
|
|
|
|
configLocDocker,
|
2022-11-13 19:17:07 +01:00
|
|
|
configDev,
|
|
|
|
configStag,
|
|
|
|
configProd,
|
|
|
|
}
|
|
|
|
|
|
|
|
func getConfig(ns string) (Config, bool) {
|
|
|
|
if ns == "" {
|
2022-11-20 03:41:38 +01:00
|
|
|
return configLocHost, true
|
2022-11-13 19:17:07 +01:00
|
|
|
}
|
|
|
|
for _, c := range allConfig {
|
|
|
|
if c.Namespace == ns {
|
|
|
|
return c, true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return Config{}, false
|
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
ns := os.Getenv("CONF_NS")
|
|
|
|
|
|
|
|
cfg, ok := getConfig(ns)
|
|
|
|
if !ok {
|
|
|
|
log.Fatal().Str("ns", ns).Msg("Unknown config-namespace")
|
|
|
|
}
|
|
|
|
|
|
|
|
Conf = cfg
|
|
|
|
}
|