Mercurial > gemma
comparison pkg/config/config.go @ 1644:eadf84bb0e98
New config variable 'external-url'.
Deep inside the import queue we don't known the URL we find the server at.
We don't have any HTTP request we can derive this information wrong
so it needs to be configured.
Defaults to http://${web-host}:${web-port} .
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Thu, 20 Dec 2018 14:39:23 +0100 |
parents | a25a4d4a3e6e |
children | bd09d6ad4c14 |
comparison
equal
deleted
inserted
replaced
1643:1fde2f48977b | 1644:eadf84bb0e98 |
---|---|
104 // TmpDir is the path where to store temporary files. | 104 // TmpDir is the path where to store temporary files. |
105 // If left empty the system default for temporary files is used. | 105 // If left empty the system default for temporary files is used. |
106 func TmpDir() string { return viper.GetString("tmp-dir") } | 106 func TmpDir() string { return viper.GetString("tmp-dir") } |
107 | 107 |
108 var ( | 108 var ( |
109 proxyKeyOnce sync.Once | 109 proxyKeyOnce sync.Once |
110 proxyKey []byte | 110 proxyKey []byte |
111 | |
112 proxyPrefixOnce sync.Once | 111 proxyPrefixOnce sync.Once |
113 proxyPrefix string | 112 proxyPrefix string |
113 externalURLOnce sync.Once | |
114 externalURL string | |
114 ) | 115 ) |
115 | 116 |
116 // ProxyKey is a crytographic key to sign the URLs generated by the proxy. | 117 // ProxyKey is a crytographic key to sign the URLs generated by the proxy. |
117 // Use this to ensure that only known URLs are reachable over the proxy. | 118 // Use this to ensure that only known URLs are reachable over the proxy. |
118 // If left blank a random key is generated a gemma boot time. | 119 // If left blank a random key is generated a gemma boot time. |
140 // You may need to set this if you run gemma behind a proxy | 141 // You may need to set this if you run gemma behind a proxy |
141 // on a specific domain. | 142 // on a specific domain. |
142 func ProxyPrefix() string { | 143 func ProxyPrefix() string { |
143 fetchPrefix := func() { | 144 fetchPrefix := func() { |
144 if proxyPrefix == "" { | 145 if proxyPrefix == "" { |
145 proxyPrefix = fmt.Sprintf("http://%s:%d", WebHost(), WebPort()) | 146 if proxyPrefix = viper.GetString("proxy-prefix"); proxyPrefix == "" { |
147 proxyPrefix = fmt.Sprintf("http://%s:%d", WebHost(), WebPort()) | |
148 } | |
146 } | 149 } |
147 } | 150 } |
148 proxyPrefixOnce.Do(fetchPrefix) | 151 proxyPrefixOnce.Do(fetchPrefix) |
149 return proxyPrefix | 152 return proxyPrefix |
153 } | |
154 | |
155 // ExternalURL is the URL to find this server from the outside. | |
156 // It defauls to http://${WebHost}:${WebPort}". | |
157 func ExternalURL() string { | |
158 fetchExternal := func() { | |
159 if externalURL == "" { | |
160 if externalURL = viper.GetString("external-url"); externalURL == "" { | |
161 externalURL = fmt.Sprintf("http://%s:%d", WebHost(), WebPort()) | |
162 } | |
163 } | |
164 } | |
165 externalURLOnce.Do(fetchExternal) | |
166 return externalURL | |
150 } | 167 } |
151 | 168 |
152 // RootCmd is cobra command to be bound th the cobra/viper infrastructure. | 169 // RootCmd is cobra command to be bound th the cobra/viper infrastructure. |
153 var RootCmd = &cobra.Command{ | 170 var RootCmd = &cobra.Command{ |
154 Use: "gemma", | 171 Use: "gemma", |
217 str("geoserver-url", "http://localhost:8080/geoserver", "URL to GeoServer") | 234 str("geoserver-url", "http://localhost:8080/geoserver", "URL to GeoServer") |
218 str("geoserver-user", "admin", "GeoServer user") | 235 str("geoserver-user", "admin", "GeoServer user") |
219 str("geoserver-password", "geoserver", "GeoServer password") | 236 str("geoserver-password", "geoserver", "GeoServer password") |
220 bl("geoserver-clean", false, "Clean GeoServer setup") | 237 bl("geoserver-clean", false, "Clean GeoServer setup") |
221 | 238 |
222 str("proxy-key", "", `signing key for proxy URLs. Defaults to random key.`) | 239 str("proxy-key", "", "signing key for proxy URLs.\n"+ |
223 str("proxy-prefix", "", `URL prefix of proxy. Defaults to "http://${web-host}:${web-port}"`) | 240 "Defaults to random key.") |
224 | 241 str("proxy-prefix", "", "URL prefix of proxy.\n"+ |
225 str("tmp-dir", "", "Temp directory of gemma server. Defaults to system temp directory.") | 242 "Defaults to 'http://${web-host}:${web-port}'") |
243 | |
244 str("external-url", "", "URL to find the server from the outside.\n"+ | |
245 "Defaults to 'http://${web-host}:${web-port}'") | |
246 | |
247 str("tmp-dir", "", "Temp directory of gemma server.\n"+ | |
248 "Defaults to system temp directory.") | |
226 } | 249 } |
227 | 250 |
228 var ( | 251 var ( |
229 configCond = sync.NewCond(new(sync.Mutex)) | 252 configCond = sync.NewCond(new(sync.Mutex)) |
230 configReady bool | 253 configReady bool |