NewTerminal creates new instance of terminal
(user string)
| 75 | |
| 76 | // NewTerminal creates new instance of terminal |
| 77 | func NewTerminal(user string) (t *Terminal, err error) { |
| 78 | // Check user if given correctly |
| 79 | if user == "" { |
| 80 | err = fmt.Errorf("User cant be empty") |
| 81 | return |
| 82 | } |
| 83 | |
| 84 | // Before we execute user commands, we validate current user, if he have rights to do it |
| 85 | if authErr := authorizeUser(user); authErr != nil { |
| 86 | err = fmt.Errorf("You (%s) are not allowed to use terminal and execute commands", user) |
| 87 | return |
| 88 | } |
| 89 | |
| 90 | // Create new instance of terminal and set valid user |
| 91 | t = &Terminal{currentUser: user} |
| 92 | |
| 93 | return |
| 94 | } |
| 95 | |
| 96 | // Execute intercepts execution of command, implements authorizing user, validates it and |
| 97 | // poxing command to real terminal (gopherTerminal) method |