grim/hgkeeper

Parents 383331e5a4fb
Children b6e0150db76d
auto reload the access model and policy if the admin repo is accessed. This does both push and pulls right now.
--- a/access/access.go Thu Sep 12 05:54:15 2019 -0500
+++ b/access/access.go Thu Sep 12 05:55:03 2019 -0500
@@ -1,6 +1,7 @@
package access
import (
+ "path/filepath"
"sync"
)
@@ -10,16 +11,27 @@
)
var (
- accessLock sync.Mutex
+ accessLock sync.Mutex
+
adminRepoPath string
+ adminRepoName string
)
-func Setup(adminRepo string) error {
- adminRepoPath = adminRepo
+func Setup(reposPath, adminRepo string) error {
+ adminRepoName = adminRepo
+ adminRepoPath = filepath.Join(reposPath, adminRepo)
return Refresh()
}
+func AdminRepo() string {
+ return adminRepoName
+}
+
+func AdminRepoPath() string {
+ return adminRepoPath
+}
+
// Refresh will try to reload the casbin model and policies followed by SSH
// keys. If there is an error it's possible that the casbin model and polcies
// could have been updated but the ssh keys were not.
--- a/serve/command.go Thu Sep 12 05:54:15 2019 -0500
+++ b/serve/command.go Thu Sep 12 05:55:03 2019 -0500
@@ -1,8 +1,6 @@
package serve
import (
- "path/filepath"
-
"bitbucket.org/rw_grim/hgkeeper/access"
"bitbucket.org/rw_grim/hgkeeper/globals"
"bitbucket.org/rw_grim/hgkeeper/ssh"
@@ -14,12 +12,11 @@
}
func (c *Command) Run(g *globals.Globals) error {
- adminRepoPath := filepath.Join(g.ReposPath, g.AdminRepo)
- if err := access.Setup(adminRepoPath); err != nil {
+ if err := access.Setup(g.ReposPath, g.AdminRepo); err != nil {
return err
}
- s, err := ssh.NewServer(c.SSHHostKeysPath, g.ReposPath, g.AdminRepo)
+ s, err := ssh.NewServer(c.SSHHostKeysPath, g.ReposPath, access.AdminRepoPath())
if err != nil {
return err
}
--- a/ssh/commands/serve.go Thu Sep 12 05:54:15 2019 -0500
+++ b/ssh/commands/serve.go Thu Sep 12 05:55:03 2019 -0500
@@ -4,6 +4,7 @@
"fmt"
"path/filepath"
+ log "github.com/sirupsen/logrus"
"golang.org/x/crypto/ssh"
"bitbucket.org/rw_grim/hgkeeper/access"
@@ -29,7 +30,17 @@
writeable := access.CanWrite(username, "/"+s.repoName)
- return run(hg.Serve(s.repoPath, writeable), conn, serverConn, req)
+ if err := run(hg.Serve(s.repoPath, writeable), conn, serverConn, req); err != nil {
+ return err
+ }
+
+ if s.repoName == access.AdminRepo() {
+ log.Info("admin repo updated, refreshing access control")
+
+ return access.Refresh()
+ }
+
+ return nil
}
func (s *Serve) String() string {