From 8e6372ecc27b695086ffa1d81f62e58230cfb1eb Mon Sep 17 00:00:00 2001
From: Chris Seitz <54898870+cseitz@users.noreply.github.com>
Date: Sat, 4 May 2024 12:47:36 -0400
Subject: [PATCH] feat(Keygen&Config): Disabled encryption key generation and
prevented SaveConfig from overwriting config files
---
README.md | 4 ++++
internal/backend.go | 19 ++++++++++---------
internal/config.go | 17 ++++++++++-------
3 files changed, 24 insertions(+), 16 deletions(-)
diff --git a/README.md b/README.md
index e390bc2..53d9452 100644
--- a/README.md
+++ b/README.md
@@ -23,6 +23,10 @@
+### Modifications by cseitz
+
+- Disabled functionality to overwrite config files. You will need to specifiy restic repo keys manually.
+
### 💠Why / What?
Autorestic is a wrapper around the amazing [restic](https://restic.net/). While being amazing the restic cli can be a bit overwhelming and difficult to manage if you have many different locations that you want to backup to multiple locations. This utility is aimed at making this easier 🙂.
diff --git a/internal/backend.go b/internal/backend.go
index 8f1981e..5ac1c82 100644
--- a/internal/backend.go
+++ b/internal/backend.go
@@ -104,16 +104,17 @@ func (b Backend) validate() error {
// Check if key is set in environment
env, _ := b.getEnv()
if _, found := env["RESTIC_PASSWORD"]; !found {
+ return fmt.Errorf(`Backend "%s" has no encryption key. The encryption key is required!"`, b.name)
// No key set in config file or env => generate random key and save file
- key := generateRandomKey()
- b.Key = key
- c := GetConfig()
- tmp := c.Backends[b.name]
- tmp.Key = key
- c.Backends[b.name] = tmp
- if err := c.SaveConfig(); err != nil {
- return err
- }
+ // key := generateRandomKey()
+ // b.Key = key
+ // c := GetConfig()
+ // tmp := c.Backends[b.name]
+ // tmp.Key = key
+ // c.Backends[b.name] = tmp
+ // if err := c.SaveConfig(); err != nil {
+ // return err
+ // }
}
}
env, err := b.getEnv()
diff --git a/internal/config.go b/internal/config.go
index 8479efd..8c657bd 100644
--- a/internal/config.go
+++ b/internal/config.go
@@ -263,16 +263,19 @@ func AddFlagsToCommand(cmd *cobra.Command, backend bool) {
}
func (c *Config) SaveConfig() error {
- file := viper.ConfigFileUsed()
- if err := CopyFile(file, file+".old"); err != nil {
- return err
+ if true {
+ return fmt.Errorf(`Not overwriting config; throwing error`);
}
- colors.Secondary.Println("Saved a backup copy of your file next to the original.")
+ // file := viper.ConfigFileUsed()
+ // if err := CopyFile(file, file+".old"); err != nil {
+ // return err
+ // }
+ // colors.Secondary.Println("Saved a backup copy of your file next to the original.")
- viper.Set("backends", c.Backends)
- viper.Set("locations", c.Locations)
+ // viper.Set("backends", c.Backends)
+ // viper.Set("locations", c.Locations)
- return viper.WriteConfig()
+ // return viper.WriteConfig()
}
func optionToString(option string) string {