Skip to content

Commit

Permalink
Merge 0e534f5 into 2859535
Browse files Browse the repository at this point in the history
  • Loading branch information
bsoniam committed Sep 11, 2019
2 parents 2859535 + 0e534f5 commit 0923776
Show file tree
Hide file tree
Showing 22 changed files with 206 additions and 151 deletions.
2 changes: 1 addition & 1 deletion Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Gopkg.toml
Expand Up @@ -27,11 +27,11 @@

[[constraint]]
name = "github.com/cloudtrust/common-service"
version = "v1.0-rc6"
branch = "error-handling"

[[constraint]]
name = "github.com/cloudtrust/keycloak-client"
version = "v1.0-rc5"
branch = "error-handling"

[[constraint]]
name = "github.com/go-kit/kit"
Expand Down
41 changes: 21 additions & 20 deletions api/management/api.go
Expand Up @@ -5,6 +5,7 @@ import (
"regexp"
"strconv"

internal "github.com/cloudtrust/keycloak-bridge/internal/keycloakb"
kc "github.com/cloudtrust/keycloak-client"
)

Expand Down Expand Up @@ -231,59 +232,59 @@ func ConvertToKCUser(user UserRepresentation) kc.UserRepresentation {
// Validate is a validator for UserRepresentation
func (user UserRepresentation) Validate() error {
if user.Id != nil && !matchesRegExp(*user.Id, RegExpID) {
return errors.New("Invalid user ID")
return errors.New(internal.MsgErrInvalidParam + "." + internal.UserId)
}

if user.Username != nil && !matchesRegExp(*user.Username, RegExpUsername) {
return errors.New("Invalid username")
return errors.New(internal.MsgErrInvalidParam + "." + internal.Username)
}

if user.Email != nil && !matchesRegExp(*user.Email, RegExpEmail) {
return errors.New("Invalid email")
return errors.New(internal.MsgErrInvalidParam + "." + internal.Email)
}

if user.FirstName != nil && !matchesRegExp(*user.FirstName, RegExpFirstName) {
return errors.New("Invalid firstname")
return errors.New(internal.MsgErrInvalidParam + "." + internal.Firstname)
}

if user.LastName != nil && !matchesRegExp(*user.LastName, RegExpLastName) {
return errors.New("Invalid lastname")
return errors.New(internal.MsgErrInvalidParam + "." + internal.Lastname)
}

if user.PhoneNumber != nil && !matchesRegExp(*user.PhoneNumber, RegExpPhoneNumber) {
return errors.New("Invalid phone number")
return errors.New(internal.MsgErrInvalidParam + "." + internal.PhoneNumber)
}

if user.Label != nil && !matchesRegExp(*user.Label, RegExpLabel) {
return errors.New("Invalid label")
return errors.New(internal.MsgErrInvalidParam + "." + internal.Label)
}

if user.Gender != nil && !matchesRegExp(*user.Gender, RegExpGender) {
return errors.New("Invalid gender")
return errors.New(internal.MsgErrInvalidParam + "." + internal.Gender)
}

if user.BirthDate != nil && !matchesRegExp(*user.BirthDate, RegExpBirthDate) {
return errors.New("Invalid birthdate")
return errors.New(internal.MsgErrInvalidParam + "." + internal.Birthdate)
}

if user.Groups != nil {
for _, groupID := range *(user.Groups) {
if !matchesRegExp(groupID, RegExpID) {
return errors.New("Invalid group ID")
return errors.New(internal.MsgErrInvalidParam + "." + internal.GroudId)
}
}
}

if user.Roles != nil {
for _, roleID := range *(user.Roles) {
if !matchesRegExp(roleID, RegExpID) {
return errors.New("Invalid role ID")
return errors.New(internal.MsgErrInvalidParam + "." + internal.RoleId)
}
}
}

if user.Locale != nil && !matchesRegExp(*user.Locale, RegExpLocale) {
return errors.New("Invalid locale")
return errors.New(internal.MsgErrInvalidParam + "." + internal.Locale)
}

return nil
Expand All @@ -292,19 +293,19 @@ func (user UserRepresentation) Validate() error {
// Validate is a validator for RoleRepresentation
func (role RoleRepresentation) Validate() error {
if role.Id != nil && !matchesRegExp(*role.Id, RegExpID) {
return errors.New("Invalid role ID")
return errors.New(internal.MsgErrInvalidParam + "." + internal.RoleId)
}

if role.Name != nil && !matchesRegExp(*role.Name, RegExpName) {
return errors.New("Invalid username")
return errors.New(internal.MsgErrInvalidParam + "." + internal.Username)
}

if role.Description != nil && !matchesRegExp(*role.Description, RegExpDescription) {
return errors.New("Invalid description")
return errors.New(internal.MsgErrInvalidParam + "." + internal.Description)
}

if role.ContainerId != nil && !matchesRegExp(*role.ContainerId, RegExpID) {
return errors.New("Invalid container ID")
return errors.New(internal.MsgErrInvalidParam + "." + internal.ContainerId)
}

return nil
Expand All @@ -313,7 +314,7 @@ func (role RoleRepresentation) Validate() error {
// Validate is a validator for PasswordRepresentation
func (password PasswordRepresentation) Validate() error {
if password.Value != nil && !matchesRegExp(*password.Value, RegExpPassword) {
return errors.New("Invalid password")
return errors.New(internal.MsgErrInvalidParam + "." + internal.Password)
}

return nil
Expand All @@ -322,11 +323,11 @@ func (password PasswordRepresentation) Validate() error {
// Validate is a validator for RealmCustomConfiguration
func (config RealmCustomConfiguration) Validate() error {
if config.DefaultClientId != nil && !matchesRegExp(*config.DefaultClientId, RegExpClientID) {
return errors.New("Invalid default client ID")
return errors.New(internal.MsgErrInvalidParam + "." + internal.DefaultClientID)
}

if config.DefaultRedirectUri != nil && !matchesRegExp(*config.DefaultRedirectUri, RegExpRedirectURI) {
return errors.New("Invalid default redirect uri")
return errors.New(internal.MsgErrInvalidParam + "." + internal.DefaultRedirectURI)
}

return nil
Expand All @@ -335,7 +336,7 @@ func (config RealmCustomConfiguration) Validate() error {
// Validate is a validator for RequiredAction
func (requiredAction RequiredAction) Validate() error {
if requiredAction != "" && !matchesRegExp(string(requiredAction), RegExpRequiredAction) {
return errors.New("Invalid required action")
return errors.New(internal.MsgErrInvalidParam + "." + internal.RequiredAction)
}

return nil
Expand Down

0 comments on commit 0923776

Please sign in to comment.