grim/hgkeeper

c10e152f5523
Use --repos-path to generate on-demand cmdline

So we can avoid special environment case. Also this fixes my installation
as the HGK_REPOS_PATH was not recognized and the default value "repos" without
any absolute path was used.

Reviewed at https://reviews.imfreedom.org/r/2429/
package access
import (
"path/filepath"
"sync"
"github.com/casbin/casbin/v2"
"go.uber.org/zap"
)
var (
enforcer *casbin.Enforcer
enforcerLock sync.Mutex
)
func refreshEnforcer() error {
enforcerLock.Lock()
defer enforcerLock.Unlock()
modelFile := filepath.Join(AdminRepoPath(), modelFilename)
policyFile := filepath.Join(AdminRepoPath(), policyFilename)
zap.S().Debugf("reading model from %q", modelFile)
zap.S().Debugf("reading policy from %q", policyFile)
e, err := casbin.NewEnforcer(modelFile, policyFile)
if err != nil {
zap.S().Errorf("failed to create new enforcer: %v", err)
return err
}
enforcer = e
return nil
}