From 667a56db88384a75b7b6b08dc36c6e691ca55163 Mon Sep 17 00:00:00 2001 From: Nic Cope Date: Tue, 21 Nov 2023 18:10:32 -0800 Subject: [PATCH] Add convenience functions for returning results Signed-off-by: Nic Cope --- crossplane/function/response.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/crossplane/function/response.py b/crossplane/function/response.py index 7b7230f..0732e6b 100644 --- a/crossplane/function/response.py +++ b/crossplane/function/response.py @@ -33,3 +33,33 @@ def to( desired=req.desired, context=req.context, ) + + +def normal(rsp: fnv1beta1.RunFunctionResponse, message: str) -> None: + """Add a normal result to the response.""" + rsp.results.append( + fnv1beta1.Result( + severity=fnv1beta1.SEVERITY_NORMAL, + message=message, + ) + ) + + +def warning(rsp: fnv1beta1.RunFunctionResponse, message: str) -> None: + """Add a warning result to the response.""" + rsp.results.append( + fnv1beta1.Result( + severity=fnv1beta1.SEVERITY_WARNING, + message=message, + ) + ) + + +def fatal(rsp: fnv1beta1.RunFunctionResponse, message: str) -> None: + """Add a fatal result to the response.""" + rsp.results.append( + fnv1beta1.Result( + severity=fnv1beta1.SEVERITY_FATAL, + message=message, + ) + )