Files
kopia/cli/command_policy.go
Jarek Kowalski e3854f7773 BREAKING: changed how hostname/username are handled
The hostname/username are now persisted when connecting to repository
in a local config file.

This prevents weird behavior changes when hostname is suddenly changed,
such as when moving between networks.

repo.Repository will now expose Hostname/Username properties which
are always guarnateed to be set, and are used throughout.

Removed --hostname/--username overrides when taking snapshot et.al.
2020-02-25 20:40:23 -08:00

44 lines
979 B
Go

package cli
import (
"context"
"github.com/pkg/errors"
"github.com/kopia/kopia/repo"
"github.com/kopia/kopia/repo/manifest"
"github.com/kopia/kopia/snapshot"
"github.com/kopia/kopia/snapshot/policy"
)
func policyTargets(ctx context.Context, rep *repo.Repository, globalFlag *bool, targetsFlag *[]string) ([]snapshot.SourceInfo, error) {
if *globalFlag == (len(*targetsFlag) > 0) {
return nil, errors.New("must pass either '--global' or a list of path targets")
}
if *globalFlag {
return []snapshot.SourceInfo{
policy.GlobalPolicySourceInfo,
}, nil
}
var res []snapshot.SourceInfo
for _, ts := range *targetsFlag {
// try loading policy by its manifest ID
if t, err := policy.GetPolicyByID(ctx, rep, manifest.ID(ts)); err == nil {
res = append(res, t.Target())
continue
}
target, err := snapshot.ParseSourceInfo(ts, rep.Hostname, rep.Username)
if err != nil {
return nil, err
}
res = append(res, target)
}
return res, nil
}