ListSources lists all snapshot sources in a given repository.
(ctx context.Context, rep repo.Repository)
| 37 | |
| 38 | // ListSources lists all snapshot sources in a given repository. |
| 39 | func ListSources(ctx context.Context, rep repo.Repository) ([]SourceInfo, error) { |
| 40 | items, err := rep.FindManifests(ctx, map[string]string{ |
| 41 | typeKey: ManifestType, |
| 42 | }) |
| 43 | if err != nil { |
| 44 | return nil, errors.Wrap(err, "unable to find manifest entries") |
| 45 | } |
| 46 | |
| 47 | uniq := map[SourceInfo]bool{} |
| 48 | for _, it := range items { |
| 49 | uniq[sourceInfoFromLabels(it.Labels)] = true |
| 50 | } |
| 51 | |
| 52 | var infos []SourceInfo |
| 53 | for k := range uniq { |
| 54 | infos = append(infos, k) |
| 55 | } |
| 56 | |
| 57 | return infos, nil |
| 58 | } |
| 59 | |
| 60 | func sourceInfoFromLabels(labels map[string]string) SourceInfo { |
| 61 | return SourceInfo{Host: labels[HostnameLabel], UserName: labels[UsernameLabel], Path: labels[PathLabel]} |