Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Start to build up a mutate package. #729

Merged
merged 2 commits into from
Sep 20, 2021
Merged

Start to build up a mutate package. #729

merged 2 commits into from
Sep 20, 2021

Conversation

mattmoor
Copy link
Member

This is not yet used, but start to lay out some useful utilities for walking over and manipulating Images and Indices.

The first bit is mutate.AppendManifests, which builds around the utility with the same name in GGCR. This utility produces an oci.SignedImageIndex, where (because of the mutation) the signatures are necessarily empty, but which provides access to the signatures of the entities contained within it. This was mostly useful for constructing images for tests.

The second bit is mutate.Map, which surfaces a way to apply a Mutator function to the oci.SignedEntitys contained within a particular oci.SignedEntity. Notable features:

  • Mutators can control whether they descend into the children of indices (useful for recursive signing or signature verification).
  • Mutators can filter entities by returning nil without error.
  • Mutators are called before and (if changed) after its children are walked, which is detectable via helpers on ctx.
  • Mutators can return their input entity if they are just a simple readonly walk.

Signed-off-by: Matt Moore [email protected]

Ticket Link

Related: #666

Release Note

NONE

This is not yet used, but start to lay out some useful utilities for walking over and manipulating Images and Indices.

The first bit is `mutate.AppendManifests`, which builds around the utility with the same name in GGCR.  This utility produces an `oci.SignedImageIndex`, where (because of the mutation) the signatures are necessarily empty, but which provides access to the signatures of the entities contained within it.  This was mostly useful for constructing images for tests.

The second bit is `mutate.Map`, which surfaces a way to apply a `Mutator` function to the `oci.SignedEntity`s contained within a particular `oci.SignedEntity`.  Notable features:
 * `Mutator`s can control whether they descend into the children of indices (useful for recursive signing or signature verification).
 * `Mutator`s can filter entities by returning `nil` without `error`.
 * `Mutator`s are called before and (if changed) after its children are walked, which is detectable via helpers on `ctx`.
 * `Mutator`s can return their input entity if they are just a simple readonly walk.

Signed-off-by: Matt Moore <[email protected]>
internal/oci/mutate/mutate.go Outdated Show resolved Hide resolved

// before decorates the context such that IsBeforeChildren(ctx) is true.
func before(ctx context.Context) context.Context {
return context.WithValue(ctx, mapPassKey{}, "before")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

turn "before" and "after" into consts and/or enums?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was going to say "but I'll just call them before/after", but I can't because that's what the methods are called. 🙃

Given the proximity of the functions, and the tests to make sure they agree, I'm sort of inclined to leave it 😅

internal/oci/mutate/map.go Outdated Show resolved Hide resolved
@mattmoor mattmoor merged commit 8790771 into sigstore:main Sep 20, 2021
@mattmoor mattmoor deleted the map branch September 20, 2021 20:13
@github-actions github-actions bot added this to the v1.3.0 milestone Sep 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants