Skip to content

Commit

Permalink
feat: adjust technical user creation check
Browse files Browse the repository at this point in the history
Refs: #1240
  • Loading branch information
Phil91 committed Jan 22, 2025
1 parent 7effc86 commit b6ad2d4
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 22 deletions.
4 changes: 0 additions & 4 deletions src/marketplace/Services.Service/ServiceSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,6 @@ public class ServiceSettings
[DistinctValues("x => x.ClientId")]
public IEnumerable<UserRoleConfig> DimUserRoles { get; set; } = null!;

[Required]
[DistinctValues("x => x.ClientId")]
public IEnumerable<UserRoleConfig> UserRolesAccessibleByProviderOnly { get; set; } = null!;

[Required(AllowEmptyStrings = true)]
public string DecentralIdentityManagementAuthUrl { get; set; } = null!;

Expand Down

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

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/********************************************************************************
* Copyright (c) 2024 Contributors to the Eclipse Foundation
/********************************************************************************
* Copyright (c) 2025 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/********************************************************************************
* Copyright (c) 2024 Contributors to the Eclipse Foundation
/********************************************************************************
* Copyright (c) 2023 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,21 +63,15 @@ public class TechnicalUserCreation(
var userProviderRoles = _settings.UserRolesAccessibleByProviderOnly.SelectMany(x => x.UserRoleNames.Select(userRoleName => (x.ClientId, userRoleName)));

var serviceAccounts = ImmutableList.CreateBuilder<CreatedServiceAccountData>();

var typeId = userRoleData.IntersectBy(userProviderRoles, providerData => (providerData.ClientClientId, providerData.UserRoleText)).Any() && technicalUserTypeId == TechnicalUserTypeId.MANAGED
? TechnicalUserTypeId.PROVIDER_OWNED
: technicalUserTypeId;
if (userRoleData.ExceptBy(dimConfigRoles, roleData => (roleData.ClientClientId, roleData.UserRoleText)).IfAny(
async roleData =>
{
var keycloakRoleData = roleData.ToImmutableList();
var (clientId, enhancedName, serviceAccountData) = await CreateKeycloakServiceAccount(bpns, enhanceTechnicalUserName, enabled, name, description, iamClientAuthMethod, keycloakRoleData).ConfigureAwait(ConfigureAwaitOptions.None);
var serviceAccountId = Guid.Empty;
if (!(userRoleData.IntersectBy(userProviderRoles, providerData => (providerData.ClientClientId, providerData.UserRoleText)).Any() && technicalUserTypeId == TechnicalUserTypeId.MANAGED))
{
serviceAccountId = CreateDatabaseServiceAccount(companyId, UserStatusId.ACTIVE, technicalUserTypeId, TechnicalUserKindId.INTERNAL, name, clientId, description, keycloakRoleData, technicalUserRepository, userRolesRepository, setOptionalParameter);
}
else
{
serviceAccountId = CreateDatabaseServiceAccount(companyId, UserStatusId.ACTIVE, TechnicalUserTypeId.PROVIDER_OWNED, TechnicalUserKindId.INTERNAL, name, clientId, description, keycloakRoleData, technicalUserRepository, userRolesRepository, setOptionalParameter);
}
var serviceAccountId = CreateDatabaseServiceAccount(companyId, UserStatusId.ACTIVE, typeId, TechnicalUserKindId.INTERNAL, name, clientId, description, keycloakRoleData, technicalUserRepository, userRolesRepository, setOptionalParameter);
serviceAccounts.Add(new CreatedServiceAccountData(
serviceAccountId,
enhancedName,
Expand All @@ -98,7 +92,7 @@ public class TechnicalUserCreation(
{
var dimRoleData = roleData.ToImmutableList();
var dimSaName = $"dim-{name}";
var dimServiceAccountId = CreateDatabaseServiceAccount(companyId, UserStatusId.PENDING, technicalUserTypeId, TechnicalUserKindId.EXTERNAL, dimSaName, null, description, dimRoleData, technicalUserRepository, userRolesRepository, setOptionalParameter);
var dimServiceAccountId = CreateDatabaseServiceAccount(companyId, UserStatusId.PENDING, typeId, TechnicalUserKindId.EXTERNAL, dimSaName, null, description, dimRoleData, technicalUserRepository, userRolesRepository, setOptionalParameter);
var processStepRepository = portalRepositories.GetInstance<IProcessStepRepository>();
if (processData?.ProcessTypeId is not null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ public async Task CreateServiceAccountAsync_WithValidDimData_ReturnsExpected()
}

[Fact]
public async Task CreateServiceAccountAsync_WithValidProviderRolesData_ReturnsExpected()
public async Task CreateServiceAccountAsync_ContainsProviderRolesData_ReturnsExpected()
{
// Arrange
var serviceAccounts = new List<TechnicalUser>();
Expand Down

0 comments on commit b6ad2d4

Please sign in to comment.