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

Method Execute

structural/proxy/main.go:98–114  ·  view source on GitHub ↗

Execute intercepts execution of command, implements authorizing user, validates it and poxing command to real terminal (gopherTerminal) method

(command string)

Source from the content-addressed store, hash-verified

96// Execute intercepts execution of command, implements authorizing user, validates it and
97// poxing command to real terminal (gopherTerminal) method
98func (t *Terminal) Execute(command string) (resp string, err error) {
99 // If user allowed to execute send commands then, for example we can decide which terminal can be used, remote or local etc..
100 // but for example we just creating new instance of terminal,
101 // set current user and send user command to execution in terminal
102 t.gopherTerminal = &GopherTerminal{User: t.currentUser}
103
104 // For example our proxy can log or output intercepted execution... etc
105 fmt.Printf("PROXY: Intercepted execution of user (%s), asked command (%s)\n", t.currentUser, command)
106
107 // Transfer data to original object and execute command
108 if resp, err = t.gopherTerminal.Execute(command); err != nil {
109 err = fmt.Errorf("I know only how to execute commands: say_hi, man")
110 return
111 }
112
113 return
114}
115
116// authorize validates user right to execute commands
117func authorizeUser(user string) (err error) {

Callers 1

mainFunction · 0.95

Calls 1

ExecuteMethod · 0.65

Tested by

no test coverage detected