Home

ugit @4731c0bd3502b9a7317f412c0ee3325a3b0ea457 - refs - log -
-
https://git.jolheiser.com/ugit.git
The code powering this h*ckin' site
ugit / internal / ssh / ssh.go
- raw
 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
package ssh

import (
	"fmt"

	"github.com/charmbracelet/ssh"
	"github.com/charmbracelet/wish"
	"github.com/charmbracelet/wish/git"
	"github.com/charmbracelet/wish/logging"
)

func New() (*ssh.Server, error) {
	s, err := wish.NewServer(
		wish.WithAuthorizedKeys(".ssh/authorized_keys"),
		wish.WithAddress("localhost:8448"),
		wish.WithHostKeyPath(".ssh/ugit_ed25519"),
		wish.WithMiddleware(
			git.Middleware(".ugit", app{}),
			logging.Middleware(),
		),
	)
	if err != nil {
		return nil, fmt.Errorf("could not create new SSH server: %w", err)
	}

	return s, nil
}

type app struct{}

func (a app) AuthRepo(repo string, pk ssh.PublicKey) git.AccessLevel {
	return git.ReadWriteAccess
}
func (a app) Push(_ string, _ ssh.PublicKey)  {}
func (a app) Fetch(_ string, _ ssh.PublicKey) {}