Skip to content

Commit

Permalink
Merge pull request #91 from RedHatInsights/master
Browse files Browse the repository at this point in the history
Current master into security-compliance
  • Loading branch information
coderbydesign authored Jun 29, 2023
2 parents 832f2d3 + 6c31651 commit 43ccced
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 3 deletions.
2 changes: 1 addition & 1 deletion internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func Get() *MbopConfig {
Debug: debug,

KeyCloakUserServiceHost: fetchWithDefault("KEYCLOAK_USER_SERVICE_HOST", "localhost"),
KeyCloakUserServicePort: fetchWithDefault("KEYCLOAK_USER_SERVICE_PORT", ":8000"),
KeyCloakUserServicePort: fetchWithDefault("KEYCLOAK_USER_SERVICE_PORT", ":8443"),
KeyCloakUserServiceScheme: fetchWithDefault("KEYCLOAK_USER_SERVICE_SCHEME", "http"),
KeyCloakUserServiceTimeout: userServiceTimeout,
KeyCloakTimeout: keyCloakTimeout,
Expand Down
2 changes: 1 addition & 1 deletion internal/handlers/accounts_v3_usersBy_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ func AccountsV3UsersByHandler(w http.ResponseWriter, r *http.Request) {
}
}

sendJSON(w, usersToV3Response(u.Users))
sendJSON(w, u.Users)
default:
// mbop server instance injected somewhere
// pass right through to the current handler
Expand Down
6 changes: 5 additions & 1 deletion internal/service/keycloak-user-service/user_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,12 @@ func createV3UsersRequestURL(orgID string, q models.UserV3Query) (*url.URL, erro
}
queryParams := url.Query()

// default ordering
queryParams.Add("order", "username")
queryParams.Add("direction", "asc")

if q.SortOrder != "" {
queryParams.Add("direction", q.SortOrder)
queryParams.Set("direction", q.SortOrder)
}

queryParams.Add("org_id", orgID)
Expand Down
32 changes: 32 additions & 0 deletions internal/service/mailer/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"github.com/redhatinsights/mbop/internal/config"
l "github.com/redhatinsights/mbop/internal/logger"
"github.com/redhatinsights/mbop/internal/models"
"github.com/redhatinsights/mbop/internal/service/keycloak"
keycloakuserservice "github.com/redhatinsights/mbop/internal/service/keycloak-user-service"
"github.com/redhatinsights/mbop/internal/service/ocm"
"golang.org/x/exp/maps"
)
Expand Down Expand Up @@ -60,6 +62,36 @@ func LookupEmailsForUsernames(ctx context.Context, email *models.Email) error {
for _, user := range users.Users {
toLookup[user.Username] = user.Email
}
case "keycloak":
keycloakClient := keycloak.NewKeyCloakClient()
err := keycloakClient.InitKeycloakConnection()
if err != nil {
return err
}

token, err := keycloakClient.GetAccessToken()
if err != nil {
return err
}

userServiceClient, err := keycloakuserservice.NewKeyCloakUserServiceClient()
if err != nil {
return err
}

err = userServiceClient.InitKeycloakUserServiceConnection()
if err != nil {
return err
}

u, err := userServiceClient.GetUsers(token, models.UserBody{Users: maps.Keys(toLookup)}, models.UserV1Query{})
if err != nil {
return err
}

for _, user := range u.Users {
toLookup[user.Username] = user.Email
}
case "mock":
for k := range toLookup {
toLookup[k] = k + "@mocked.biz"
Expand Down

0 comments on commit 43ccced

Please sign in to comment.