Skip to content

Commit

Permalink
user hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
wardviaene committed Oct 15, 2024
1 parent a45080c commit e218344
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 26 deletions.
10 changes: 4 additions & 6 deletions auth/provisioning/scim/new.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
11 changes: 3 additions & 8 deletions auth/provisioning/scim/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions auth/provisioning/scim/users.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions auth/provisioning/scim/users_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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: "[email protected]",
Name: Name{
Expand Down
4 changes: 0 additions & 4 deletions rest/resources/.gitignore

This file was deleted.

0 comments on commit e218344

Please sign in to comment.