diff options
author | Runxi Yu <me@runxiyu.org> | 2025-08-17 03:09:52 +0800 |
---|---|---|
committer | Runxi Yu <me@runxiyu.org> | 2025-08-17 03:09:52 +0800 |
commit | 009a6e397651a9540b6c6bb74ef2230eeda9b577 (patch) | |
tree | 0a808670d95aba5804a73a558cc335a49d230aa6 /forged/internal/incoming/hooks/hooks.go | |
parent | Remove HTML templates from main server (diff) | |
download | forge-009a6e397651a9540b6c6bb74ef2230eeda9b577.tar.gz forge-009a6e397651a9540b6c6bb74ef2230eeda9b577.tar.zst forge-009a6e397651a9540b6c6bb74ef2230eeda9b577.zip |
Some mass renaming
Diffstat (limited to 'forged/internal/incoming/hooks/hooks.go')
-rw-r--r-- | forged/internal/incoming/hooks/hooks.go | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/forged/internal/incoming/hooks/hooks.go b/forged/internal/incoming/hooks/hooks.go new file mode 100644 index 0000000..64e1cbe --- /dev/null +++ b/forged/internal/incoming/hooks/hooks.go @@ -0,0 +1,61 @@ +package hooks + +import ( + "fmt" + "net" + + "github.com/gliderlabs/ssh" + "go.lindenii.runxiyu.org/forge/forged/internal/common/cmap" + "go.lindenii.runxiyu.org/forge/forged/internal/common/misc" +) + +type Server struct { + hookMap cmap.Map[string, hookInfo] + socketPath string + executablesPath string +} + +type Config struct { + Socket string `scfg:"socket"` + Execs string `scfg:"execs"` +} + +type hookInfo struct { + session ssh.Session + pubkey string + directAccess bool + repoPath string + userID int + userType string + repoID int + groupPath []string + repoName string + contribReq string +} + +func New(config Config) (pool *Server) { + return &Server{ + socketPath: config.Socket, + executablesPath: config.Execs, + } +} + +func (pool *Server) Run() error { + listener, _, err := misc.ListenUnixSocket(pool.socketPath) + if err != nil { + return fmt.Errorf("listen unix socket for hooks: %w", err) + } + + for { + conn, err := listener.Accept() + if err != nil { + return fmt.Errorf("accept conn: %w", err) + } + + go pool.handleConn(conn) + } +} + +func (pool *Server) handleConn(conn net.Conn) { + panic("TODO: handle hook connection") +} |