Merge pull request #631 from skriss/restic-refactor-get-snapshot-id

use pkg/util/exec for running get snapshot id cmd
pull/633/head
Nolan Brubaker 2018-06-29 17:03:46 -04:00 committed by GitHub
commit 39bb3963ee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 7 deletions

View File

@ -18,21 +18,19 @@ package restic
import (
"encoding/json"
"os/exec"
"github.com/pkg/errors"
"github.com/heptio/ark/pkg/util/exec"
)
// GetSnapshotID runs a 'restic snapshots' command to get the ID of the snapshot
// in the specified repo matching the set of provided tags, or an error if a
// unique snapshot cannot be identified.
func GetSnapshotID(repoIdentifier, passwordFile string, tags map[string]string) (string, error) {
output, err := GetSnapshotCommand(repoIdentifier, passwordFile, tags).Cmd().Output()
stdout, stderr, err := exec.RunCommand(GetSnapshotCommand(repoIdentifier, passwordFile, tags).Cmd())
if err != nil {
if exitErr, ok := err.(*exec.ExitError); ok {
return "", errors.Wrapf(err, "error running command, stderr=%s", exitErr.Stderr)
}
return "", errors.Wrap(err, "error running command")
return "", errors.Wrapf(err, "error running command, stderr=%s", stderr)
}
type snapshotID struct {
@ -40,7 +38,7 @@ func GetSnapshotID(repoIdentifier, passwordFile string, tags map[string]string)
}
var snapshots []snapshotID
if err := json.Unmarshal(output, &snapshots); err != nil {
if err := json.Unmarshal([]byte(stdout), &snapshots); err != nil {
return "", errors.Wrap(err, "error unmarshalling restic snapshots result")
}