Skip to content

Commit

Permalink
add massif options to suppress nonleaf errors when getting massifs
Browse files Browse the repository at this point in the history
  • Loading branch information
jgough committed Jun 5, 2024
1 parent 027fecb commit 927820e
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 3 deletions.
17 changes: 14 additions & 3 deletions logverification/massif.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,21 @@ var (
// Massif gets the massif (blob) that contains the given mmrIndex, from azure blob storage
//
// defined by the azblob configuration.
func Massif(mmrIndex uint64, massifReader massifs.MassifReader, tenantId string, massifHeight uint8) (*massifs.MassifContext, error) {
func Massif(mmrIndex uint64, massifReader massifs.MassifReader, tenantId string, massifHeight uint8, opts ...MassifOption) (*massifs.MassifContext, error) {

massifOptions := ParseMassifOptions(opts...)

massifIndex, err := massifs.MassifIndexFromMMRIndex(massifHeight, mmrIndex)
if err != nil {

// we don't want to suppress NotLeaf error for mmrIndex that are not leaf
// nodes, so just surface any error.
if !massifOptions.nonLeafNode && err != nil {
return nil, err
}

// we want to suppress NotLeaf error for mmrIndexs that are not leaf
// nodes.
if massifOptions.nonLeafNode && !errors.Is(err, massifs.ErrNotleaf) {
return nil, err
}

Expand All @@ -42,7 +53,7 @@ func Massif(mmrIndex uint64, massifReader massifs.MassifReader, tenantId string,
// MassifFromEvent gets the massif (blob) that contains the given event, from azure blob storage
//
// defined by the azblob configuration.
func MassifFromEvent(eventJson []byte, reader azblob.Reader, options ...VerifyOption) (*massifs.MassifContext, error) {
func MassifFromEvent(eventJson []byte, reader azblob.Reader, options ...MassifOption) (*massifs.MassifContext, error) {

verifyOptions := ParseOptions(options...)

Expand Down
33 changes: 33 additions & 0 deletions logverification/massifoptions.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package logverification

type MassifOptions struct {

// nonLeafNode is an optional suppression
//
// of errors that occur due to attempting to get
// a massif based on a non leaf node mmrIndex.
nonLeafNode bool
}

type MassifOption func(*MassifOptions)

// WithNonLeafNode is an optional suppression
//
// of errors that occur due to attempting to get
// a massif based on a non leaf node mmrIndex.
func WithNonLeafNode(nonLeafNode bool) MassifOption {
return func(mo *MassifOptions) { mo.nonLeafNode = nonLeafNode }
}

// ParseMassifOptions parses the given options into a MassifOptions struct
func ParseMassifOptions(options ...MassifOption) MassifOptions {
massifOptions := MassifOptions{
nonLeafNode: false, // default to erroring on non leaf nodes
}

for _, option := range options {
option(&massifOptions)
}

return massifOptions
}

0 comments on commit 927820e

Please sign in to comment.