-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Charles-Edouard Brétéché <[email protected]>
- Loading branch information
1 parent
b262315
commit 2868b21
Showing
5 changed files
with
169 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,41 @@ | ||
module github.com/kyverno/kyverno-envoy-plugin | ||
|
||
go 1.21.4 | ||
go 1.21 | ||
|
||
toolchain go1.21.0 | ||
|
||
require ( | ||
github.com/envoyproxy/go-control-plane v0.12.0 | ||
github.com/jmespath-community/go-jmespath v1.1.2-0.20231123142750-72f7c13d265e | ||
github.com/kyverno/kyverno-json v0.0.2 | ||
google.golang.org/genproto/googleapis/rpc v0.0.0-20240123012728-ef4313101c80 | ||
google.golang.org/grpc v1.62.1 | ||
k8s.io/apimachinery v0.29.2 | ||
) | ||
|
||
require ( | ||
github.com/IGLOU-EU/go-wildcard v1.0.3 // indirect | ||
github.com/aquilax/truncate v1.0.0 // indirect | ||
github.com/blang/semver/v4 v4.0.0 // indirect | ||
github.com/cncf/xds/go v0.0.0-20231128003011-0fa0005c9caa // indirect | ||
github.com/envoyproxy/protoc-gen-validate v1.0.4 // indirect | ||
github.com/go-logr/logr v1.3.0 // indirect | ||
github.com/gogo/protobuf v1.3.2 // indirect | ||
github.com/golang/protobuf v1.5.3 // indirect | ||
github.com/gopherjs/gopherjs v1.17.2 // indirect | ||
github.com/jtolds/gls v4.20.0+incompatible // indirect | ||
github.com/kr/text v0.2.0 // indirect | ||
github.com/kyverno/kyverno v1.5.0-rc1.0.20231029235953-c96199dee1f6 // indirect | ||
github.com/smarty/assertions v1.15.1 // indirect | ||
github.com/zach-klippenstein/goregen v0.0.0-20160303162051-795b5e3961ea // indirect | ||
golang.org/x/crypto v0.18.0 // indirect | ||
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect | ||
golang.org/x/net v0.20.0 // indirect | ||
golang.org/x/sys v0.16.0 // indirect | ||
golang.org/x/text v0.14.0 // indirect | ||
google.golang.org/protobuf v1.32.0 // indirect | ||
gopkg.in/inf.v0 v0.9.1 // indirect | ||
k8s.io/klog/v2 v2.110.1 // indirect | ||
k8s.io/utils v0.0.0-20230726121419-3b25d923346b // indirect | ||
sigs.k8s.io/yaml v1.4.0 // indirect | ||
) |
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
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,31 @@ | ||
package scratch | ||
|
||
import ( | ||
"context" | ||
|
||
jpfunctions "github.com/jmespath-community/go-jmespath/pkg/functions" | ||
"github.com/jmespath-community/go-jmespath/pkg/interpreter" | ||
"github.com/jmespath-community/go-jmespath/pkg/parsing" | ||
"github.com/kyverno/kyverno-json/pkg/engine/template" | ||
) | ||
|
||
var Caller = func() interpreter.FunctionCaller { | ||
var funcs []jpfunctions.FunctionEntry | ||
funcs = append(funcs, template.GetFunctions(context.Background())...) | ||
return interpreter.NewFunctionCaller(funcs...) | ||
}() | ||
|
||
func GetUser(authorisation string) (string, error) { | ||
vm := interpreter.NewInterpreter(nil, nil) | ||
parser := parsing.NewParser() | ||
statement := `base64_decode(@)` | ||
compiled, err := parser.Parse(statement) | ||
if err != nil { | ||
return "", err | ||
} | ||
out, err := vm.Execute(compiled, authorisation, interpreter.WithFunctionCaller(Caller)) | ||
if err != nil { | ||
return "", err | ||
} | ||
return out.(string), nil | ||
} |
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,30 @@ | ||
package scratch | ||
|
||
import "testing" | ||
|
||
func TestGetUser(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
authorisation string | ||
want string | ||
wantErr bool | ||
}{ | ||
{ | ||
authorisation: "YWxpY2U6cGFzc3dvcmQ=", | ||
want: "alice:password", | ||
wantErr: false, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
got, err := GetUser(tt.authorisation) | ||
if (err != nil) != tt.wantErr { | ||
t.Errorf("GetUser() error = %v, wantErr %v", err, tt.wantErr) | ||
return | ||
} | ||
if got != tt.want { | ||
t.Errorf("GetUser() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} |