diff --git a/Gopkg.lock b/Gopkg.lock index c6cc066..b3ca125 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -2,15 +2,15 @@ [[projects]] - digest = "1:5642d26fba562723106466a33c8fb7710f32dd608d54491e499b76c82387bcc7" + branch = "master" + digest = "1:c3e6e91aafe6e3a12e3669b77f8fd608ddf8e61a727858ce50811daabc9600ea" name = "github.com/cloudtrust/common-service" packages = [ ".", "errors", ] pruneopts = "" - revision = "ae957836daffbc39f197fa5f27201f8d100179d5" - version = "v1.2.3" + revision = "bda3eb6af01813931780dc33b49aabd0f878be19" [[projects]] digest = "1:379d34d9efc755fab444199f007819fe99718640f9ccfbdd3f0430340bb02b07" @@ -118,7 +118,7 @@ [[projects]] branch = "master" - digest = "1:466229595e2439c31e2b3eb30f5d13782c3ffaed6b36d075d104c3ce7e9d9779" + digest = "1:8dc5306c5097afa86c85335c9e981a22c164aab641ff749f88d2eecf9dbfdb93" name = "golang.org/x/crypto" packages = [ "ed25519", @@ -126,7 +126,7 @@ "pbkdf2", ] pruneopts = "" - revision = "6d4e4cb37c7d6416dfea8472e751c7b6615267a6" + revision = "530e935923ad688be97c15eeb8e5ee42ebf2b54a" [[projects]] branch = "master" diff --git a/Gopkg.toml b/Gopkg.toml index e377dec..c6e8c4f 100644 --- a/Gopkg.toml +++ b/Gopkg.toml @@ -22,7 +22,7 @@ [[constraint]] name = "github.com/cloudtrust/common-service" - version = "v1.2.3" + branch = "master" [[constraint]] name = "github.com/pkg/errors" diff --git a/groups.go b/groups.go index 7f171a3..c0d5a0a 100644 --- a/groups.go +++ b/groups.go @@ -1,12 +1,15 @@ package keycloak import ( + "gopkg.in/h2non/gentleman.v2/plugins/body" "gopkg.in/h2non/gentleman.v2/plugins/url" ) const ( - groupsPath = "/auth/admin/realms/:realm/groups" - groupByIDPath = "/auth/admin/realms/:realm/groups/:id" + groupsPath = "/auth/admin/realms/:realm/groups" + groupByIDPath = groupsPath + "/:id" + groupClientRoleMappingPath = groupByIDPath + "/role-mappings/clients/:clientId" + availableGroupClientRoleMappingPath = groupClientRoleMappingPath + "/available" ) // GetGroups gets all groups for the realm @@ -22,3 +25,38 @@ func (c *Client) GetGroup(accessToken string, realmName string, groupID string) var err = c.get(accessToken, &resp, url.Path(groupByIDPath), url.Param("realm", realmName), url.Param("id", groupID)) return resp, err } + +// CreateGroup creates the group from its GroupRepresentation. The group name must be unique. +func (c *Client) CreateGroup(accessToken string, reqRealmName string, group GroupRepresentation) (string, error) { + return c.post(accessToken, nil, url.Path(groupsPath), url.Param("realm", reqRealmName), body.JSON(group)) +} + +// DeleteGroup deletes a specific group’s representation +func (c *Client) DeleteGroup(accessToken string, realmName string, groupID string) error { + return c.delete(accessToken, url.Path(groupByIDPath), url.Param("realm", realmName), url.Param("id", groupID)) +} + +// AssignClientRole assigns client roles to a specific group +func (c *Client) AssignClientRole(accessToken string, realmName string, groupID string, clientID string, roles []RoleRepresentation) error { + _, err := c.post(accessToken, nil, url.Path(groupClientRoleMappingPath), url.Param("realm", realmName), url.Param("id", groupID), url.Param("clientId", clientID), body.JSON(roles)) + return err +} + +// RemoveClientRole deletes client roles from a specific group +func (c *Client) RemoveClientRole(accessToken string, realmName string, groupID string, clientID string, roles []RoleRepresentation) error { + return c.delete(accessToken, url.Path(groupClientRoleMappingPath), url.Param("realm", realmName), url.Param("id", groupID), url.Param("clientId", clientID), body.JSON(roles)) +} + +// GetGroupClientRoles gets client roles assigned to a specific group +func (c *Client) GetGroupClientRoles(accessToken string, realmName string, groupID string, clientID string) ([]RoleRepresentation, error) { + var roles = []RoleRepresentation{} + var err = c.get(accessToken, &roles, url.Path(groupClientRoleMappingPath), url.Param("realm", realmName), url.Param("id", groupID), url.Param("clientId", clientID)) + return roles, err +} + +// GetAvailableGroupClientRoles gets client roles available in a specific group +func (c *Client) GetAvailableGroupClientRoles(accessToken string, realmName string, groupID string, clientID string) ([]RoleRepresentation, error) { + var roles = []RoleRepresentation{} + var err = c.get(accessToken, &roles, url.Path(availableGroupClientRoleMappingPath), url.Param("realm", realmName), url.Param("id", groupID), url.Param("clientId", clientID)) + return roles, err +}