LoadEntries returns the set of all ACLs in the repository, using old list as a cache.
(ctx context.Context, rep repo.Repository, old []*Entry)
| 70 | |
| 71 | // LoadEntries returns the set of all ACLs in the repository, using old list as a cache. |
| 72 | func LoadEntries(ctx context.Context, rep repo.Repository, old []*Entry) ([]*Entry, error) { |
| 73 | if rep == nil { |
| 74 | return nil, nil |
| 75 | } |
| 76 | |
| 77 | entries, err := rep.FindManifests(ctx, map[string]string{ |
| 78 | manifest.TypeLabelKey: aclManifestType, |
| 79 | }) |
| 80 | if err != nil { |
| 81 | return nil, errors.Wrap(err, "error listing ACL manifests") |
| 82 | } |
| 83 | |
| 84 | om := map[manifest.ID]*Entry{} |
| 85 | for _, v := range old { |
| 86 | om[v.ManifestID] = v |
| 87 | } |
| 88 | |
| 89 | result := []*Entry{} |
| 90 | |
| 91 | for _, m := range entries { |
| 92 | if o := om[m.ID]; o != nil { |
| 93 | result = append(result, o) |
| 94 | continue |
| 95 | } |
| 96 | |
| 97 | var p Entry |
| 98 | |
| 99 | _, err := rep.GetManifest(ctx, m.ID, &p) |
| 100 | if err != nil { |
| 101 | return nil, errors.Wrapf(err, "error loading ACL manifest %v", m.ID) |
| 102 | } |
| 103 | |
| 104 | p.ManifestID = m.ID |
| 105 | |
| 106 | result = append(result, &p) |
| 107 | } |
| 108 | |
| 109 | return result, nil |
| 110 | } |
| 111 | |
| 112 | // AddACL validates and adds the specified ACL entry to the repository. |
| 113 | func AddACL(ctx context.Context, w repo.RepositoryWriter, e *Entry, overwrite bool) error { |