github.com/lyraproj/hiera@v1.0.0-rc4/api/invocation.go (about)

     1  package api
     2  
     3  import (
     4  	"github.com/lyraproj/dgo/dgo"
     5  )
     6  
     7  // An Invocation keeps track of one specific lookup invocation implements a guard against
     8  // endless recursion
     9  type Invocation interface {
    10  	Session
    11  
    12  	// Obtain the configuration appointed by the given configPath and moduleName. The configuration is considered
    13  	// global if the moduleName is the empty string. A global configuration can find data and lookup options for
    14  	// data regardless of if the key has a module prefix or not. A module configuration can only find data and lookup
    15  	// options for keys prefixed with the name of the module.
    16  	Config(configPath string, moduleName string) ResolvedConfig
    17  
    18  	// DoWithScope associates the given scope with this invocation and calls the given Doer function. The
    19  	// scope is then restored to what it was before the call.
    20  	DoWithScope(scope dgo.Keyed, doer dgo.Doer)
    21  
    22  	// Call doer and while it is executing, don't reveal any found values in logs
    23  	DoRedacted(doer dgo.Doer)
    24  
    25  	// Interpolate resolves interpolations in the given value and returns the result
    26  	Interpolate(value dgo.Value, allowMethods bool) dgo.Value
    27  
    28  	// InterpolateInScope resolves a key expression in the invocation scope
    29  	InterpolateInScope(expr string, allowMethods bool) dgo.Value
    30  
    31  	// InterpolateString resolves a string containing interpolation expressions
    32  	InterpolateString(str string, allowMethods bool) (dgo.Value, bool)
    33  
    34  	// Lookup performs a lookup using the given options
    35  	Lookup(key Key, options dgo.Map) dgo.Value
    36  
    37  	// LookupAndConvertData checks if the lookupOptions assigned to this invocation with SetMergeStrategy also
    38  	// stipulates that a found value should be converted to a Sensitive. If that is the case, any occurrence of
    39  	// the found value will be redacted in log statements written during the call of the given
    40  	// function.
    41  	//
    42  	// The value will be converted prior to returned if the lookupOptions stipulates
    43  	// it should converted.
    44  	LookupAndConvertData(fn func() dgo.Value) dgo.Value
    45  
    46  	// MergeHierarchy merges the result of performing a lookup usign each of the given
    47  	// data providers
    48  	MergeHierarchy(key Key, providers []DataProvider, merge MergeStrategy) dgo.Value
    49  
    50  	// MergeLocations merges the result of lookups on all locations (or without location) for the
    51  	// given provider and merge options
    52  	MergeLocations(key Key, provider DataProvider, merge MergeStrategy) dgo.Value
    53  
    54  	// ReportText will add the message returned by the given function to the
    55  	// lookup explainer. The method will only get called when the explanation
    56  	// support is enabled
    57  	ReportText(messageProducer func() string)
    58  
    59  	// ReportLocationNotFound reports that the current location wasn't found
    60  	ReportLocationNotFound()
    61  
    62  	// ReportFound reports that the given value was found using the given key
    63  	ReportFound(key interface{}, value dgo.Value)
    64  
    65  	// ReportMergeResult reports the result of a the current merge operation
    66  	ReportMergeResult(value dgo.Value)
    67  
    68  	// ReportMergeSource reports the source of the current merge (explicit options or lookup options)
    69  	ReportMergeSource(source string)
    70  
    71  	// ReportModuleNotFound reports that the current module was not found
    72  	ReportModuleNotFound()
    73  
    74  	// ReportNotFound reports that the given key was not found
    75  	ReportNotFound(key interface{})
    76  
    77  	// ServerContext returns a new server context for this invocation configured with the given options
    78  	ServerContext(options dgo.Map) ServerContext
    79  
    80  	// WithDataProvider pushes the given provider to the explanation stack and calls the producer, then pops the
    81  	// provider again before returning.
    82  	WithDataProvider(pvd DataProvider, f dgo.Producer) dgo.Value
    83  
    84  	// WithInterpolation pushes the given expression to the explanation stack and calls the producer, then pops the
    85  	// expression again before returning.
    86  	WithInterpolation(expr string, f dgo.Producer) dgo.Value
    87  
    88  	// WithInvalidKey pushes the given key to the explanation stack and calls the producer, then pops the
    89  	// key again before returning.
    90  	WithInvalidKey(key interface{}, f dgo.Producer) dgo.Value
    91  
    92  	// WithLocation pushes the given location to the explanation stack and calls the producer, then pops the
    93  	// location again before returning.
    94  	WithLocation(loc Location, f dgo.Producer) dgo.Value
    95  
    96  	// WithLookup pushes the given key to the explanation stack and calls the producer, then pops the
    97  	// key again before returning.
    98  	WithLookup(key Key, f dgo.Producer) dgo.Value
    99  
   100  	// WithMerge pushes the given strategy to the explanation stack and calls the producer, then pops the
   101  	// strategy again before returning.
   102  	WithMerge(ms MergeStrategy, f dgo.Producer) dgo.Value
   103  
   104  	// WithModule pushes the given module to the explanation stack and calls the producer, then pops the
   105  	// module again before returning.
   106  	WithModule(moduleName string, f dgo.Producer) dgo.Value
   107  
   108  	// WithSegment pushes the given segment to the explanation stack and calls the producer, then pops the
   109  	// segment again before returning.
   110  	WithSegment(seg interface{}, f dgo.Producer) dgo.Value
   111  
   112  	// WithLookup pushes the given key to the explanation stack and calls the producer, then pops the
   113  	// key again before returning.
   114  	WithSubLookup(key Key, f dgo.Producer) dgo.Value
   115  
   116  	// ExplainMode returns true if explain support is active
   117  	ExplainMode() bool
   118  
   119  	// ForConfig returns an Invocation without explain support
   120  	ForConfig() Invocation
   121  
   122  	// ForData returns an Invocation returns an Invocation that has adjusted its explainer according to
   123  	// how it should report lookup of data (as opposed to lookup of "lookup_options").
   124  	ForData() Invocation
   125  
   126  	// ForLookupOptions returns an Invocation that has adjusted its explainer according to
   127  	// how it should report lookup of the "lookup_options" key.
   128  	ForLookupOptions() Invocation
   129  
   130  	// SetMergeStrategy sets the current merge strategy for the invocation from the given command line
   131  	// option `merge` and lookupOptions for the key that is currently being looked up.
   132  	SetMergeStrategy(cliMergeOpt dgo.Value, lookupOptions dgo.Map)
   133  
   134  	// Returns the current merge strategy
   135  	MergeStrategy() MergeStrategy
   136  
   137  	// Returns the current lookup options
   138  	LookupOptions() dgo.Map
   139  
   140  	// Returns true if this invocation is adjusted to do lookup of the "lookup_options" key
   141  	LookupOptionsMode() bool
   142  
   143  	// Returns true if this invocation is adjusted to do lookup of data and not "lookup_options"
   144  	DataMode() bool
   145  }