Skip to content

Commit

Permalink
New Realm Service (#7)
Browse files Browse the repository at this point in the history
* add read, update, and delete Realms

* Update build and imports, request templates. (#8)

* Update issue templates

* add read, update, and delete Realms

* Update build and imports, request templates. (#8)

* add read, update, and delete Realms

* Remove uuid from tests.

* add read, update, and delete Realms

* add read, update, and delete Realms

* Fix build.
  • Loading branch information
Scuilion authored and thspinto committed Apr 21, 2019
1 parent 38811e8 commit ca533b8
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
46 changes: 46 additions & 0 deletions keycloak/realm_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,49 @@ func (rs *RealmService) Delete(ctx context.Context, realm string) error {
return err
return realms, nil
}

// Get realm with realm name (not id!)
func (rs *RealmService) Get(ctx context.Context, realm string) (*RealmRepresentation, error) {
path := "/realms/{realm}"

rr := &RealmRepresentation{}

_, err := rs.client.newRequest(ctx).
SetPathParams(map[string]string{
"realm": realm,
}).
SetResult(rr).
Get(path)

if err != nil {
return nil, err
}

return rr, nil
}

// Create realm with realm, known in Keycloak as import
func (rs *RealmService) Create(ctx context.Context, realm *RealmRepresentation) error {
path := "/realms"
_, err := rs.client.newRequest(ctx).
SetBody(realm).
Post(path)

return err
}

// Delete realm with realm name (not id!)
func (rs *RealmService) Delete(ctx context.Context, realm string) error {

// nolint: goconst
path := "/realms/{realm}"

_, err := rs.client.newRequest(ctx).
SetPathParams(map[string]string{
"realm": realm,
}).
SetResult(realm).
Delete(path)

return err
}
2 changes: 1 addition & 1 deletion keycloak/realms.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

package keycloak

// RealmRepresentation represents client consents
// RealmRepresentation represents a realm
type RealmRepresentation struct {
AccessCodeLifespan int `json:"accessCodeLifespan,omitempty"`
AccessCodeLifespanLogin int `json:"accessCodeLifespanLogin,omitempty"`
Expand Down

0 comments on commit ca533b8

Please sign in to comment.