Skip to content

Commit

Permalink
ask for password if necessary
Browse files Browse the repository at this point in the history
  • Loading branch information
rainu committed Jan 7, 2021
1 parent 5aea567 commit c5bc70d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ go build

## Release History

* 0.2.3
* ask for the password if no one is in the database and no corresponding argument is giving
* 0.2.2
* Fix nil pointer error if there is a glacier job of type != "ArchiveRetrieval"
* Fix nil pointer error if upload failed
Expand Down
13 changes: 6 additions & 7 deletions backup/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ type BackupCreater interface {
type BackupGetter interface {
io.Closer

Download(backupId uint, target string) error
Download(backupId uint, target string, fallbackPassword func() string) error
}

type BackupDeleter interface {
Expand All @@ -42,7 +42,7 @@ type BackupManager interface {
io.Closer

Create(files []string, blacklist []*regexp.Regexp, description, vaultName string) *BackupResult
Download(backupId uint, target string) error
Download(backupId uint, target string, fallbackPassword func() string) error
Delete(backupId uint) error
}

Expand Down Expand Up @@ -208,21 +208,20 @@ func (b *backupManager) updateBackup(result *BackupResult, dbBackupEntity *model
b.dbRepository.UpdateBackup(dbBackupEntity)
}

func (b *backupManager) Download(backupId uint, target string) error {
func (b *backupManager) Download(backupId uint, target string, fallbackPassword func() string) error {
fTarget, err := os.Create(target)
if err != nil {
return errors.Wrap(err, "Could not create target file")
}
defer fTarget.Close()

if err != nil {
return errors.Wrap(err, "Error while initialise download")
}

toDownload := b.dbRepository.GetBackupById(backupId)
if b.password != nil {
toDownload.Password = *b.password
}
if toDownload.Password == "" {
toDownload.Password = fallbackPassword()
}

// glacier -> decrypt -> save as zip
srcCrypt, dstCrypt := io.Pipe()
Expand Down
2 changes: 1 addition & 1 deletion cli/action_get.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func (a *actionGet) Do(cfg *config.Config) {
defer repo.Close()

if e := repo.GetBackupById(cfg.Get.BackupId); e.ID == cfg.Get.BackupId {
err := b.Download(cfg.Get.BackupId, cfg.Get.File)
err := b.Download(cfg.Get.BackupId, cfg.Get.File, askForPassword)
if err != nil {
LogError("Could not download backup. Error: %v", err)
} else {
Expand Down

0 comments on commit c5bc70d

Please sign in to comment.