grim/hgkeeper

Add a caching layer to the hgweb portion. This should take some strain off of mercurial anf our cpu quota
package access
import (
"path/filepath"
"sync"
"github.com/casbin/casbin/v2"
log "github.com/sirupsen/logrus"
)
var (
enforcer *casbin.Enforcer
enforcerLock sync.Mutex
)
func refreshEnforcer(adminRepoPath string) error {
enforcerLock.Lock()
defer enforcerLock.Unlock()
modelFile := filepath.Join(adminRepoPath, modelFilename)
policyFile := filepath.Join(adminRepoPath, policyFilename)
log.Debugf("reading model from %q", modelFile)
log.Debugf("reading policy from %q", policyFile)
e, err := casbin.NewEnforcer(modelFile, policyFile)
if err != nil {
log.Errorf("failed to create new enforcer: %v", err)
return err
}
enforcer = e
return nil
}