-
Notifications
You must be signed in to change notification settings - Fork 3
/
gf_solo_config.go
149 lines (112 loc) · 4.4 KB
/
gf_solo_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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/*
GloFlow application and media management/publishing platform
Copyright (C) 2021 Ivan Trajkovic
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
package gf_solo_service
import (
"strings"
"github.com/spf13/viper"
)
//-------------------------------------------------------------
type GFconfig struct {
// ENVIRONMENT
EnvStr string `mapstructure:"env"`
// DOMAINS - where this gf_solo instance is reachable on
DomainBaseStr string `mapstructure:"domain_base"`
DomainAdminBaseStr string `mapstructure:"domain_admin_base"`
// DOMAIN_FOR_AUTH_COOKIES - domain/pattern that is set on the auth cookies to restrict their scope.
DomainForAuthCookiesStr string `mapstructure:"domain_for_auth_cookies"`
// PORTS
PortStr string `mapstructure:"port"`
PortAdminStr string `mapstructure:"port_admin"`
PortMetricsStr string `mapstructure:"port_metrics"`
// SQL
SQLuserNameStr string `mapstructure:"sql_user_name"`
SQLpassStr string `mapstructure:"sql_pass"`
SQLhostStr string `mapstructure:"sql_host"`
SQLdbNameStr string `mapstructure:"sql_db_name"`
// MONGODB - this is the dedicated mongodb DB
MongoHostStr string `mapstructure:"mongodb_host"`
MongoDBnameStr string `mapstructure:"mongodb_db_name"`
// ELASTICSEARCH
// ElasticsearchHostStr string `mapstructure:"elasticsearch_host"`
// SENTRY_ENDPOINT
SentryEndpointStr string `mapstructure:"sentry_endpoint"`
// TEMPLATES
TemplatesPathsMap map[string]string `mapstructure:"templates_paths"`
//--------------------
// IDENTITY
AuthSubsystemTypeStr string `mapstructure:"auth_subsystem_type"`
AdminMFAsecretKeyBase32str string `mapstructure:"admin_mfa_secret_key_base32"`
AdminEmailStr string `mapstructure:"admin_email"`
//--------------------
// GF_IMAGES
ImagesConfigFilePathStr string `mapstructure:"images__config_file_path"`
//--------------------
// GF_ANALYTICS
AnalyticsPyStatsDirsLst []string `mapstructure:"analytics__py_stats_dirs"`
AnalyticsRunIndexerBool bool `mapstructure:"analytics__run_indexer"`
CrawlConfigFilePathStr string `mapstructure:"crawl__config_file_path"`
CrawlClusterNodeTypeStr string `mapstructure:"crawl__cluster_node_type"`
CrawlImagesLocalDirPathStr string `mapstructure:"crawl__images_local_dir_path"`
//--------------------
// ALCHEMY
AlchemyAPIkeyStr string `mapstructure:"alchemy_api_key"`
//--------------------
// NEW_STORAGE_ENGINE - flag indicating if the new image storage engine should be used
ImagesUseNewStorageEngineBool bool `mapstructure:"images_use_new_storage_engine"`
// IPFS
IPFSnodeHostStr string `mapstructure:"ipfs_node_host"`
//--------------------
}
//-------------------------------------------------------------
// CONFIG_INIT
/*
load config for gf_solo from all the sources.
Viper lib is used for config loading.
configs are loaded from:
- ENV vars
- gf_solo.yaml config file
- via CLI args
*/
func ConfigInit(pConfigDirPathStr string,
pConfigFileNameStr string) (*GFconfig, error) {
configNameStr := strings.Split(pConfigFileNameStr, ".")[0] // viper expects just the file name, without extension
// FILE
viper.AddConfigPath(pConfigDirPathStr)
viper.SetConfigName(configNameStr)
//--------------------
// ENV_VARS
// all config members that have their mapstructure name for Viper config,
// also have a corresponding ENV var name thats generated for them by
// upper-casing their name.
//--------------------
// ENV_PREFIX - "GF" becomes "GF_" - prefix expected in all recognized ENV vars.
viper.SetEnvPrefix("GF")
// IMPORTANT!! - enable Viper parsing ENV vars.
viper.AutomaticEnv()
//--------------------
// LOAD
err := viper.ReadInConfig()
if err != nil {
return nil, err
}
// CONFIG
config := &GFconfig{}
err = viper.Unmarshal(config)
if err != nil {
return nil, err
}
return config, nil
}