aboutsummaryrefslogtreecommitdiff
path: root/forged/internal/hooki/hooki.go
diff options
context:
space:
mode:
Diffstat (limited to 'forged/internal/hooki/hooki.go')
-rw-r--r--forged/internal/hooki/hooki.go60
1 files changed, 60 insertions, 0 deletions
diff --git a/forged/internal/hooki/hooki.go b/forged/internal/hooki/hooki.go
new file mode 100644
index 0000000..8e75bae
--- /dev/null
+++ b/forged/internal/hooki/hooki.go
@@ -0,0 +1,60 @@
+package hooki
+
+import (
+ "fmt"
+ "net"
+
+ "github.com/gliderlabs/ssh"
+ "go.lindenii.runxiyu.org/forge/forged/internal/cmap"
+ "go.lindenii.runxiyu.org/forge/forged/internal/misc"
+)
+
+type Pool 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 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")
+}