-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: timeouts management (#1719)
* refactor: timeouts management Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com> * fix Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com> --------- Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>
- Loading branch information
1 parent
6a9ee23
commit f00417c
Showing
8 changed files
with
200 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package model | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/jmespath-community/go-jmespath/pkg/binding" | ||
"github.com/kyverno/chainsaw/pkg/mutate" | ||
"github.com/kyverno/chainsaw/pkg/runner/functions" | ||
"github.com/kyverno/kyverno-json/pkg/engine/template" | ||
) | ||
|
||
func Evaluate[T any](ctx context.Context, in string, bindings binding.Bindings) (T, error) { | ||
var def T | ||
if converted, err := mutate.Mutate(ctx, nil, mutate.Parse(ctx, in), nil, bindings, template.WithFunctionCaller(functions.Caller)); err != nil { | ||
return def, err | ||
} else if converted, ok := converted.(T); !ok { | ||
return converted, fmt.Errorf("expression didn't evaluate to the expected type (%s)", in) | ||
} else { | ||
return converted, nil | ||
} | ||
} | ||
|
||
func String(ctx context.Context, in string, bindings binding.Bindings) (string, error) { | ||
return Evaluate[string](ctx, in, bindings) | ||
} |
Oops, something went wrong.