Skip to content

Commit d900747

Browse files
ScuilionAzuka
authored andcommitted
New Realm Service (#7)
* 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.
1 parent 47d716b commit d900747

File tree

14 files changed

+394
-4126
lines changed

14 files changed

+394
-4126
lines changed

Gopkg.lock

Lines changed: 3 additions & 19 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Gopkg.toml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,6 @@
2929
name = "gopkg.in/resty.v1"
3030
version = "1.7.0"
3131

32-
[[constraint]]
33-
branch = "master"
34-
name = "github.com/mailru/easyjson"
35-
3632
[[constraint]]
3733
branch = "v1"
3834
name = "gopkg.in/jarcoal/httpmock.v1"

Makefile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ format:
3939
.PHONY: generate
4040
generate:
4141
@echo "$(OK_COLOR)==> Generating code$(NO_COLOR)"
42-
@rm -rf $(PWD)/keycloak/*_easyjson.go
4342
@go generate ./...
4443

4544
# Lint

Readme.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,12 @@ make integration
4040
- [ ] Key
4141
- [ ] Protocol Mappers
4242
- [ ] Realms Admin
43+
- [x] Get realm
44+
- [ ] Import realm
45+
- [ ] Update realm
46+
- [x] Delete realm
47+
- [ ] Get admin events
48+
- [ ] Delete admin events
4349
- [ ] Role Mapper
4450
- [ ] Roles
4551
- [ ] Roles (by ID)
@@ -57,6 +63,5 @@ make integration
5763

5864
## Thanks to
5965
- https://gopkg.in/resty.v1: quick and dirty REST client
60-
- https://github.com/mailru/easyjson: faster JSON serialization
6166
- https://godoc.org/golang.org/x/oauth2: for the shamelessly copied authentication
62-
- https://github.com/fatih/gomodifytags: because I'm too lazy to type json struct tags
67+
- https://github.com/fatih/gomodifytags: because I'm too lazy to type json struct tags

integration/helpers_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@ func pseudoRandString() string {
1717
prefix[i] = chars[rand.Intn(len(chars))]
1818
}
1919

20-
return fmt.Sprintf("%s-%d", string(chars), time.Now().Unix())
20+
return fmt.Sprintf("%s-%d", string(prefix), time.Now().Unix())
2121
}

integration/realm_test.go

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
package integration_test
2+
3+
import (
4+
"github.com/Azuka/keycloak-admin-go/keycloak"
5+
)
6+
7+
func (suite *integrationTester) TestRealmFetch() {
8+
realm, err := suite.client.Realm.Get(suite.ctx, keycloakAdminRealm)
9+
suite.NotNil(realm)
10+
suite.NoError(err)
11+
suite.Equal(keycloakAdminRealm, realm.ID)
12+
}
13+
14+
func (suite *integrationTester) TestRealmDelete() {
15+
realmID := pseudoRandString()
16+
realmName := pseudoRandString()
17+
18+
newRealm := &keycloak.RealmRepresentation{
19+
ID: realmID,
20+
Realm: realmName,
21+
}
22+
23+
err := suite.client.Realm.Create(suite.ctx, newRealm)
24+
suite.NoError(err)
25+
26+
err = suite.client.Realm.Delete(suite.ctx, realmName)
27+
suite.NoError(err)
28+
}
29+
30+
func (suite *integrationTester) TestRealmCreate() {
31+
realmID := pseudoRandString()
32+
realmName := pseudoRandString()
33+
t := func() *bool { b := true; return &b }()
34+
newRealm := &keycloak.RealmRepresentation{
35+
ID: realmID,
36+
Realm: realmName,
37+
AccessCodeLifespan: 1,
38+
AccessCodeLifespanLogin: 2,
39+
AccessCodeLifespanUserAction: 3,
40+
AccessTokenLifespan: 4,
41+
AccessTokenLifespanForImplicitFlow: 5,
42+
AccountTheme: "base",
43+
ActionTokenGeneratedByAdminLifespan: 6,
44+
ActionTokenGeneratedByUserLifespan: 7,
45+
AdminEventsDetailsEnabled: t,
46+
AdminEventsEnabled: t,
47+
AdminTheme: "base",
48+
DisplayName: "realmDisplayName",
49+
DisplayNameHTML: "realmDisplayNameHTML",
50+
}
51+
52+
err := suite.client.Realm.Create(suite.ctx, newRealm)
53+
suite.NoError(err)
54+
55+
actualRealm, err := suite.client.Realm.Get(suite.ctx, realmName)
56+
suite.NoError(err)
57+
suite.NotNil(actualRealm)
58+
suite.Equal(actualRealm.ID, newRealm.ID)
59+
suite.Equal(actualRealm.Realm, newRealm.Realm)
60+
61+
suite.Equal(actualRealm.AccessCodeLifespan, newRealm.AccessCodeLifespan)
62+
suite.Equal(actualRealm.AccessCodeLifespanLogin, newRealm.AccessCodeLifespanLogin)
63+
suite.Equal(actualRealm.AccessCodeLifespanUserAction, newRealm.AccessCodeLifespanUserAction)
64+
suite.Equal(actualRealm.AccessTokenLifespan, newRealm.AccessTokenLifespan)
65+
suite.Equal(actualRealm.AccessTokenLifespanForImplicitFlow, newRealm.AccessTokenLifespanForImplicitFlow)
66+
suite.Equal(actualRealm.AccountTheme, newRealm.AccountTheme)
67+
suite.Equal(actualRealm.ActionTokenGeneratedByAdminLifespan, newRealm.ActionTokenGeneratedByAdminLifespan)
68+
suite.Equal(actualRealm.ActionTokenGeneratedByUserLifespan, newRealm.ActionTokenGeneratedByUserLifespan)
69+
suite.Equal(actualRealm.AdminEventsDetailsEnabled, newRealm.AdminEventsDetailsEnabled)
70+
suite.Equal(actualRealm.AdminEventsEnabled, newRealm.AdminEventsEnabled)
71+
suite.Equal(actualRealm.AdminTheme, newRealm.AdminTheme)
72+
suite.Equal(actualRealm.DisplayName, newRealm.DisplayName)
73+
suite.Equal(actualRealm.DisplayNameHTML, newRealm.DisplayNameHTML)
74+
}

keycloak/client.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ type Client struct {
2323

2424
// Services for working with various keycloak resources
2525
Users *UserService
26+
Realm *RealmService
2627
}
2728

2829
// NewClient creates a new client instance set to talk to the keycloak service
@@ -37,6 +38,7 @@ func NewClient(u url.URL, c *http.Client) *Client {
3738
}
3839

3940
client.Users = NewUserService(client)
41+
client.Realm = NewRealmService(client)
4042

4143
return client
4244
}

keycloak/clients.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
//go:generate gomodifytags -file $GOFILE -struct ScopeRepresentation -add-options json=omitempty -add-tags json -w -transform camelcase
55
//go:generate gomodifytags -file $GOFILE -struct ResourceRepresentation -add-options json=omitempty -add-tags json -w -transform camelcase
66
//go:generate gomodifytags -file $GOFILE -struct ProtocolMapperRepresentation -add-options json=omitempty -add-tags json -w -transform camelcase
7-
//go:generate easyjson -all $GOFILE
87

98
package keycloak
109

0 commit comments

Comments
 (0)