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

WIP discussion of function values to resources #716

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Prev Previous commit
Next Next commit
lang: funcs: facts: Add CallableFunc implementation for fact
Add an initial implementation for this wrapper function.
  • Loading branch information
purpleidea committed Jan 20, 2024
commit 299ec4acddabfce4418ef7314be62ef1db8cb530
13 changes: 13 additions & 0 deletions lang/funcs/facts/facts.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,16 @@ type Fact interface {
Init(*Init) error
Stream(context.Context) error
}

// CallableFunc is a function that can be called statically if we want to do it
// speculatively or from a resource.
type CallableFact interface {
Fact // implement everything in Fact but add the additional requirements

// Call this function with the input args and return the value if it is
// possible to do so at this time. To transform from the single value,
// graph representation of the callable values into a linear, standard
// args list for use here, you can use the StructToCallableArgs
// function.
Call() (types.Value, error)
}
12 changes: 12 additions & 0 deletions lang/funcs/facts/func.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,15 @@ func (obj *FactFunc) Init(init *interfaces.Init) error {
func (obj *FactFunc) Stream(ctx context.Context) error {
return obj.Fact.Stream(ctx)
}

// Call means this function implements the CallableFunc interface and can be
// called statically if we want to do it speculatively or from a resource.
func (obj *FactFunc) Call() (types.Value, error) {

callableFact, ok := obj.Fact.(CallableFact)
if !ok {
return nil, fmt.Errorf("fact is not a CallableFact")
}

return callableFact.Call()
}