Skip to content

Commit

Permalink
Adding UpdateRealm methods
Browse files Browse the repository at this point in the history
  • Loading branch information
dlisin committed Feb 9, 2020
1 parent a587a05 commit d96dfa5
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 1 deletion.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,8 @@ type GoCloak interface {

GetRealm(token string, realm string) (*RealmRepresentation, error)
GetRealms(token string) ([]*RealmRepresentation, error)
CreateRealm(token string, realm RealmRepresentation) error
CreateRealm(token string, realm RealmRepresentation) (string, error)
UpdateRealm(token string, realm RealmRepresentation) error
DeleteRealm(token string, realm string) error
ClearRealmCache(token string, realm string) error
ClearUserCache(token string, realm string) error
Expand Down
9 changes: 9 additions & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -1179,6 +1179,15 @@ func (client *gocloak) CreateRealm(token string, realm RealmRepresentation) (str
return getID(resp), nil
}

// UpdateRealm updates a given realm
func (client *gocloak) UpdateRealm(token string, realm RealmRepresentation) error {
resp, err := client.getRequestWithBearerAuth(token).
SetBody(realm).
Put(client.getAdminRealmURL(PString(realm.Realm)))

return checkForError(resp, err)
}

// DeleteRealm removes a realm
func (client *gocloak) DeleteRealm(token string, realm string) error {
resp, err := client.getRequestWithBearerAuth(token).
Expand Down
16 changes: 16 additions & 0 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1452,6 +1452,22 @@ func TestGocloak_CreateRealm(t *testing.T) {
defer tearDown()
}

func TestGocloak_UpdateRealm(t *testing.T) {
t.Parallel()
client := NewClientWithDebug(t)
token := GetAdminToken(t, client)

tearDown, realmID := CreateRealm(t, client)
defer tearDown()

realm, err := client.GetRealm(token.AccessToken, realmID)
assert.NoError(t, err, "GetRealm failed")

realm.Enabled = BoolP(false)
err = client.UpdateRealm(token.AccessToken, *realm)
assert.NoError(t, err, "UpdateRealm failed")
}

func TestGocloak_ClearRealmCache(t *testing.T) {
t.Parallel()
client := NewClientWithDebug(t)
Expand Down
2 changes: 2 additions & 0 deletions gocloak.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,8 @@ type GoCloak interface {
GetRealms(token string) ([]*RealmRepresentation, error)
// CreateRealm creates a realm
CreateRealm(token string, realm RealmRepresentation) (string, error)
// UpdateRealm updates a given realm
UpdateRealm(token string, realm RealmRepresentation) error
// DeleteRealm removes a realm
DeleteRealm(token string, realm string) error
// ClearRealmCache clears realm cache
Expand Down

0 comments on commit d96dfa5

Please sign in to comment.