1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
package ssh
import (
"fmt"
"github.com/charmbracelet/log"
"github.com/charmbracelet/ssh"
"github.com/charmbracelet/wish"
"github.com/charmbracelet/wish/logging"
)
// Settings holds the configuration for the SSH server
type Settings struct {
AuthorizedKeys string
CloneURL string
Port int
HostKey string
RepoDir string
}
// New creates a new SSH server.
func New(settings Settings) (*ssh.Server, error) {
s, err := wish.NewServer(
wish.WithAuthorizedKeys(settings.AuthorizedKeys),
wish.WithAddress(fmt.Sprintf(":%d", settings.Port)),
wish.WithHostKeyPath(settings.HostKey),
wish.WithMiddleware(
Middleware(settings.RepoDir, settings.CloneURL, settings.Port, hooks{}),
logging.MiddlewareWithLogger(DefaultLogger),
),
)
if err != nil {
return nil, fmt.Errorf("could not create new SSH server: %w", err)
}
return s, nil
}
type hooks struct{}
func (a hooks) Push(_ string, _ ssh.PublicKey) {}
func (a hooks) Fetch(_ string, _ ssh.PublicKey) {}
var (
DefaultLogger logging.Logger = log.StandardLog()
NoopLogger logging.Logger = noopLogger{}
)
type noopLogger struct{}
func (n noopLogger) Printf(format string, v ...interface{}) {}
|