summaryrefslogtreecommitdiff
path: root/config
diff options
context:
space:
mode:
authorPaul Bütow <pbuetow@mimecast.com>2020-01-20 18:41:05 +0000
committerPaul Bütow <pbuetow@mimecast.com>2020-01-21 14:35:23 +0000
commitc128865c4c7411c29a59fca9a3a2f95537686d7b (patch)
tree193bccc70d942c8b70cc93fae2670263701e43aa /config
parent3755a9911ecb05886577095f2b8cc8b9e4066a3a (diff)
Move commands to cmd/ and move internal dependencies to internal/
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, 0 insertions, 191 deletions
diff --git a/config/client.go b/config/client.go
deleted file mode 100644
index 1515aae..0000000
--- a/config/client.go
+++ /dev/null
@@ -1,11 +0,0 @@
-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
deleted file mode 100644
index 8c07710..0000000
--- a/config/common.go
+++ /dev/null
@@ -1,42 +0,0 @@
-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
deleted file mode 100644
index 5463c5f..0000000
--- a/config/config.go
+++ /dev/null
@@ -1,72 +0,0 @@
-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
deleted file mode 100644
index 7883b33..0000000
--- a/config/server.go
+++ /dev/null
@@ -1,66 +0,0 @@
-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
-}