Mercurial > gemma
annotate pkg/config/config.go @ 1321:8d9754007089
Used keyed initializer to make 'go vet' happy.
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Sat, 24 Nov 2018 16:40:34 +0100 |
parents | 5443f5c9154c |
children | 6a439a92abf7 |
rev | line source |
---|---|
1017
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1000
diff
changeset
|
1 // This is Free Software under GNU Affero General Public License v >= 3.0 |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1000
diff
changeset
|
2 // without warranty, see README.md and license for details. |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1000
diff
changeset
|
3 // |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1000
diff
changeset
|
4 // SPDX-License-Identifier: AGPL-3.0-or-later |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1000
diff
changeset
|
5 // License-Filename: LICENSES/AGPL-3.0.txt |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1000
diff
changeset
|
6 // |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1000
diff
changeset
|
7 // Copyright (C) 2018 by via donau |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1000
diff
changeset
|
8 // – Österreichische Wasserstraßen-Gesellschaft mbH |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1000
diff
changeset
|
9 // Software engineering by Intevation GmbH |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1000
diff
changeset
|
10 // |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1000
diff
changeset
|
11 // Author(s): |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1000
diff
changeset
|
12 // * Sascha L. Teichmann <sascha.teichmann@intevation.de> |
1317
5443f5c9154c
Added missing authors names in Go files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1017
diff
changeset
|
13 // * Bernhard E. Reiter <bernhard.reiter@intevation.de> |
1017
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1000
diff
changeset
|
14 |
28
714787accd26
Fetch database connection string parts from configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
15 package config |
714787accd26
Fetch database connection string parts from configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
16 |
332
394fafeb4052
Use viper as config storage (I don't like it).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
325
diff
changeset
|
17 import ( |
408
ac23905e64b1
Improve WFS proxy a lot. It now generates signed re-writings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
396
diff
changeset
|
18 "crypto/sha256" |
ac23905e64b1
Improve WFS proxy a lot. It now generates signed re-writings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
396
diff
changeset
|
19 "fmt" |
332
394fafeb4052
Use viper as config storage (I don't like it).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
325
diff
changeset
|
20 "log" |
408
ac23905e64b1
Improve WFS proxy a lot. It now generates signed re-writings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
396
diff
changeset
|
21 "sync" |
332
394fafeb4052
Use viper as config storage (I don't like it).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
325
diff
changeset
|
22 |
394fafeb4052
Use viper as config storage (I don't like it).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
325
diff
changeset
|
23 homedir "github.com/mitchellh/go-homedir" |
394fafeb4052
Use viper as config storage (I don't like it).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
325
diff
changeset
|
24 "github.com/spf13/cobra" |
394fafeb4052
Use viper as config storage (I don't like it).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
325
diff
changeset
|
25 "github.com/spf13/viper" |
408
ac23905e64b1
Improve WFS proxy a lot. It now generates signed re-writings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
396
diff
changeset
|
26 |
414
c1047fd04a3a
Moved project specific Go packages to new pkg folder.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
408
diff
changeset
|
27 "gemma.intevation.de/gemma/pkg/common" |
332
394fafeb4052
Use viper as config storage (I don't like it).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
325
diff
changeset
|
28 ) |
394fafeb4052
Use viper as config storage (I don't like it).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
325
diff
changeset
|
29 |
394fafeb4052
Use viper as config storage (I don't like it).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
325
diff
changeset
|
30 // This is not part of the persistent config. |
394fafeb4052
Use viper as config storage (I don't like it).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
325
diff
changeset
|
31 var configFile string |
394fafeb4052
Use viper as config storage (I don't like it).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
325
diff
changeset
|
32 |
394fafeb4052
Use viper as config storage (I don't like it).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
325
diff
changeset
|
33 func ConfigFile() string { return configFile } |
394fafeb4052
Use viper as config storage (I don't like it).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
325
diff
changeset
|
34 |
517
7e45aaec7081
Consolidate configuration parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
496
diff
changeset
|
35 func DBHost() string { return viper.GetString("db-host") } |
7e45aaec7081
Consolidate configuration parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
496
diff
changeset
|
36 func DBPort() uint { return uint(viper.GetInt32("db-port")) } |
7e45aaec7081
Consolidate configuration parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
496
diff
changeset
|
37 func DBName() string { return viper.GetString("db-name") } |
7e45aaec7081
Consolidate configuration parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
496
diff
changeset
|
38 func DBUser() string { return viper.GetString("db-user") } |
7e45aaec7081
Consolidate configuration parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
496
diff
changeset
|
39 func DBPassword() string { return viper.GetString("db-password") } |
7e45aaec7081
Consolidate configuration parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
496
diff
changeset
|
40 func DBSSLMode() string { return viper.GetString("db-ssl") } |
7e45aaec7081
Consolidate configuration parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
496
diff
changeset
|
41 |
332
394fafeb4052
Use viper as config storage (I don't like it).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
325
diff
changeset
|
42 func SessionStore() string { return viper.GetString("sessions") } |
394fafeb4052
Use viper as config storage (I don't like it).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
325
diff
changeset
|
43 |
517
7e45aaec7081
Consolidate configuration parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
496
diff
changeset
|
44 func Web() string { return viper.GetString("web") } |
7e45aaec7081
Consolidate configuration parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
496
diff
changeset
|
45 func WebHost() string { return viper.GetString("host") } |
7e45aaec7081
Consolidate configuration parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
496
diff
changeset
|
46 func WebPort() uint { return uint(viper.GetInt32("port")) } |
386
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
385
diff
changeset
|
47 |
332
394fafeb4052
Use viper as config storage (I don't like it).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
325
diff
changeset
|
48 func MailHost() string { return viper.GetString("mail-host") } |
394fafeb4052
Use viper as config storage (I don't like it).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
325
diff
changeset
|
49 func MailPort() uint { return uint(viper.GetInt32("mail-port")) } |
394fafeb4052
Use viper as config storage (I don't like it).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
325
diff
changeset
|
50 func MailUser() string { return viper.GetString("mail-user") } |
394fafeb4052
Use viper as config storage (I don't like it).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
325
diff
changeset
|
51 func MailPassword() string { return viper.GetString("mail-password") } |
394fafeb4052
Use viper as config storage (I don't like it).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
325
diff
changeset
|
52 func MailFrom() string { return viper.GetString("mail-from") } |
394fafeb4052
Use viper as config storage (I don't like it).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
325
diff
changeset
|
53 func MailHelo() string { return viper.GetString("mail-helo") } |
394fafeb4052
Use viper as config storage (I don't like it).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
325
diff
changeset
|
54 |
394fafeb4052
Use viper as config storage (I don't like it).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
325
diff
changeset
|
55 func AllowedOrigins() []string { return viper.GetStringSlice("allowed-origins") } |
394fafeb4052
Use viper as config storage (I don't like it).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
325
diff
changeset
|
56 |
421
c37457f12b8e
Differ between internal and external proxies.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
414
diff
changeset
|
57 func Proxies(key string) map[string]interface{} { return viper.GetStringMap(key) } |
335
bd292a554b6e
Made gemma a WFS proxy.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
332
diff
changeset
|
58 |
385
3cfab707f909
Added config parameters for GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
338
diff
changeset
|
59 func GeoServerURL() string { return viper.GetString("geoserver-url") } |
3cfab707f909
Added config parameters for GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
338
diff
changeset
|
60 func GeoServerUser() string { return viper.GetString("geoserver-user") } |
3cfab707f909
Added config parameters for GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
338
diff
changeset
|
61 func GeoServerPassword() string { return viper.GetString("geoserver-password") } |
874
da526b58c9c4
Added a flag geoserver-clean to force deletion of the gemma workspace before configuring the GeoServer again.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
517
diff
changeset
|
62 func GeoServerClean() bool { return viper.GetBool("geoserver-clean") } |
385
3cfab707f909
Added config parameters for GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
338
diff
changeset
|
63 |
958
2818ad6c7d32
Started with import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
874
diff
changeset
|
64 func TmpDir() string { return viper.GetString("tmp-dir") } |
2818ad6c7d32
Started with import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
874
diff
changeset
|
65 |
408
ac23905e64b1
Improve WFS proxy a lot. It now generates signed re-writings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
396
diff
changeset
|
66 var ( |
ac23905e64b1
Improve WFS proxy a lot. It now generates signed re-writings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
396
diff
changeset
|
67 proxyKeyOnce sync.Once |
ac23905e64b1
Improve WFS proxy a lot. It now generates signed re-writings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
396
diff
changeset
|
68 proxyKey []byte |
ac23905e64b1
Improve WFS proxy a lot. It now generates signed re-writings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
396
diff
changeset
|
69 |
ac23905e64b1
Improve WFS proxy a lot. It now generates signed re-writings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
396
diff
changeset
|
70 proxyPrefixOnce sync.Once |
ac23905e64b1
Improve WFS proxy a lot. It now generates signed re-writings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
396
diff
changeset
|
71 proxyPrefix string |
ac23905e64b1
Improve WFS proxy a lot. It now generates signed re-writings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
396
diff
changeset
|
72 ) |
ac23905e64b1
Improve WFS proxy a lot. It now generates signed re-writings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
396
diff
changeset
|
73 |
ac23905e64b1
Improve WFS proxy a lot. It now generates signed re-writings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
396
diff
changeset
|
74 func ProxyKey() []byte { |
ac23905e64b1
Improve WFS proxy a lot. It now generates signed re-writings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
396
diff
changeset
|
75 fetchKey := func() { |
ac23905e64b1
Improve WFS proxy a lot. It now generates signed re-writings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
396
diff
changeset
|
76 if proxyKey == nil { |
ac23905e64b1
Improve WFS proxy a lot. It now generates signed re-writings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
396
diff
changeset
|
77 key := []byte(viper.GetString("proxy-key")) |
ac23905e64b1
Improve WFS proxy a lot. It now generates signed re-writings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
396
diff
changeset
|
78 if len(key) == 0 { |
ac23905e64b1
Improve WFS proxy a lot. It now generates signed re-writings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
396
diff
changeset
|
79 key = common.GenerateRandomKey(64) |
ac23905e64b1
Improve WFS proxy a lot. It now generates signed re-writings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
396
diff
changeset
|
80 } |
ac23905e64b1
Improve WFS proxy a lot. It now generates signed re-writings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
396
diff
changeset
|
81 hash := sha256.New() |
ac23905e64b1
Improve WFS proxy a lot. It now generates signed re-writings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
396
diff
changeset
|
82 hash.Write(key) |
ac23905e64b1
Improve WFS proxy a lot. It now generates signed re-writings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
396
diff
changeset
|
83 proxyKey = hash.Sum(nil) |
ac23905e64b1
Improve WFS proxy a lot. It now generates signed re-writings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
396
diff
changeset
|
84 } |
ac23905e64b1
Improve WFS proxy a lot. It now generates signed re-writings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
396
diff
changeset
|
85 } |
ac23905e64b1
Improve WFS proxy a lot. It now generates signed re-writings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
396
diff
changeset
|
86 proxyKeyOnce.Do(fetchKey) |
ac23905e64b1
Improve WFS proxy a lot. It now generates signed re-writings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
396
diff
changeset
|
87 return proxyKey |
ac23905e64b1
Improve WFS proxy a lot. It now generates signed re-writings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
396
diff
changeset
|
88 } |
ac23905e64b1
Improve WFS proxy a lot. It now generates signed re-writings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
396
diff
changeset
|
89 |
ac23905e64b1
Improve WFS proxy a lot. It now generates signed re-writings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
396
diff
changeset
|
90 func ProxyPrefix() string { |
ac23905e64b1
Improve WFS proxy a lot. It now generates signed re-writings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
396
diff
changeset
|
91 fetchPrefix := func() { |
ac23905e64b1
Improve WFS proxy a lot. It now generates signed re-writings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
396
diff
changeset
|
92 if proxyPrefix == "" { |
ac23905e64b1
Improve WFS proxy a lot. It now generates signed re-writings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
396
diff
changeset
|
93 proxyPrefix = fmt.Sprintf("http://%s:%d", WebHost(), WebPort()) |
ac23905e64b1
Improve WFS proxy a lot. It now generates signed re-writings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
396
diff
changeset
|
94 } |
ac23905e64b1
Improve WFS proxy a lot. It now generates signed re-writings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
396
diff
changeset
|
95 } |
ac23905e64b1
Improve WFS proxy a lot. It now generates signed re-writings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
396
diff
changeset
|
96 proxyPrefixOnce.Do(fetchPrefix) |
ac23905e64b1
Improve WFS proxy a lot. It now generates signed re-writings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
396
diff
changeset
|
97 return proxyPrefix |
ac23905e64b1
Improve WFS proxy a lot. It now generates signed re-writings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
396
diff
changeset
|
98 } |
ac23905e64b1
Improve WFS proxy a lot. It now generates signed re-writings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
396
diff
changeset
|
99 |
332
394fafeb4052
Use viper as config storage (I don't like it).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
325
diff
changeset
|
100 var RootCmd = &cobra.Command{ |
394fafeb4052
Use viper as config storage (I don't like it).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
325
diff
changeset
|
101 Use: "gemma", |
394fafeb4052
Use viper as config storage (I don't like it).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
325
diff
changeset
|
102 Short: "gemma is a server for waterway monitoring and management", |
394fafeb4052
Use viper as config storage (I don't like it).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
325
diff
changeset
|
103 } |
119
29e56c342c9f
Added first middleware for JWT token extraction. TODO: Add second one to check against logged in users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
28
diff
changeset
|
104 |
385
3cfab707f909
Added config parameters for GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
338
diff
changeset
|
105 var allowedOrigins = []string{ |
3cfab707f909
Added config parameters for GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
338
diff
changeset
|
106 // TODO: Fill me! |
3cfab707f909
Added config parameters for GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
338
diff
changeset
|
107 } |
3cfab707f909
Added config parameters for GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
338
diff
changeset
|
108 |
332
394fafeb4052
Use viper as config storage (I don't like it).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
325
diff
changeset
|
109 func init() { |
394fafeb4052
Use viper as config storage (I don't like it).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
325
diff
changeset
|
110 cobra.OnInitialize(initConfig) |
394fafeb4052
Use viper as config storage (I don't like it).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
325
diff
changeset
|
111 fl := RootCmd.PersistentFlags() |
394fafeb4052
Use viper as config storage (I don't like it).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
325
diff
changeset
|
112 fl.StringVarP(&configFile, "config", "c", "", "config file (default is $HOME/.gemma.toml)") |
394fafeb4052
Use viper as config storage (I don't like it).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
325
diff
changeset
|
113 |
394fafeb4052
Use viper as config storage (I don't like it).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
325
diff
changeset
|
114 vbind := func(name string) { viper.BindPFlag(name, fl.Lookup(name)) } |
302
0777aa6de45b
Password reset. Part I
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
221
diff
changeset
|
115 |
385
3cfab707f909
Added config parameters for GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
338
diff
changeset
|
116 str := func(name, value, usage string) { |
3cfab707f909
Added config parameters for GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
338
diff
changeset
|
117 fl.String(name, value, usage) |
3cfab707f909
Added config parameters for GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
338
diff
changeset
|
118 vbind(name) |
3cfab707f909
Added config parameters for GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
338
diff
changeset
|
119 } |
3cfab707f909
Added config parameters for GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
338
diff
changeset
|
120 strP := func(name, shorthand, value, usage string) { |
3cfab707f909
Added config parameters for GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
338
diff
changeset
|
121 fl.StringP(name, shorthand, value, usage) |
3cfab707f909
Added config parameters for GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
338
diff
changeset
|
122 vbind(name) |
3cfab707f909
Added config parameters for GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
338
diff
changeset
|
123 } |
3cfab707f909
Added config parameters for GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
338
diff
changeset
|
124 ui := func(name string, value uint, usage string) { |
3cfab707f909
Added config parameters for GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
338
diff
changeset
|
125 fl.Uint(name, value, usage) |
3cfab707f909
Added config parameters for GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
338
diff
changeset
|
126 vbind(name) |
3cfab707f909
Added config parameters for GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
338
diff
changeset
|
127 } |
3cfab707f909
Added config parameters for GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
338
diff
changeset
|
128 uiP := func(name, shorthand string, value uint, usage string) { |
3cfab707f909
Added config parameters for GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
338
diff
changeset
|
129 fl.UintP(name, shorthand, value, usage) |
3cfab707f909
Added config parameters for GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
338
diff
changeset
|
130 vbind(name) |
3cfab707f909
Added config parameters for GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
338
diff
changeset
|
131 } |
3cfab707f909
Added config parameters for GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
338
diff
changeset
|
132 strSl := func(name string, value []string, usage string) { |
3cfab707f909
Added config parameters for GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
338
diff
changeset
|
133 fl.StringSlice(name, value, usage) |
3cfab707f909
Added config parameters for GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
338
diff
changeset
|
134 vbind(name) |
3cfab707f909
Added config parameters for GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
338
diff
changeset
|
135 } |
874
da526b58c9c4
Added a flag geoserver-clean to force deletion of the gemma workspace before configuring the GeoServer again.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
517
diff
changeset
|
136 bl := func(name string, value bool, usage string) { |
da526b58c9c4
Added a flag geoserver-clean to force deletion of the gemma workspace before configuring the GeoServer again.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
517
diff
changeset
|
137 fl.Bool(name, value, usage) |
da526b58c9c4
Added a flag geoserver-clean to force deletion of the gemma workspace before configuring the GeoServer again.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
517
diff
changeset
|
138 vbind(name) |
da526b58c9c4
Added a flag geoserver-clean to force deletion of the gemma workspace before configuring the GeoServer again.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
517
diff
changeset
|
139 } |
332
394fafeb4052
Use viper as config storage (I don't like it).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
325
diff
changeset
|
140 |
517
7e45aaec7081
Consolidate configuration parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
496
diff
changeset
|
141 strP("db-host", "H", "localhost", "host of the database") |
7e45aaec7081
Consolidate configuration parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
496
diff
changeset
|
142 uiP("db-port", "P", 5432, "port of the database") |
7e45aaec7081
Consolidate configuration parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
496
diff
changeset
|
143 strP("db-name", "d", "gemma", "name of the database") |
7e45aaec7081
Consolidate configuration parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
496
diff
changeset
|
144 str("db-user", "meta_login", "Metamorphic database user") |
7e45aaec7081
Consolidate configuration parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
496
diff
changeset
|
145 str("db-password", "", "Metamorphic database user password") |
7e45aaec7081
Consolidate configuration parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
496
diff
changeset
|
146 strP("db-ssl", "S", "prefer", "SSL mode of the database") |
385
3cfab707f909
Added config parameters for GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
338
diff
changeset
|
147 |
3cfab707f909
Added config parameters for GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
338
diff
changeset
|
148 strP("sessions", "s", "", "path to the sessions file") |
3cfab707f909
Added config parameters for GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
338
diff
changeset
|
149 |
394
f24ed1d570c7
server: add default value for serving "web".
Bernhard Reiter <bernhard@intevation.de>
parents:
386
diff
changeset
|
150 strP("web", "w", "./web", "path to the web files") |
385
3cfab707f909
Added config parameters for GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
338
diff
changeset
|
151 strP("host", "o", "localhost", "host of the web app") |
3cfab707f909
Added config parameters for GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
338
diff
changeset
|
152 uiP("port", "p", 8000, "port of the web app") |
3cfab707f909
Added config parameters for GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
338
diff
changeset
|
153 |
3cfab707f909
Added config parameters for GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
338
diff
changeset
|
154 str("mail-host", "localhost", "server to send mail with") |
3cfab707f909
Added config parameters for GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
338
diff
changeset
|
155 ui("mail-port", 465, "port of server to send mail with") |
517
7e45aaec7081
Consolidate configuration parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
496
diff
changeset
|
156 str("mail-user", "gemma", "user to authenticate against mail-host.\n"+ |
7e45aaec7081
Consolidate configuration parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
496
diff
changeset
|
157 "Leave empty for trying to send without auth.") |
385
3cfab707f909
Added config parameters for GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
338
diff
changeset
|
158 str("mail-password", "", "password of user to send mail with") |
489
8f3f7577fbe7
proxy: fix minor typo in default for --mail-from
Bernhard Reiter <bernhard@intevation.de>
parents:
449
diff
changeset
|
159 str("mail-from", "noreply@localhost", "from line of mails") |
385
3cfab707f909
Added config parameters for GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
338
diff
changeset
|
160 str("mail-helo", "localhost", "name of server to send mail from.") |
332
394fafeb4052
Use viper as config storage (I don't like it).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
325
diff
changeset
|
161 |
385
3cfab707f909
Added config parameters for GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
338
diff
changeset
|
162 strSl("allowed-origins", allowedOrigins, "allow access for remote origins") |
3cfab707f909
Added config parameters for GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
338
diff
changeset
|
163 |
3cfab707f909
Added config parameters for GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
338
diff
changeset
|
164 str("geoserver-url", "http://localhost:8080/geoserver", "URL to GeoServer") |
3cfab707f909
Added config parameters for GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
338
diff
changeset
|
165 str("geoserver-user", "admin", "GeoServer user") |
3cfab707f909
Added config parameters for GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
338
diff
changeset
|
166 str("geoserver-password", "geoserver", "GeoServer password") |
874
da526b58c9c4
Added a flag geoserver-clean to force deletion of the gemma workspace before configuring the GeoServer again.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
517
diff
changeset
|
167 bl("geoserver-clean", false, "Clean GeoServer setup") |
408
ac23905e64b1
Improve WFS proxy a lot. It now generates signed re-writings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
396
diff
changeset
|
168 |
ac23905e64b1
Improve WFS proxy a lot. It now generates signed re-writings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
396
diff
changeset
|
169 str("proxy-key", "", `signing key for proxy URLs. Defaults to random key.`) |
ac23905e64b1
Improve WFS proxy a lot. It now generates signed re-writings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
396
diff
changeset
|
170 str("proxy-prefix", "", `URL prefix of proxy. Defaults to "http://${web-host}:${web-port}"`) |
ac23905e64b1
Improve WFS proxy a lot. It now generates signed re-writings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
396
diff
changeset
|
171 |
958
2818ad6c7d32
Started with import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
874
diff
changeset
|
172 str("tmp-dir", "", "Temp directory of gemma server. Defaults to system temp directory.") |
1000
14425e35e3c2
Wait with start of import queue until configuration is fully loaded.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
958
diff
changeset
|
173 } |
958
2818ad6c7d32
Started with import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
874
diff
changeset
|
174 |
1000
14425e35e3c2
Wait with start of import queue until configuration is fully loaded.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
958
diff
changeset
|
175 var ( |
14425e35e3c2
Wait with start of import queue until configuration is fully loaded.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
958
diff
changeset
|
176 configCond = sync.NewCond(new(sync.Mutex)) |
14425e35e3c2
Wait with start of import queue until configuration is fully loaded.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
958
diff
changeset
|
177 configReady bool |
14425e35e3c2
Wait with start of import queue until configuration is fully loaded.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
958
diff
changeset
|
178 ) |
14425e35e3c2
Wait with start of import queue until configuration is fully loaded.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
958
diff
changeset
|
179 |
14425e35e3c2
Wait with start of import queue until configuration is fully loaded.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
958
diff
changeset
|
180 func Ready() { |
14425e35e3c2
Wait with start of import queue until configuration is fully loaded.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
958
diff
changeset
|
181 configCond.L.Lock() |
14425e35e3c2
Wait with start of import queue until configuration is fully loaded.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
958
diff
changeset
|
182 defer configCond.L.Unlock() |
14425e35e3c2
Wait with start of import queue until configuration is fully loaded.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
958
diff
changeset
|
183 configReady = true |
14425e35e3c2
Wait with start of import queue until configuration is fully loaded.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
958
diff
changeset
|
184 configCond.Broadcast() |
14425e35e3c2
Wait with start of import queue until configuration is fully loaded.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
958
diff
changeset
|
185 } |
14425e35e3c2
Wait with start of import queue until configuration is fully loaded.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
958
diff
changeset
|
186 |
14425e35e3c2
Wait with start of import queue until configuration is fully loaded.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
958
diff
changeset
|
187 func WaitReady() { |
14425e35e3c2
Wait with start of import queue until configuration is fully loaded.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
958
diff
changeset
|
188 configCond.L.Lock() |
14425e35e3c2
Wait with start of import queue until configuration is fully loaded.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
958
diff
changeset
|
189 defer configCond.L.Unlock() |
14425e35e3c2
Wait with start of import queue until configuration is fully loaded.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
958
diff
changeset
|
190 for !configReady { |
14425e35e3c2
Wait with start of import queue until configuration is fully loaded.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
958
diff
changeset
|
191 configCond.Wait() |
14425e35e3c2
Wait with start of import queue until configuration is fully loaded.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
958
diff
changeset
|
192 } |
332
394fafeb4052
Use viper as config storage (I don't like it).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
325
diff
changeset
|
193 } |
325
c23eb0f34e39
Added CORS support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
302
diff
changeset
|
194 |
332
394fafeb4052
Use viper as config storage (I don't like it).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
325
diff
changeset
|
195 func initConfig() { |
394fafeb4052
Use viper as config storage (I don't like it).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
325
diff
changeset
|
196 // Don't forget to read config either from cfgFile or from home directory! |
394fafeb4052
Use viper as config storage (I don't like it).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
325
diff
changeset
|
197 if configFile != "" { |
394fafeb4052
Use viper as config storage (I don't like it).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
325
diff
changeset
|
198 // Use config file from the flag. |
394fafeb4052
Use viper as config storage (I don't like it).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
325
diff
changeset
|
199 viper.SetConfigFile(configFile) |
394fafeb4052
Use viper as config storage (I don't like it).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
325
diff
changeset
|
200 } else { |
394fafeb4052
Use viper as config storage (I don't like it).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
325
diff
changeset
|
201 // Find home directory. |
394fafeb4052
Use viper as config storage (I don't like it).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
325
diff
changeset
|
202 home, err := homedir.Dir() |
394fafeb4052
Use viper as config storage (I don't like it).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
325
diff
changeset
|
203 if err != nil { |
394fafeb4052
Use viper as config storage (I don't like it).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
325
diff
changeset
|
204 log.Fatalf("error: %v\n", err) |
394fafeb4052
Use viper as config storage (I don't like it).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
325
diff
changeset
|
205 } |
394fafeb4052
Use viper as config storage (I don't like it).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
325
diff
changeset
|
206 |
394fafeb4052
Use viper as config storage (I don't like it).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
325
diff
changeset
|
207 // Search config in home directory with name ".cobra" (without extension). |
394fafeb4052
Use viper as config storage (I don't like it).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
325
diff
changeset
|
208 viper.AddConfigPath(home) |
394fafeb4052
Use viper as config storage (I don't like it).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
325
diff
changeset
|
209 viper.SetConfigName(".gemma") |
394fafeb4052
Use viper as config storage (I don't like it).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
325
diff
changeset
|
210 } |
394fafeb4052
Use viper as config storage (I don't like it).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
325
diff
changeset
|
211 if err := viper.ReadInConfig(); err != nil { |
394fafeb4052
Use viper as config storage (I don't like it).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
325
diff
changeset
|
212 if _, ok := err.(viper.ConfigFileNotFoundError); ok && configFile == "" { |
394fafeb4052
Use viper as config storage (I don't like it).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
325
diff
changeset
|
213 // Don't bother if not found. |
394fafeb4052
Use viper as config storage (I don't like it).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
325
diff
changeset
|
214 return |
394fafeb4052
Use viper as config storage (I don't like it).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
325
diff
changeset
|
215 } |
394fafeb4052
Use viper as config storage (I don't like it).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
325
diff
changeset
|
216 log.Fatalf("Can't read config: %v\n", err) |
394fafeb4052
Use viper as config storage (I don't like it).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
325
diff
changeset
|
217 } |
28
714787accd26
Fetch database connection string parts from configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
218 } |