From e2183445416ad06e7b4ff4f16b422ca559c73380 Mon Sep 17 00:00:00 2001 From: Edward Viaene Date: Tue, 15 Oct 2024 14:10:19 -0500 Subject: [PATCH] user hooks --- auth/provisioning/scim/new.go | 10 ++++------ auth/provisioning/scim/types.go | 11 +++-------- auth/provisioning/scim/users.go | 6 +++--- auth/provisioning/scim/users_test.go | 10 +++++----- rest/resources/.gitignore | 4 ---- 5 files changed, 15 insertions(+), 26 deletions(-) delete mode 100644 rest/resources/.gitignore diff --git a/auth/provisioning/scim/new.go b/auth/provisioning/scim/new.go index ab95988..a6a6918 100644 --- a/auth/provisioning/scim/new.go +++ b/auth/provisioning/scim/new.go @@ -5,13 +5,11 @@ import ( "github.com/in4it/go-devops-platform/users" ) -func New(storage storage.Iface, userStore *users.UserStore, token string, disableFunc DisableFunc, reactivateFunc ReactivateFunc) *Scim { +func New(storage storage.Iface, userStore *users.UserStore, token string) *Scim { s := &Scim{ - Token: token, - UserStore: userStore, - storage: storage, - DisableFunc: disableFunc, - ReactivateFunc: reactivateFunc, + Token: token, + UserStore: userStore, + storage: storage, } return s } diff --git a/auth/provisioning/scim/types.go b/auth/provisioning/scim/types.go index 863a970..f226eb9 100644 --- a/auth/provisioning/scim/types.go +++ b/auth/provisioning/scim/types.go @@ -7,15 +7,10 @@ import ( "github.com/in4it/go-devops-platform/users" ) -type DisableFunc func(storage.Iface, users.User) error -type ReactivateFunc func(storage.Iface, users.User) error - type Scim struct { - Token string `json:"token"` - UserStore *users.UserStore `json:"userStore"` - storage storage.Iface - DisableFunc DisableFunc - ReactivateFunc ReactivateFunc + Token string `json:"token"` + UserStore *users.UserStore `json:"userStore"` + storage storage.Iface } type Iface interface { diff --git a/auth/provisioning/scim/users.go b/auth/provisioning/scim/users.go index 1be9372..98ab918 100644 --- a/auth/provisioning/scim/users.go +++ b/auth/provisioning/scim/users.go @@ -100,14 +100,14 @@ func (s *Scim) PutUserHandler(w http.ResponseWriter, r *http.Request) { } if !putUserRequest.Active && !user.Suspended { // user is suspended - err = s.DisableFunc(s.storage, user) + err = s.UserStore.UserHooks.DisableFunc(s.storage, user) if err != nil { returnError(w, fmt.Errorf("could not delete all clients for user %s: %s", user.ID, err), http.StatusBadRequest) return } } if putUserRequest.Active && user.Suspended { // user is unsuspended - err := s.ReactivateFunc(s.storage, user) + err := s.UserStore.UserHooks.ReactivateFunc(s.storage, user) if err != nil { returnError(w, fmt.Errorf("could not reactivate all clients for user %s: %s", user.ID, err), http.StatusBadRequest) return @@ -144,7 +144,7 @@ func (s *Scim) DeleteUserHandler(w http.ResponseWriter, r *http.Request) { return } - err = s.DisableFunc(s.storage, user) + err = s.UserStore.UserHooks.DeleteFunc(s.storage, user) if err != nil { returnError(w, fmt.Errorf("could not delete all clients for user %s: %s", user.ID, err), http.StatusBadRequest) return diff --git a/auth/provisioning/scim/users_test.go b/auth/provisioning/scim/users_test.go index ff0375f..5ee1a23 100644 --- a/auth/provisioning/scim/users_test.go +++ b/auth/provisioning/scim/users_test.go @@ -26,7 +26,7 @@ func TestUsersGetCount100EmptyResult(t *testing.T) { t.Fatalf("cannot empty user store") } - s := New(storage, userStore, "token", nil, nil) + s := New(storage, userStore, "token") req := httptest.NewRequest("GET", "http://example.com/api/scim/v2/Users?count=100&startIndex=1&", nil) w := httptest.NewRecorder() s.GetUsersHandler(w, req) @@ -64,7 +64,7 @@ func TestUsersGetCount10(t *testing.T) { if err != nil { t.Fatalf("cannot create users: %s", err) } - s := New(storage, userStore, "token", nil, nil) + s := New(storage, userStore, "token") req := httptest.NewRequest("GET", "http://example.com/api/scim/v2/Users?count=10&startIndex=1&", nil) w := httptest.NewRecorder() s.GetUsersHandler(w, req) @@ -104,7 +104,7 @@ func TestUsersGetCount10Start5(t *testing.T) { if err != nil { t.Fatalf("cannot create users: %s", err) } - s := New(storage, userStore, "token", nil, nil) + s := New(storage, userStore, "token") req := httptest.NewRequest("GET", fmt.Sprintf("http://example.com/api/scim/v2/Users?count=%d&startIndex=%d&", count, start), nil) w := httptest.NewRecorder() s.GetUsersHandler(w, req) @@ -139,7 +139,7 @@ func TestUsersGetNonExistentUser(t *testing.T) { t.Fatalf("cannot create new user stoer") } - s := New(&memorystorage.MockMemoryStorage{}, userStore, "token", nil, nil) + s := New(&memorystorage.MockMemoryStorage{}, userStore, "token") req := httptest.NewRequest("GET", "http://example.com/api/scim/v2/Users?filter=userName+eq+%22ward%40in4it.io%22&", nil) w := httptest.NewRecorder() s.GetUsersHandler(w, req) @@ -166,7 +166,7 @@ func TestAddUser(t *testing.T) { if err != nil { t.Fatalf("cannot empty user store") } - s := New(storage, userStore, "token", nil, nil) + s := New(storage, userStore, "token") payload := PostUserRequest{ UserName: "john@domain.inv", Name: Name{ diff --git a/rest/resources/.gitignore b/rest/resources/.gitignore deleted file mode 100644 index 5e7d273..0000000 --- a/rest/resources/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -# Ignore everything in this directory -* -# Except this file -!.gitignore