Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add ssh commands back #370

Merged
merged 2 commits into from
Aug 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ require (
github.com/charmbracelet/git-lfs-transfer v0.1.1-0.20230725143853-5dd0632f9245
github.com/charmbracelet/keygen v0.4.3
github.com/charmbracelet/log v0.2.3
github.com/charmbracelet/ssh v0.0.0-20230720143903-5bdd92839155
github.com/charmbracelet/ssh v0.0.0-20230822194956-1a051f898e09
github.com/go-jose/go-jose/v3 v3.0.0
github.com/gobwas/glob v0.2.3
github.com/gogs/git-module v1.8.2
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ github.com/charmbracelet/log v0.2.3 h1:YVmBhJtpGL7nW/nlf5u+SEloU8XYljxozGzZpgwIv
github.com/charmbracelet/log v0.2.3/go.mod h1:ZApwwzDbbETVTIRTk7724yQRJAXIktt98yGVMMaa3y8=
github.com/charmbracelet/ssh v0.0.0-20230720143903-5bdd92839155 h1:vJqYhlL0doAWQPz+EX/hK5x/ZYguoua773oRz77zYKo=
github.com/charmbracelet/ssh v0.0.0-20230720143903-5bdd92839155/go.mod h1:F1vgddWsb/Yr/OZilFeRZEh5sE/qU0Dt1mKkmke6Zvg=
github.com/charmbracelet/ssh v0.0.0-20230822194956-1a051f898e09 h1:ZDIQmTtohv0S/AAYE//w8mYTxCzqphhF1+4ACPDMiLU=
github.com/charmbracelet/ssh v0.0.0-20230822194956-1a051f898e09/go.mod h1:F1vgddWsb/Yr/OZilFeRZEh5sE/qU0Dt1mKkmke6Zvg=
github.com/charmbracelet/wish v1.1.1 h1:KdICASKd2oh2JPvk1Z4CJtAi97cFErXF7NKienPICO4=
github.com/charmbracelet/wish v1.1.1/go.mod h1:xh4KZpSULw+Xqb9bcbhw92QAinVB75CVLWrFuyY6IVs=
github.com/containerd/console v1.0.4-0.20230313162750-1ae8d489ac81 h1:q2hJAaP1k2wIvVRd/hEHD7lacgqrCPS+k8g1MndzfWY=
Expand Down
26 changes: 7 additions & 19 deletions server/ssh/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,13 @@
cmd.GitUploadArchiveCommand(),
cmd.GitReceivePackCommand(),
cmd.RepoCommand(),
cmd.SettingsCommand(),
cmd.UserCommand(),
cmd.InfoCommand(),
cmd.PubkeyCommand(),
cmd.SetUsernameCommand(),
cmd.JWTCommand(),
cmd.TokenCommand(),
)

if cfg.LFS.Enabled {
Expand All @@ -84,33 +91,14 @@

rootCmd.SetArgs(args)
if len(args) == 0 {
// otherwise it'll default to os.Args, which is not what we want.
rootCmd.SetArgs([]string{"--help"})
}

Check warning on line 96 in server/ssh/middleware.go

View check run for this annotation

Codecov / codecov/patch

server/ssh/middleware.go#L94-L96

Added lines #L94 - L96 were not covered by tests
rootCmd.SetIn(s)
rootCmd.SetOut(s)
rootCmd.SetErr(s.Stderr())
rootCmd.SetContext(ctx)

user := proto.UserFromContext(ctx)
isAdmin := cmd.IsPublicKeyAdmin(cfg, s.PublicKey()) || (user != nil && user.IsAdmin())
if user != nil || isAdmin {
if isAdmin {
rootCmd.AddCommand(
cmd.SettingsCommand(),
cmd.UserCommand(),
)
}

rootCmd.AddCommand(
cmd.InfoCommand(),
cmd.PubkeyCommand(),
cmd.SetUsernameCommand(),
cmd.JWTCommand(),
cmd.TokenCommand(),
)
}

if err := rootCmd.ExecuteContext(ctx); err != nil {
s.Exit(1) // nolint: errcheck
return
Expand Down Expand Up @@ -145,19 +133,19 @@
}

if isPty {
logArgs = []interface{}{
"term", ptyReq.Term,
"width", ptyReq.Window.Width,
"height", ptyReq.Window.Height,
}
}

Check warning on line 141 in server/ssh/middleware.go

View check run for this annotation

Codecov / codecov/patch

server/ssh/middleware.go#L136-L141

Added lines #L136 - L141 were not covered by tests

if config.IsVerbose() {
logArgs = append(logArgs,
"key", hpk,
"envs", s.Environ(),
)
}

Check warning on line 148 in server/ssh/middleware.go

View check run for this annotation

Codecov / codecov/patch

server/ssh/middleware.go#L144-L148

Added lines #L144 - L148 were not covered by tests

msg := fmt.Sprintf("user %q", s.User())
logger.Debug(msg+" connected", logArgs...)
Expand Down
Loading