diff --git a/config/config.go b/config/config.go index 0eb46cc..bf9b746 100644 --- a/config/config.go +++ b/config/config.go @@ -25,7 +25,8 @@ type Server struct { } type Log struct { - Path string `yaml:"path"` + WriteToFile bool `yaml:"write_to_file"` + Path string `yaml:"path"` } type User struct { @@ -38,6 +39,18 @@ func (conf *Config) BasicCheck() error { if len(conf.Users) <= 0 { return errors.New("invalid user length") } + + for _, u := range conf.Users { + allCmds := false + for _, c := range u.Cmds { + if c == "*" { + allCmds = true + } + } + if allCmds && len(u.Cmds) > 1 { + return errors.New("can't have all cmds and specific cmd at same time") + } + } return nil } @@ -48,7 +61,8 @@ func DefaultConfig() *Config { Port: "7070", }, Log: Log{ - Path: "ttrace.log", + WriteToFile: true, + Path: "ttrace.log", }, Name: "time_trace", } diff --git a/config/config.yaml b/config/config.yaml index c55b8c7..4dfaf2a 100644 --- a/config/config.yaml +++ b/config/config.yaml @@ -5,6 +5,7 @@ server: port: "7070" log: + write_to_file: true path: ttrace.log users: @@ -18,10 +19,10 @@ users: # - name: root # password: super_secret_password # cmd: -# - * # all commands. +# - '*' # all commands. # - name: developer # password: secret_password # cmd: -# - GET -# - PUSH -# - DEL \ No newline at end of file +# - 'GET' +# - 'PUSH' +# - 'DEL' \ No newline at end of file diff --git a/config/config_test.go b/config/config_test.go index cf8b40b..928dacb 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -53,4 +53,9 @@ func TestBasicCheck(t *testing.T) { c.Users = []User{} err = c.BasicCheck() assert.Error(t, errors.New("invalid user length"), err) + + c.Users = []User{DefaultConfig().Users[0]} + c.Users[0].Cmds = []string{"*", "GET"} + err = c.BasicCheck() + assert.Error(t, errors.New("can't have all cmds and specific cmd at same time"), err) } diff --git a/doc/config/.keep b/doc/config/.keep deleted file mode 100644 index e69de29..0000000 diff --git a/doc/config/config.md b/doc/config/config.md new file mode 100644 index 0000000..f8c992d --- /dev/null +++ b/doc/config/config.md @@ -0,0 +1,71 @@ +# Config + +In this part of documentation we are going to explain config in ttrace. + +### config file + +In ttrace we have config in `yaml` format, you can see default config example [here](../../config/config.yaml). +Now we explain each part of config one by one. + +#### name + +First of all we have a name, which is name of instance you are running (you can use it on application layer and get it by commands). +This is name field in `config.yaml`: + +```yml +name: time_trace +``` + +#### server + +In server part you can config this two: which ip? which port? for listening and serving the TCP server. + +This is how it looks in `config.yaml`: + +```yml +server: + listen: localhost + port: "7070" +``` + +#### log + +This part will help you to config log stuff (levels, saving path and...). + +How it looks in `config.yaml`: + +```yml +log: + write_to_file: true + path: ttrace.log +``` + +#### users + +In users part, you define who can access the database and set permission for them. `name` and `password` field is user pass for connecting (required in `CON` command). + +In `cmds` you provide which command in [TQL](../TQL/) they have access to. It can be a list of commands or just a `'*'` which means all. +Also the `CON` command is open for everyone. + +example: + +```yml +users: +- name: root + password: super_secret_password + cmds: + - '*' + +# Also you can use this for multiple users and limited commands +# users: +# - name: root +# password: super_secret_password +# cmd: +# - '*' # all commands. +# - name: developer +# password: secret_password +# cmd: +# - 'GET' +# - 'PUSH' +# - 'DEL' +```