Skip to content

Commit

Permalink
feat(technicalUser): add delete technical user
Browse files Browse the repository at this point in the history
  • Loading branch information
Phil91 committed Jun 24, 2024
1 parent adae7ee commit 8982d27
Show file tree
Hide file tree
Showing 25 changed files with 1,140 additions and 36 deletions.
7 changes: 7 additions & 0 deletions src/clients/Dim.Clients/Api/Cf/CfClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -276,4 +276,11 @@ public async Task<ServiceCredentialBindingDetailResponse> GetServiceBindingDetai
throw new ServiceException(je.Message);
}
}

public async Task DeleteServiceInstanceBindings(Guid serviceBindingId, CancellationToken cancellationToken)
{
var client = await _basicAuthTokenService.GetBasicAuthorizedLegacyClient<CfClient>(_settings, cancellationToken).ConfigureAwait(false);
await client.DeleteAsync($"/v3/service_credential_bindings/{serviceBindingId}", cancellationToken)
.CatchingIntoServiceExceptionFor("delete-si-bindings", HttpAsyncResponseMessageExtension.RecoverOptions.ALLWAYS);
}
}
1 change: 1 addition & 0 deletions src/clients/Dim.Clients/Api/Cf/ICfClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,5 @@ public interface ICfClient
Task CreateServiceInstanceBindings(string tenantName, string? keyName, Guid spaceId, CancellationToken cancellationToken);
Task<Guid> GetServiceBinding(string tenantName, Guid spaceId, string bindingName, CancellationToken cancellationToken);
Task<ServiceCredentialBindingDetailResponse> GetServiceBindingDetails(Guid id, CancellationToken cancellationToken);
Task DeleteServiceInstanceBindings(Guid serviceBindingId, CancellationToken cancellationToken);
}
3 changes: 3 additions & 0 deletions src/database/Dim.DbAccess/Repositories/ITenantRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,7 @@ public interface ITenantRepository
Task<(Guid? spaceId, string technicalUserName)> GetSpaceIdAndTechnicalUserName(Guid technicalUserId);
Task<(Guid ExternalId, string? TokenAddress, string? ClientId, byte[]? ClientSecret, byte[]? InitializationVector, int? EncryptionMode)> GetTechnicalUserCallbackData(Guid technicalUserId);
Task<(Guid? DimInstanceId, Guid? CompanyId)> GetDimInstanceIdAndDid(Guid tenantId);
Task<(bool Exists, Guid TechnicalUserId)> GetTechnicalUserForBpn(string bpn, string technicalUserName);
Task<Guid> GetExternalIdForTechnicalUser(Guid technicalUserId);
void RemoveTechnicalUser(Guid technicalUserId);
}
16 changes: 16 additions & 0 deletions src/database/Dim.DbAccess/Repositories/TenantRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,4 +144,20 @@ public void AttachAndModifyTechnicalUser(Guid technicalUserId, Action<TechnicalU
.Where(x => x.Id == tenantId)
.Select(x => new ValueTuple<Guid?, Guid?>(x.DimInstanceId, x.CompanyId))
.SingleOrDefaultAsync();

public Task<(bool Exists, Guid TechnicalUserId)> GetTechnicalUserForBpn(string bpn, string technicalUserName) =>
context.TechnicalUsers
.Where(x => x.TechnicalUserName == technicalUserName && x.Tenant!.Bpn == bpn)
.Select(x => new ValueTuple<bool, Guid>(true, x.Id))
.SingleOrDefaultAsync();

public Task<Guid> GetExternalIdForTechnicalUser(Guid technicalUserId) =>
context.TechnicalUsers
.Where(x => x.Id == technicalUserId)
.Select(x => x.ExternalId)
.SingleOrDefaultAsync();

public void RemoveTechnicalUser(Guid technicalUserId) =>
context.TechnicalUsers
.Remove(new TechnicalUser(technicalUserId, default, default, null!, default));
}
6 changes: 5 additions & 1 deletion src/database/Dim.Entities/Enums/ProcessStepTypeId.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,9 @@ public enum ProcessStepTypeId
// Create Technical User
CREATE_TECHNICAL_USER = 100,
GET_TECHNICAL_USER_DATA = 101,
SEND_TECHNICAL_USER_CALLBACK = 102,
SEND_TECHNICAL_USER_CREATION_CALLBACK = 102,

// Delete Technical User
DELETE_TECHNICAL_USER = 200,
SEND_TECHNICAL_USER_DELETION_CALLBACK = 201
}
3 changes: 2 additions & 1 deletion src/database/Dim.Entities/Enums/ProcessTypeId.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@ namespace Dim.Entities.Enums;
public enum ProcessTypeId
{
SETUP_DIM = 1,
CREATE_TECHNICAL_USER = 2
CREATE_TECHNICAL_USER = 2,
DELETE_TECHNICAL_USER = 3
}
Loading

0 comments on commit 8982d27

Please sign in to comment.