FindSequence finds a sequence-forming assertion based the given
headers. Provided headers must contain a prefix of the primary key
for the assertion type except for the sequence header.
Th assertion is the first in the sequence under the prefix with
sequential number > after.
If after is -1 it returns instead the assertion with the largest
sequential number.
This will allow to hand out system-user assertions limited to a
limited set of serial assertions.
Implements the spec in https://forum.snapcraft.io/t/18163
This is a list of headers which are about the assertion specifically and can be
omitted in some contexts when outputting headers from an assertion.
Signed-off-by: Ian Johnson <ian.johnson@canonical.com>
This converts the singleton asserts.ErrNotFound to a richer asserts.NotFoundError struct carrying Type and optionally PrimaryKey, similar to store.AssertionNotFoundError which then gets folded with this.
This means code doesn't have to worry anymore which is which or to convert between the two. And when possible there is more information around. Though Backstores can continue to return minimal information (Type but not Headers in the new error).
A helper asserts.IsNotFound is also added to cover the simple old ==/!= asserts.ErrNotFound needs.
This also fixes/adjust some error handling to usually not repeat the richer information twice.
asserts: introduce NewDecoderWithTypeMaxBodySize
NewDecoderWithTypeMaxBodySize allow to create an assertion stream Decoder that is configured with optional per-type max body sizes.
This will allow snap-repair to control what size of repair scripts/bodies is happy to accept.