diff options
author | Runxi Yu <me@runxiyu.org> | 2025-08-14 09:30:08 +0800 |
---|---|---|
committer | Runxi Yu <me@runxiyu.org> | 2025-08-14 09:30:08 +0800 |
commit | b48037f4dc602bd35b38c9cba0f50dd0f8033288 (patch) | |
tree | af254558fad42e989b7c4253ad0e9f585a357df9 /forged/internal/hooki | |
parent | Revamp placement of package docstrings (diff) | |
download | forge-b48037f4dc602bd35b38c9cba0f50dd0f8033288.tar.gz forge-b48037f4dc602bd35b38c9cba0f50dd0f8033288.tar.zst forge-b48037f4dc602bd35b38c9cba0f50dd0f8033288.zip |
Refactoringrefactor
Diffstat (limited to 'forged/internal/hooki')
-rw-r--r-- | forged/internal/hooki/hooki.go | 45 |
1 files changed, 42 insertions, 3 deletions
diff --git a/forged/internal/hooki/hooki.go b/forged/internal/hooki/hooki.go index ae26846..8e75bae 100644 --- a/forged/internal/hooki/hooki.go +++ b/forged/internal/hooki/hooki.go @@ -1,13 +1,26 @@ package hooki import ( - "go.lindenii.runxiyu.org/forge/forged/internal/cmap" + "fmt" + "net" + "github.com/gliderlabs/ssh" + "go.lindenii.runxiyu.org/forge/forged/internal/cmap" + "go.lindenii.runxiyu.org/forge/forged/internal/misc" ) -type Pool cmap.Map[string, hookinfo] +type Pool struct { + hookMap cmap.Map[string, hookInfo] + socketPath string + executablesPath string +} -type hookinfo struct { +type Config struct { + Socket string `scfg:"socket"` + Execs string `scfg:"execs"` +} + +type hookInfo struct { session ssh.Session pubkey string directAccess bool @@ -19,3 +32,29 @@ type hookinfo struct { repoName string contribReq string } + +func New(config Config) (pool Pool) { + pool.socketPath = config.Socket + pool.executablesPath = config.Execs + return +} + +func (pool *Pool) 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 *Pool) handleConn(conn net.Conn) { + panic("TODO: handle hook connection") +} |