Skip to content

Commit

Permalink
fix(ci): Ensure unmanaged attributes is enabled during kc provisioning (
Browse files Browse the repository at this point in the history
#1002)

Enable "unmanaged attributes" even if the realm already exists
resolves #994
  • Loading branch information
elizabethhealy authored Jun 18, 2024
1 parent 55bdfeb commit 58393ef
Showing 1 changed file with 21 additions and 20 deletions.
41 changes: 21 additions & 20 deletions lib/fixtures/keycloak.go
Original file line number Diff line number Diff line change
Expand Up @@ -484,33 +484,34 @@ func createRealm(ctx context.Context, kcConnectParams KeycloakConnectParams, rea
}
}

if r == nil { //nolint:nestif // realm doesnt already exist
if r == nil {
if _, err := client.CreateRealm(ctx, token.AccessToken, realm); err != nil {
return err
}
slog.Info("✅ Realm created", slog.String("realm", *realm.Realm))

// update realm users profile via upconfig
realmProfileURL := fmt.Sprintf("%s/admin/realms/%s/users/profile", kcConnectParams.BasePath, *realm.Realm)
realmUserProfileResp, err := client.GetRequestWithBearerAuth(ctx, token.AccessToken).Get(realmProfileURL)
if err != nil {
slog.Error("Error retrieving realm users profile ", slog.String("realm", *realm.Realm))
return err
}
var upConfig map[string]interface{}
err = json.Unmarshal([]byte(realmUserProfileResp.String()), &upConfig)
if err != nil {
return err
}
upConfig["unmanagedAttributePolicy"] = "ENABLED"
_, err = client.GetRequestWithBearerAuth(ctx, token.AccessToken).SetBody(upConfig).Put(realmProfileURL)
if err != nil {
return err
}
slog.Info("✅ Realm Users Profile Updated", slog.String("realm", *realm.Realm))
} else {
slog.Info("⏭️ Realm already exists", slog.String("realm", *realm.Realm))
}

// update realm users profile via upconfig
realmProfileURL := fmt.Sprintf("%s/admin/realms/%s/users/profile", kcConnectParams.BasePath, *realm.Realm)
realmUserProfileResp, err := client.GetRequestWithBearerAuth(ctx, token.AccessToken).Get(realmProfileURL)
if err != nil {
slog.Error("Error retrieving realm users profile ", slog.String("realm", *realm.Realm))
return err
}
var upConfig map[string]interface{}
err = json.Unmarshal([]byte(realmUserProfileResp.String()), &upConfig)
if err != nil {
return err
}
upConfig["unmanagedAttributePolicy"] = "ENABLED"
_, err = client.GetRequestWithBearerAuth(ctx, token.AccessToken).SetBody(upConfig).Put(realmProfileURL)
if err != nil {
return err
}
slog.Info("✅ Realm Users Profile Updated", slog.String("realm", *realm.Realm))

return nil
}

Expand Down

0 comments on commit 58393ef

Please sign in to comment.