-
Notifications
You must be signed in to change notification settings - Fork 2
/
config.go
204 lines (184 loc) · 7.9 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
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
package main
import (
"fmt"
"os"
"github.com/eukarya-inc/reearth-plateauview/server/cmsintegration"
"github.com/eukarya-inc/reearth-plateauview/server/datacatalog"
"github.com/eukarya-inc/reearth-plateauview/server/opinion"
"github.com/eukarya-inc/reearth-plateauview/server/plateaucms"
"github.com/eukarya-inc/reearth-plateauview/server/sdkapi/sdkapiv3"
"github.com/eukarya-inc/reearth-plateauview/server/searchindex"
"github.com/eukarya-inc/reearth-plateauview/server/sidebar"
"github.com/joho/godotenv"
"github.com/k0kubun/pp/v3"
"github.com/kelseyhightower/envconfig"
"github.com/reearth/reearthx/log"
)
var noColorPP *pp.PrettyPrinter
func init() {
noColorPP = pp.New()
noColorPP.SetColoringEnabled(false)
}
const configPrefix = "REEARTH_PLATEAUVIEW"
type Config struct {
Port uint `default:"8080" envconfig:"PORT"`
Host string `default:"http://localhost:8080"`
GOOGLE_CLOUD_PROJECT string `envconfig:"GOOGLE_CLOUD_PROJECT" pp:",omitempty"`
GOOGLE_CLOUD_REGION string `envconfig:"GOOGLE_CLOUD_REGION" pp:",omitempty"`
Debug bool `pp:",omitempty"`
Origin []string `pp:",omitempty"`
Secret string `pp:",omitempty"`
Delegate_URL string `pp:",omitempty"`
CMS_Webhook_Secret string `pp:",omitempty"`
CMS_BaseURL string `pp:",omitempty"`
CMS_Token string `pp:",omitempty"`
CMS_IntegrationID string `pp:",omitempty"`
CMS_PlateauProject string `pp:",omitempty"`
CMS_SystemProject string `pp:",omitempty"`
CMS_TokenProject string `pp:",omitempty"`
FME_BaseURL string `pp:",omitempty"`
FME_BaseURL_V2 string `pp:",omitempty"`
FME_URL_V3 string `pp:",omitempty"`
FME_Mock bool `pp:",omitempty"`
FME_Token string `pp:",omitempty"`
FME_SkipQualityCheck bool `pp:",omitempty"`
Ckan_BaseURL string `pp:",omitempty"`
Ckan_Org string `pp:",omitempty"`
Ckan_Token string `pp:",omitempty"`
Ckan_Private bool `pp:",omitempty"`
SDK_Token string `pp:",omitempty"`
SendGrid_APIKey string `pp:",omitempty"`
Opinion_From string `pp:",omitempty"`
Opinion_FromName string `pp:",omitempty"`
Opinion_To string `pp:",omitempty"`
Opinion_ToName string `pp:",omitempty"`
Sidebar_Token string `pp:",omitempty"`
Share_Disable bool `pp:",omitempty"`
Geospatialjp_Publication_Disable bool `pp:",omitempty"`
Geospatialjp_CatalocCheck_Disable bool `pp:",omitempty"`
Geospatialjp_BuildType string `pp:",omitempty"`
Geospatialjp_JobName string `pp:",omitempty"`
Geospatialjp_CloudBuildImage string `pp:",omitempty"`
Geospatialjp_CloudBuildMachineType string `pp:",omitempty"`
Geospatialjp_CloudBuildProject string `pp:",omitempty"`
Geospatialjp_CloudBuildRegion string `pp:",omitempty"`
Geospatialjp_CloudBuildDiskSizeGb int64 `pp:",omitempty"`
DataConv_Disable bool `pp:",omitempty"`
Indexer_Delegate bool `pp:",omitempty"`
DataCatalog_DisableCache bool `pp:",omitempty"`
DataCatalog_CacheUpdateKey string `pp:",omitempty"`
DataCatalog_PlaygroundEndpoint string `pp:",omitempty"`
DataCatalog_CacheTTL int `pp:",omitempty"`
DataCatalog_GQL_MaxComplexity int `pp:",omitempty"`
DataCatalog_PanicOnInit bool `pp:",omitempty"`
GCParcent int `pp:",omitempty"`
}
func NewConfig() (*Config, error) {
if err := godotenv.Load(".env"); err != nil && !os.IsNotExist(err) {
return nil, err
} else if err == nil {
log.Infof("config: .env loaded")
}
var c Config
err := envconfig.Process(configPrefix, &c)
return &c, err
}
func (c *Config) Print() string {
return noColorPP.Sprint(c)
}
func (c *Config) LocalURL(path string) string {
return fmt.Sprintf("http://[::]:%d%s", c.Port, path)
}
func (c *Config) CMSIntegration() cmsintegration.Config {
cloudBuildProject := c.Geospatialjp_CloudBuildProject
if cloudBuildProject == "" {
cloudBuildProject = c.GOOGLE_CLOUD_PROJECT
}
cloudBuildRegion := c.Geospatialjp_CloudBuildRegion
if cloudBuildRegion == "" {
cloudBuildRegion = c.GOOGLE_CLOUD_REGION
}
return cmsintegration.Config{
Host: c.Host,
FMEMock: c.FME_Mock,
FMEBaseURL: c.FME_BaseURL,
FMEToken: c.FME_Token,
FMEBaseURLV2: c.FME_BaseURL_V2,
FMEURLV3: c.FME_URL_V3,
FMESkipQualityCheck: c.FME_SkipQualityCheck,
CMSBaseURL: c.CMS_BaseURL,
CMSToken: c.CMS_Token,
CMSIntegration: c.CMS_IntegrationID,
Secret: c.Secret,
Debug: c.Debug,
CkanBaseURL: c.Ckan_BaseURL,
CkanOrg: c.Ckan_Org,
CkanToken: c.Ckan_Token,
CkanPrivate: c.Ckan_Private,
DisableGeospatialjpPublication: c.Geospatialjp_Publication_Disable,
DisableGeospatialjpCatalogCheck: c.Geospatialjp_CatalocCheck_Disable,
DisableDataConv: c.DataConv_Disable,
APIToken: c.Sidebar_Token,
GeospatialjpBuildType: c.Geospatialjp_BuildType,
GeospatialjpCloudRunJobsJobName: c.Geospatialjp_JobName,
GeospatialjpCloudBuildImage: c.Geospatialjp_CloudBuildImage,
GeospatialjpCloudBuildMachineType: c.Geospatialjp_CloudBuildMachineType,
GeospatialjpCloudBuildProject: cloudBuildProject,
GeospatialjpCloudBuildRegion: cloudBuildRegion,
GeospatialjpCloudBuildDiskSizeGb: c.Geospatialjp_CloudBuildDiskSizeGb,
}
}
func (c *Config) SearchIndex() searchindex.Config {
return searchindex.Config{
CMSBase: c.CMS_BaseURL,
CMSToken: c.CMS_Token,
CMSStorageProject: c.CMS_SystemProject,
Delegate: c.Indexer_Delegate,
DelegateURL: c.Delegate_URL,
Debug: c.Debug,
// CMSModel: c.CMS_Model,
// CMSStorageModel: c.CMS_IndexerStorageModel,
}
}
func (c *Config) SDKAPI() sdkapiv3.Config {
return sdkapiv3.Config{
DataCatagloAPIURL: c.LocalURL("/datacatalog"),
Token: c.SDK_Token,
}
}
func (c *Config) Opinion() opinion.Config {
return opinion.Config{
SendGridAPIKey: c.SendGrid_APIKey,
From: c.Opinion_From,
FromName: c.Opinion_FromName,
To: c.Opinion_To,
ToName: c.Opinion_ToName,
}
}
func (c *Config) Sidebar() sidebar.Config {
return sidebar.Config{
Config: c.plateauCMS(),
DisableShare: c.Share_Disable,
}
}
func (c *Config) DataCatalog() datacatalog.Config {
return datacatalog.Config{
Config: c.plateauCMS(),
CacheUpdateKey: c.DataCatalog_CacheUpdateKey,
PlaygroundEndpoint: c.DataCatalog_PlaygroundEndpoint,
GraphqlMaxComplexity: c.DataCatalog_GQL_MaxComplexity,
DisableCache: c.DataCatalog_DisableCache,
CacheTTL: c.DataCatalog_CacheTTL,
ErrorOnInit: c.DataCatalog_PanicOnInit,
}
}
func (c *Config) plateauCMS() plateaucms.Config {
return plateaucms.Config{
CMSBaseURL: c.CMS_BaseURL,
CMSMainToken: c.CMS_Token,
CMSTokenProject: c.CMS_TokenProject,
// compat
CMSMainProject: c.CMS_SystemProject,
AdminToken: c.Sidebar_Token,
}
}