diff options
Diffstat (limited to 'internal/admin/model.go')
| -rw-r--r-- | internal/admin/model.go | 28 |
1 files changed, 13 insertions, 15 deletions
diff --git a/internal/admin/model.go b/internal/admin/model.go index 8618d69..fef73ca 100644 --- a/internal/admin/model.go +++ b/internal/admin/model.go @@ -7,6 +7,7 @@ import ( "io" "io/fs" "log" + "log/slog" "os" "path/filepath" @@ -103,14 +104,11 @@ func loadFromGit(gitURL, filePath string) ([]byte, error) { URL: gitURL, }) if err != nil { - // log.error - fmt.Printf("couldn't clone mgmt repo %s", err) - return []byte(""), errors.New("couldn't clone mgmt repo") + return []byte(""), fmt.Errorf("couldn't clone mgmt repo %w", err) } file, err := fs.Open(filePath) if err != nil { - fmt.Printf("Failed to open gitserver config %s", err) - return []byte(""), errors.New("couldn't open git config file from mgmt repo") + return []byte(""), fmt.Errorf("couldn't open file in repo %w", err) } defer file.Close() return io.ReadAll(file) @@ -119,14 +117,12 @@ func loadFromGit(gitURL, filePath string) ([]byte, error) { func loadLocalFile(path string) ([]byte, error) { file, err := os.Open(path) if err != nil { - log.Printf("config file not opened %s", path) - return []byte{}, err + return []byte{}, fmt.Errorf("config file not opened or found %w", err) } defer file.Close() configBytes, err := io.ReadAll(file) if err != nil { - log.Print("config file not read") - return []byte{}, err + return []byte{}, fmt.Errorf("config file not read %w", err) } return configBytes, nil } @@ -149,14 +145,14 @@ func loadServerConfig(mgmtRepo bool, baseDir, configPath string) (*ServerRepos, configBytes, err = loadFromGit(repoURI, configPath) if err != nil { // log.error - log.Print("Failed to load config file from git") + slog.Error("Failed to load config file from git", "path", configPath) return &ServerRepos{}, err } } else { configBytes, err = loadLocalFile(configPath) if err != nil { // log.error - log.Print("Failed to load config file from file system") + slog.Error("Local server config couldn't be loaded") return &ServerRepos{}, err } } @@ -178,10 +174,11 @@ func (s *ServerRepos) ServerPolicies() [][]string { } // ConfigureRepos run reconciler for all repos -func (s *ServerRepos) ConfigureRepos() { +func (s *ServerRepos) ConfigureRepos() error { for _, repo := range s.Repos { - repo.ReconcileRepo(s.basePath) + return repo.ReconcileRepo(s.basePath) } + return nil } func readOnlyPaths(role, repoName string) [][]string { @@ -219,7 +216,7 @@ func (r *GitRepo) CasbinPolicies() [][]string { } // ReconcileRepo update repo export settings, update web config -func (r *GitRepo) ReconcileRepo(basePath string) { +func (r *GitRepo) ReconcileRepo(basePath string) error { // if exist -> continue repoBase := filepath.Join(basePath, fmt.Sprintf("%s.git", r.Name)) _, err := os.Stat(repoBase) @@ -237,7 +234,7 @@ func (r *GitRepo) ReconcileRepo(basePath string) { f, err := os.Create(okExport) f.Close() if err != nil { - log.Fatalf("%s couldn't be created %s", GitExportMagic, err) + return fmt.Errorf("%s couldn't be created %w", GitExportMagic, err) } } r.ConfigureExport(repoBase) @@ -245,6 +242,7 @@ func (r *GitRepo) ReconcileRepo(basePath string) { r.GitWebConfig = &GitWeb{} } r.GitWebConfig.ReconcileGitConf(repoBase) + return nil } // ConfigureExport setup repo for sharing and configure web settings |