-
Notifications
You must be signed in to change notification settings - Fork 167
/
admin-config-check.go
84 lines (75 loc) · 2.55 KB
/
admin-config-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
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
/*
* Copyright (c) 2019-2022. Abstrium SAS <team (at) pydio.com>
* This file is part of Pydio Cells.
*
* Pydio Cells is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Pydio Cells 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Pydio Cells. If not, see <http://www.gnu.org/licenses/>.
*
* The latest code can be found at <https://pydio.com>.
*/
package cmd
import (
"github.com/manifoldco/promptui"
"github.com/pydio/cells/v4/common/config"
"github.com/pydio/cells/v4/common/runtime"
"github.com/spf13/cobra"
"os"
"strings"
)
var (
configCheckURL string
)
// delConfigCmd deletes a configuration
var copyConfigCheck = &cobra.Command{
Use: "check",
Short: "Check if a valid config is found",
Long: `
DESCRIPTION
Use this command to automatically detect if config is already set and valid.
By default it points the URL provided by the **global** --config flag.
You can override this with the --conf to specify a config not currently used by Cells.
EXAMPLE
Check if an etcd config is prepared
$ ` + os.Args[0] + ` admin config check --config etcd://:2379/
`,
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
// Replace admin PersistentPreRunE
bindViperFlags(cmd.Flags())
return nil
},
Run: func(cmd *cobra.Command, args []string) {
if configCheckURL == "" {
configCheckURL = runtime.ConfigURL()
}
if strings.Contains(configCheckURL, "?") {
configCheckURL += "&readOnly=true"
} else {
configCheckURL += "?readOnly=true"
}
cmd.Println("Checking config at " + configCheckURL)
s, e := config.OpenStore(ctx, configCheckURL)
if e != nil {
cmd.Println(promptui.IconBad + " Cannot open config: " + e.Error())
os.Exit(1)
}
if s.Val("defaults", "datasource").String() == "" {
cmd.Println(promptui.IconBad + " No default datasource found")
os.Exit(1)
}
cmd.Println(promptui.IconGood + " Default datasource set. A config process has already been performed.")
},
}
func init() {
copyConfigCheck.Flags().StringVar(&configCheckURL, "conf", "", "Alternative config URL (overrides global flag)")
ConfigCmd.AddCommand(copyConfigCheck)
}