-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor into middleware and server packages
- Loading branch information
Toby Padilla
committed
Jul 30, 2021
1 parent
7c823a0
commit 4d5e35b
Showing
6 changed files
with
64 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package bubbletea | ||
|
||
import ( | ||
"smoothie/server/middleware" | ||
|
||
tea "github.com/charmbracelet/bubbletea" | ||
"github.com/gliderlabs/ssh" | ||
) | ||
|
||
func Middleware(bth func(ssh.Session) tea.Model, opts ...tea.ProgramOption) middleware.Middleware { | ||
return func(sh ssh.Handler) ssh.Handler { | ||
return func(s ssh.Session) { | ||
m := bth(s) | ||
if m != nil { | ||
opts = append(opts, tea.WithInput(s), tea.WithOutput(s)) | ||
p := tea.NewProgram(m, opts...) | ||
_ = p.Start() | ||
} | ||
sh(s) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package logging | ||
|
||
import ( | ||
"log" | ||
"smoothie/server/middleware" | ||
|
||
"github.com/gliderlabs/ssh" | ||
) | ||
|
||
func Middleware() middleware.Middleware { | ||
return func(sh ssh.Handler) ssh.Handler { | ||
return func(s ssh.Session) { | ||
hpk := s.PublicKey() != nil | ||
log.Printf("%s connect %v %v\n", s.RemoteAddr().String(), hpk, s.Command()) | ||
sh(s) | ||
log.Printf("%s disconnect %v %v\n", s.RemoteAddr().String(), hpk, s.Command()) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package middleware | ||
|
||
import "github.com/gliderlabs/ssh" | ||
|
||
type Middleware func(ssh.Handler) ssh.Handler |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters