From 44123567fc6063f140a5f4f775519bbbdb056381 Mon Sep 17 00:00:00 2001 From: Amit Schendel Date: Thu, 25 Jan 2024 15:36:52 +0200 Subject: [PATCH] Adding function defenition Signed-off-by: Amit Schendel --- core/pkg/opaprocessor/utils.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/core/pkg/opaprocessor/utils.go b/core/pkg/opaprocessor/utils.go index 275d0910..243888a7 100644 --- a/core/pkg/opaprocessor/utils.go +++ b/core/pkg/opaprocessor/utils.go @@ -112,3 +112,21 @@ var imageNameNormalizeDefinition = func(bctx rego.BuiltinContext, a *ast.Term) ( normalizedName, err := cautils.NormalizeImageName(string(aStr)) return ast.StringTerm(normalizedName), err } + +var unauthenticatedServiceDeclaration = ®o.Function{ + Name: "networkscanner.unauthenticated_service", + Decl: types.NewFunction(types.Args(types.S), types.B), + Memoize: true, +} + +var unauthenticatedServiceDefinition = func(bctx rego.BuiltinContext, a, b *ast.Term) (*ast.Term, error) { + aStr, err := builtins.StringOperand(a.Value, 1) + if err != nil { + return nil, fmt.Errorf("invalid parameter type: %v", err) + } + bStr, err := builtins.StringOperand(b.Value, 1) + if err != nil { + return nil, fmt.Errorf("invalid parameter type: %v", err) + } + return ast.BooleanTerm(isUnauthenticatedService(string(aStr), string(bStr))), nil +}