fix: use addrepo RPC to apply validations when updating repo config

This commit is contained in:
garethgeorge
2024-08-14 17:44:26 -07:00
parent 48626b923e
commit a67c29b57a
2 changed files with 11 additions and 10 deletions
+9 -1
View File
@@ -9,6 +9,7 @@ import (
"os"
"path"
"reflect"
"slices"
"time"
"connectrpc.com/connect"
@@ -99,8 +100,15 @@ func (s *BackrestHandler) AddRepo(ctx context.Context, req *connect.Request[v1.R
return nil, fmt.Errorf("failed to get config: %w", err)
}
// Deep copy the configuration
c = proto.Clone(c).(*v1.Config)
c.Repos = append(c.Repos, req.Msg)
// Add or implicit update the repo
if idx := slices.IndexFunc(c.Repos, func(r *v1.Repo) bool { return r.Id == req.Msg.Id }); idx != -1 {
c.Repos[idx] = req.Msg
} else {
c.Repos = append(c.Repos, req.Msg)
}
if err := config.ValidateConfig(c); err != nil {
return nil, fmt.Errorf("validation error: %w", err)
+2 -9
View File
@@ -106,15 +106,8 @@ export const AddRepoModal = ({ template }: { template: Repo | null }) => {
});
if (template !== null) {
const configCopy = config.clone();
// We are in the edit repo flow, update the repo in the config
const idx = configCopy.repos!.findIndex((r) => r.id === template!.id);
if (idx === -1) {
alertsApi.error("Can't update repo, not found");
return;
}
configCopy.repos![idx] = repo;
setConfig(await backrestService.setConfig(configCopy));
// We are in the update repo flow, update the repo via the service
setConfig(await backrestService.addRepo(repo));
showModal(null);
alertsApi.success("Updated repo configuration " + repo.uri);
} else {