mirror of
https://github.com/garethgeorge/backrest.git
synced 2026-08-23 09:26:31 +00:00
fix: use addrepo RPC to apply validations when updating repo config
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user