MCPcopy
hub / github.com/tmrts/go-patterns / NewTerminal

Function NewTerminal

structural/proxy/main.go:77–94  ·  view source on GitHub ↗

NewTerminal creates new instance of terminal

(user string)

Source from the content-addressed store, hash-verified

75
76// NewTerminal creates new instance of terminal
77func 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

Callers 1

mainFunction · 0.85

Calls 1

authorizeUserFunction · 0.85

Tested by

no test coverage detected