summaryrefslogtreecommitdiff
path: root/config
diff options
context:
space:
mode:
Diffstat (limited to 'config')
-rw-r--r--config/client.go11
-rw-r--r--config/common.go42
-rw-r--r--config/config.go72
-rw-r--r--config/server.go66
4 files changed, 191 insertions, 0 deletions
diff --git a/config/client.go b/config/client.go
new file mode 100644
index 0000000..1515aae
--- /dev/null
+++ b/config/client.go
@@ -0,0 +1,11 @@
+package config
+
+// ClientConfig represents a DTail client configuration (empty as of now as there
+// are no available config options yet, but that may changes in the future).
+type ClientConfig struct {
+}
+
+// Create a new default client configuration.
+func newDefaultClientConfig() *ClientConfig {
+ return &ClientConfig{}
+}
diff --git a/config/common.go b/config/common.go
new file mode 100644
index 0000000..8c07710
--- /dev/null
+++ b/config/common.go
@@ -0,0 +1,42 @@
+package config
+
+// CommonConfig stores configuration keys shared by DTail server and client.
+type CommonConfig struct {
+ // The SSH server port number.
+ SSHPort int
+ // Enable experimental features.
+ ExperimentalFeaturesEnable bool `json:",omitempty"`
+ // Enable extra debug logging (used for deevlopment or debugging purpes only).
+ DebugEnable bool `json:",omitempty"`
+ // Enable extra trace logging (used for deevlopment or debugging purpes only).
+ TraceEnable bool `json:",omitempty"`
+ // The log strategy to use, one of
+ // stdout: only log to stdout (useful when used with systemd)
+ // daily: create a log file for every day
+ LogStrategy string
+ // The log directory
+ LogDir string
+ // The cache directory
+ CacheDir string
+ // Do we want to enable pperf http server?
+ PProfEnable bool `json:",omitempty"`
+ // The HTTP port used by PProf
+ PProfPort int `json:",omitempty"`
+ // The PProf HTTP server bind address
+ PProfBindAddress string `json:",omitempty"`
+}
+
+// Create a new default configuration.
+func newDefaultCommonConfig() *CommonConfig {
+ return &CommonConfig{
+ SSHPort: 2222,
+ DebugEnable: false,
+ TraceEnable: false,
+ ExperimentalFeaturesEnable: false,
+ LogDir: "log",
+ CacheDir: "cache",
+ PProfEnable: false,
+ PProfPort: 6060,
+ PProfBindAddress: "0.0.0.0",
+ }
+}
diff --git a/config/config.go b/config/config.go
new file mode 100644
index 0000000..5463c5f
--- /dev/null
+++ b/config/config.go
@@ -0,0 +1,72 @@
+package config
+
+import (
+ "encoding/json"
+ "io/ioutil"
+ "os"
+)
+
+// ControlUser is used for various DTail specific operations.
+const ControlUser string = "DTAIL-CONTROL-USER"
+
+// Client holds a DTail client configuration.
+var Client *ClientConfig
+
+// Server holds a DTail server configuration.
+var Server *ServerConfig
+
+// Common holds common configs of both both, client and server.
+var Common *CommonConfig
+
+// Used to initialize the configuration.
+type configInitializer struct {
+ Common *CommonConfig
+ Server *ServerConfig
+ Client *ClientConfig
+}
+
+// Parse and read a given config file in JSON format.
+func (c *configInitializer) parseConfig(configFile string) {
+ fd, err := os.Open(configFile)
+ if err != nil {
+ panic(err)
+ }
+ defer fd.Close()
+
+ cfgBytes, err := ioutil.ReadAll(fd)
+ if err != nil {
+ panic(err)
+ }
+
+ err = json.Unmarshal([]byte(cfgBytes), c)
+ if err != nil {
+ panic(err)
+ }
+}
+
+// Init the DTail configuration.
+func Init(configFile string) {
+ initializer := configInitializer{
+ Common: newDefaultCommonConfig(),
+ Server: newDefaultServerConfig(),
+ Client: newDefaultClientConfig(),
+ }
+
+ if configFile == "" {
+ configFile = "./cfg/dtail.json"
+ }
+
+ if _, err := os.Stat(configFile); !os.IsNotExist(err) {
+ initializer.parseConfig(configFile)
+ }
+
+ // Assign pointers to global variables, so that we can access the
+ // configuration from any place of the program.
+ Common = initializer.Common
+ Server = initializer.Server
+ Client = initializer.Client
+
+ if Server.MapreduceLogFormat == "" {
+ Server.MapreduceLogFormat = "default"
+ }
+}
diff --git a/config/server.go b/config/server.go
new file mode 100644
index 0000000..7883b33
--- /dev/null
+++ b/config/server.go
@@ -0,0 +1,66 @@
+package config
+
+import (
+ "errors"
+)
+
+// Permissions map. Each SSH user has a list of permissions which
+// log files it is allowed to follow and which ones not.
+type Permissions struct {
+ // The default user permissions.
+ Default []string
+ // The per user special permissions.
+ Users map[string][]string
+}
+
+// ServerConfig represents the server configuration.
+type ServerConfig struct {
+ // The SSH server bind port.
+ SSHBindAddress string
+ // The max amount of concurrent user connection allowed to connect to the server.
+ MaxConnections int
+ // The max amount of concurrent cats per server.
+ MaxConcurrentCats int
+ // The max amount of concurrent tails per server.
+ MaxConcurrentTails int
+ // The user permissions.
+ Permissions Permissions `json:",omitempty"`
+ // The mapr log format
+ MapreduceLogFormat string `json:",omitempty"`
+ // The default path of the server host key
+ HostKeyFile string
+ // The host key size in bits
+ HostKeyBits int
+}
+
+// Create a new default server configuration.
+func newDefaultServerConfig() *ServerConfig {
+ defaultPermissions := []string{"^/.*"}
+ defaultBindAddress := "0.0.0.0"
+
+ return &ServerConfig{
+ SSHBindAddress: defaultBindAddress,
+ MaxConnections: 10,
+ MaxConcurrentCats: 2,
+ MaxConcurrentTails: 50,
+ HostKeyFile: "./cache/ssh_host_key",
+ HostKeyBits: 4096,
+ Permissions: Permissions{
+ Default: defaultPermissions,
+ },
+ }
+}
+
+// ServerUserPermissions retrieves the permission set of a given user.
+func ServerUserPermissions(userName string) (permissions []string, err error) {
+ permissions = Server.Permissions.Default
+ if p, ok := Server.Permissions.Users[userName]; ok {
+ permissions = p
+ }
+
+ if len(permissions) == 0 {
+ err = errors.New("Empty set of permission, user won't be able to open any files")
+ }
+
+ return
+}