aboutsummaryrefslogtreecommitdiff
path: root/internal/admin/service.go
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--internal/admin/service.go37
1 files changed, 37 insertions, 0 deletions
diff --git a/internal/admin/service.go b/internal/admin/service.go
new file mode 100644
index 0000000..c09ad66
--- /dev/null
+++ b/internal/admin/service.go
@@ -0,0 +1,37 @@
+package admin
+
+import (
+ "log"
+
+ casbin "github.com/casbin/casbin/v2"
+)
+
+// Servicer container for dependencies and functions
+type Servicer struct {
+ *casbin.SyncedEnforcer
+ Conf *ServerRepos
+}
+
+// InitServer initialize a git server and configure
+func (s *Servicer) InitServer() {
+ policies := s.Conf.ServerPolicies()
+ s.AddPolicies(policies)
+ s.SavePolicy()
+ s.LoadPolicy()
+ s.Conf.ServerPolicies()
+}
+
+// NewService create a new admin service, load config, and generate policies
+func NewService(modelPath, policyPath, serverConfigPath string) *Servicer {
+ enf, err := casbin.NewSyncedEnforcer(modelPath, policyPath)
+ if err != nil {
+ log.Fatalf("Couldn't load the enforcer encountered the following error: %s", err)
+ }
+ conf := loadServerConfig(serverConfigPath)
+ svc := &Servicer{
+ enf,
+ conf,
+ }
+ svc.InitServer()
+ return svc
+}