|
|
@ -58,7 +58,15 @@ func (b Backend) generateRepo() (string, error) {
|
|
|
|
|
|
|
|
|
|
|
|
func (b Backend) getEnv() (map[string]string, error) {
|
|
|
|
func (b Backend) getEnv() (map[string]string, error) {
|
|
|
|
env := make(map[string]string)
|
|
|
|
env := make(map[string]string)
|
|
|
|
env["RESTIC_PASSWORD"] = b.Key
|
|
|
|
if b.Key != "" {
|
|
|
|
|
|
|
|
env["RESTIC_PASSWORD"] = b.Key
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
key, err := b.getKey()
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
return nil, err
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
env["RESTIC_PASSWORD"] = key
|
|
|
|
|
|
|
|
}
|
|
|
|
repo, err := b.generateRepo()
|
|
|
|
repo, err := b.generateRepo()
|
|
|
|
env["RESTIC_REPOSITORY"] = repo
|
|
|
|
env["RESTIC_REPOSITORY"] = repo
|
|
|
|
for key, value := range b.Env {
|
|
|
|
for key, value := range b.Env {
|
|
|
@ -77,6 +85,16 @@ func generateRandomKey() string {
|
|
|
|
return key
|
|
|
|
return key
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (b Backend) getKey() (string, error) {
|
|
|
|
|
|
|
|
if b.Key != "" {
|
|
|
|
|
|
|
|
return b.Key, nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if key, found := os.LookupEnv("AUTORESTIC_KEY_" + strings.ToUpper(b.name)); found {
|
|
|
|
|
|
|
|
return key, nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return "", fmt.Errorf("no key found for backend \"%s\"", b.name)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (b Backend) validate() error {
|
|
|
|
func (b Backend) validate() error {
|
|
|
|
if b.Type == "" {
|
|
|
|
if b.Type == "" {
|
|
|
|
return fmt.Errorf(`Backend "%s" has no "type"`, b.name)
|
|
|
|
return fmt.Errorf(`Backend "%s" has no "type"`, b.name)
|
|
|
@ -85,14 +103,18 @@ func (b Backend) validate() error {
|
|
|
|
return fmt.Errorf(`Backend "%s" has no "path"`, b.name)
|
|
|
|
return fmt.Errorf(`Backend "%s" has no "path"`, b.name)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if b.Key == "" {
|
|
|
|
if b.Key == "" {
|
|
|
|
key := generateRandomKey()
|
|
|
|
// Check if key is set in environment
|
|
|
|
b.Key = key
|
|
|
|
if _, err := b.getKey(); err != nil {
|
|
|
|
c := GetConfig()
|
|
|
|
// If not generate a new one
|
|
|
|
tmp := c.Backends[b.name]
|
|
|
|
key := generateRandomKey()
|
|
|
|
tmp.Key = key
|
|
|
|
b.Key = key
|
|
|
|
c.Backends[b.name] = tmp
|
|
|
|
c := GetConfig()
|
|
|
|
if err := c.SaveConfig(); err != nil {
|
|
|
|
tmp := c.Backends[b.name]
|
|
|
|
return err
|
|
|
|
tmp.Key = key
|
|
|
|
|
|
|
|
c.Backends[b.name] = tmp
|
|
|
|
|
|
|
|
if err := c.SaveConfig(); err != nil {
|
|
|
|
|
|
|
|
return err
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
env, err := b.getEnv()
|
|
|
|
env, err := b.getEnv()
|
|
|
|