Skip to content

Commit

Permalink
eventbuilder off lasso (#221)
Browse files Browse the repository at this point in the history
* refactor: eventbuilder off lasso

* fix: garbage from old tests
  • Loading branch information
ebauman authored Feb 13, 2025
1 parent 4e9ad95 commit b50bf92
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 14 deletions.
11 changes: 1 addition & 10 deletions v4/pkg/authentication/providers/ldap/ldap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ package ldap

import (
"encoding/base64"
"github.com/hobbyfarm/gargantua/v4/pkg/apis/hobbyfarm.io/v4alpha1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"testing"
)

Expand All @@ -29,14 +27,7 @@ func Test_LabelToDn(t *testing.T) {
func Test_DnToLabel(t *testing.T) {
var host = "dc01.it.example.org"
var dn = "cn=user01,ou=users,dc=it,dc=example,dc=org"
l := dnToLabel(dn, &v4alpha1.LdapConfig{
TypeMeta: metav1.TypeMeta{},
ObjectMeta: metav1.ObjectMeta{},
Spec: v4alpha1.LdapConfigSpec{
LdapHost: host,
},
Status: v4alpha1.LdapConfigStatus{},
})
l := dnToLabel(dn, host)

res := base64.StdEncoding.EncodeToString([]byte("ldap://" + host + "/" + dn))

Expand Down
7 changes: 3 additions & 4 deletions v4/pkg/eventbuilder/eventbuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"github.com/hobbyfarm/gargantua/v4/pkg/apis/hobbyfarm.io/v4alpha1"
"github.com/hobbyfarm/gargantua/v4/pkg/names"
lasso "github.com/rancher/lasso/pkg/client"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"log/slog"
Expand Down Expand Up @@ -48,16 +47,16 @@ func Error() *EventBuilder {
// WriteOrLog attempts to write the event using the provided client.
// Unlike Write, this method does not return an error. Instead
// it uses log/slog to write the error if one should occur.
func (e *EventBuilder) WriteOrLog(kclient *lasso.Client) {
func (e *EventBuilder) WriteOrLog(kclient client.Client) {
if err := e.Write(kclient); err != nil {
slog.Error(err.Error())
}
}

// Write attempts to write the event using the provided client.
func (e *EventBuilder) Write(kclient *lasso.Client) error {
func (e *EventBuilder) Write(kclient client.Client) error {
ev := e.ToEvent()
return kclient.Create(context.Background(), "", ev, ev, metav1.CreateOptions{})
return kclient.Create(context.Background(), ev)
}

// Type sets the EventType of the Event.
Expand Down

0 comments on commit b50bf92

Please sign in to comment.