|
|
@ -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)
|
|
|
|
|
|
|
|
if b.Key != "" {
|
|
|
|
env["RESTIC_PASSWORD"] = 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,6 +103,9 @@ 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 == "" {
|
|
|
|
|
|
|
|
// Check if key is set in environment
|
|
|
|
|
|
|
|
if _, err := b.getKey(); err != nil {
|
|
|
|
|
|
|
|
// If not generate a new one
|
|
|
|
key := generateRandomKey()
|
|
|
|
key := generateRandomKey()
|
|
|
|
b.Key = key
|
|
|
|
b.Key = key
|
|
|
|
c := GetConfig()
|
|
|
|
c := GetConfig()
|
|
|
@ -95,6 +116,7 @@ func (b Backend) validate() error {
|
|
|
|
return err
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
env, err := b.getEnv()
|
|
|
|
env, err := b.getEnv()
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
return err
|
|
|
|