forked from pydio/cells
-
Notifications
You must be signed in to change notification settings - Fork 0
/
admin.go
68 lines (53 loc) · 2.01 KB
/
admin.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
package cmd
import (
"strings"
"github.com/pydio/cells/discovery/nats"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
"github.com/spf13/viper"
)
// AdminCmd groups the data manipulation commands
// The sub-commands are connecting via gRPC to a **running** Cells instance.
var AdminCmd = &cobra.Command{
Use: "admin",
Short: "Direct Read/Write access to Cells data",
Long: `
DESCRIPTION
Admin commands allow direct access to Cells data.
These commands require a running Cells instance. They connect directly to low-level services
using gRPC connections. They are not authenticated.
`,
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
replaceKeys := map[string]string{}
cmd.Flags().VisitAll(func(flag *pflag.Flag) {
key := flag.Name
if replace, ok := replaceKeys[flag.Name]; ok {
key = replace
}
flag.Usage += " [" + strings.ToUpper("$"+EnvPrefixNew+"_"+key) + "]"
viper.BindPFlag(key, flag)
})
nats.Init()
// Initialise the default registry
handleRegistry()
// Initialise the default broker
handleBroker()
// Initialise the default transport
handleTransport()
return nil
},
Run: func(cmd *cobra.Command, args []string) {
cmd.Help()
},
}
func init() {
AdminCmd.PersistentFlags().String("registry", "nats", "Registry used to manage services (currently nats only)")
AdminCmd.PersistentFlags().String("registry_address", ":4222", "Registry connection address")
AdminCmd.PersistentFlags().String("registry_cluster_address", "", "Registry cluster address")
AdminCmd.PersistentFlags().String("registry_cluster_routes", "", "Registry cluster routes")
AdminCmd.PersistentFlags().String("broker", "nats", "Pub/sub service for events between services (currently nats only)")
AdminCmd.PersistentFlags().String("broker_address", ":4222", "Broker port")
AdminCmd.PersistentFlags().String("transport", "grpc", "Transport protocol for RPC")
AdminCmd.PersistentFlags().String("transport_address", ":4222", "Transport protocol port")
RootCmd.AddCommand(AdminCmd)
}