github.com/databricks/cli@v0.203.0/bundle/mutator.go (about)

     1  package bundle
     2  
     3  import (
     4  	"context"
     5  
     6  	"github.com/databricks/cli/libs/log"
     7  )
     8  
     9  // Mutator is the interface type that mutates a bundle's configuration or internal state.
    10  // This makes every mutation or action observable and debuggable.
    11  type Mutator interface {
    12  	// Name returns the mutators name.
    13  	Name() string
    14  
    15  	// Apply mutates the specified bundle object.
    16  	Apply(context.Context, *Bundle) error
    17  }
    18  
    19  func Apply(ctx context.Context, b *Bundle, m Mutator) error {
    20  	ctx = log.NewContext(ctx, log.GetLogger(ctx).With("mutator", m.Name()))
    21  
    22  	log.Debugf(ctx, "Apply")
    23  	err := m.Apply(ctx, b)
    24  	if err != nil {
    25  		log.Errorf(ctx, "Error: %s", err)
    26  		return err
    27  	}
    28  
    29  	return nil
    30  }