(ctx context.Context, rep repo.Repository)
| 45 | } |
| 46 | |
| 47 | func (c *policyTargetFlags) policyTargets(ctx context.Context, rep repo.Repository) ([]snapshot.SourceInfo, error) { |
| 48 | if c.global == (len(c.targets) > 0) { |
| 49 | return nil, errors.New("must pass either '--global' or a list of path targets") |
| 50 | } |
| 51 | |
| 52 | if c.global { |
| 53 | return []snapshot.SourceInfo{ |
| 54 | policy.GlobalPolicySourceInfo, |
| 55 | }, nil |
| 56 | } |
| 57 | |
| 58 | var res []snapshot.SourceInfo |
| 59 | |
| 60 | for _, ts := range c.targets { |
| 61 | // try loading policy by its manifest ID |
| 62 | if t, err := policy.GetPolicyByID(ctx, rep, manifest.ID(ts)); err == nil { |
| 63 | res = append(res, t.Target()) |
| 64 | continue |
| 65 | } |
| 66 | |
| 67 | target, err := snapshot.ParseSourceInfo(ts, rep.ClientOptions().Hostname, rep.ClientOptions().Username) |
| 68 | if err != nil { |
| 69 | return nil, errors.Wrapf(err, "unable to parse source info: %q", ts) |
| 70 | } |
| 71 | |
| 72 | res = append(res, target) |
| 73 | } |
| 74 | |
| 75 | return res, nil |
| 76 | } |
no test coverage detected