/
server-check.go
44 lines (35 loc) · 1.43 KB
/
server-check.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
package cmd
import (
"encoding/json"
"github.com/go-errors/errors"
"github.com/markuskreukniet/irmago-measurements/server/requestorserver"
"github.com/spf13/cobra"
)
var serverCheckCmd = &cobra.Command{
Use: "check",
Short: "Check server configuration correctness",
Long: `check reads the server configuration like the main command does, from a
configuration file, command line flags, or environmental variables, and checks
that the configuration is valid.
Specify -v to see the configuration.`,
Run: func(command *cobra.Command, args []string) {
if err := configureServer(command); err != nil {
die("", errors.WrapPrefix(err, "Failed to read configuration from file, args, or env vars", 0))
}
// Hack: temporarily disable scheme updating to prevent verifyConfiguration() from immediately updating schemes
enabled := conf.DisableSchemesUpdate
conf.DisableSchemesUpdate = true
if _, err := requestorserver.New(conf); err != nil {
die("", errors.WrapPrefix(err, "Invalid configuration", 0))
}
conf.DisableSchemesUpdate = enabled // restore previous value before printing configuration
bts, _ := json.MarshalIndent(conf, "", " ")
conf.Logger.Debug("Configuration: ", string(bts), "\n")
},
}
func init() {
serverCmd.AddCommand(serverCheckCmd)
if err := setFlags(serverCheckCmd, productionMode()); err != nil {
die("", errors.WrapPrefix(err, "Failed to attach flags to "+serverCheckCmd.Name()+" command", 0))
}
}