Skip to content

Commit

Permalink
code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
markusheiliger committed May 20, 2022
1 parent 27936b9 commit 76a9e92
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 19 deletions.
47 changes: 29 additions & 18 deletions src/TeamCloud.Adapters/AdapterWithIdentity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,35 @@ namespace TeamCloud.Adapters;

public abstract class AdapterWithIdentity : Adapter, IAdapterIdentity
{
private readonly IAzureService azure;
private readonly IAzureService azureService;
private readonly IGraphService graphService;
private readonly IOrganizationRepository organizationRepository;
private readonly IProjectRepository projectRepository;

#pragma warning disable CS0618 // Type or member is obsolete

protected AdapterWithIdentity(IAuthorizationSessionClient sessionClient,
IAuthorizationTokenClient tokenClient,
IDistributedLockManager distributedLockManager,
IAzureService azure,
IGraphService graphService,
IOrganizationRepository organizationRepository,
IDeploymentScopeRepository deploymentScopeRepository,
IProjectRepository projectRepository,
IUserRepository userRepository) : base(sessionClient, tokenClient, distributedLockManager, azure, graphService, organizationRepository, deploymentScopeRepository, projectRepository, userRepository)
protected AdapterWithIdentity(
IAuthorizationSessionClient sessionClient,
IAuthorizationTokenClient tokenClient,
IDistributedLockManager distributedLockManager,
IAzureService azureService,
IGraphService graphService,
IOrganizationRepository organizationRepository,
IDeploymentScopeRepository deploymentScopeRepository,
IProjectRepository projectRepository,
IUserRepository userRepository)
: base(
sessionClient,
tokenClient,
distributedLockManager,
azureService,
graphService,
organizationRepository,
deploymentScopeRepository,
projectRepository,
userRepository)
{
this.azure = azure ?? throw new ArgumentNullException(nameof(azure));
this.azureService = azureService ?? throw new ArgumentNullException(nameof(azureService));
this.graphService = graphService ?? throw new ArgumentNullException(nameof(graphService));
this.organizationRepository = organizationRepository ?? throw new ArgumentNullException(nameof(organizationRepository));
this.projectRepository = projectRepository ?? throw new ArgumentNullException(nameof(projectRepository));
Expand Down Expand Up @@ -82,7 +93,7 @@ public virtual async Task<AzureServicePrincipal> GetServiceIdentityAsync(Compone
.GetAsync(component.Organization, component.ProjectId)
.ConfigureAwait(false);

var secretClient = await azure.KeyVaults
var secretClient = await azureService.KeyVaults
.GetSecretClientAsync(project.SecretsVaultId, ensureIdentityAccess: true)
.ConfigureAwait(false);

Expand All @@ -96,7 +107,7 @@ public virtual async Task<AzureServicePrincipal> GetServiceIdentityAsync(Compone
.GetAsync(component.Organization, component.ProjectId)
.ConfigureAwait(false);

var secretClient = await azure.KeyVaults
var secretClient = await azureService.KeyVaults
.GetSecretClientAsync(project.SecretsVaultId, ensureIdentityAccess: true)
.ConfigureAwait(false);

Expand Down Expand Up @@ -134,7 +145,7 @@ public virtual async Task<AzureServicePrincipal> GetServiceIdentityAsync(Deploym
.CreateServicePrincipalAsync(servicePrincipalName)
.ConfigureAwait(false);
}
else if (servicePrincipal.ExpiresOn.GetValueOrDefault(DateTime.MinValue) < DateTime.UtcNow)
else if (servicePrincipal.ExpiresOn.GetValueOrDefault(DateTime.MinValue.ToUniversalTime()) < DateTime.UtcNow)
{
// a service principal exists, but its secret is expired. lets refresh
// the service principal (create a new secret) so we can move on
Expand All @@ -147,15 +158,15 @@ public virtual async Task<AzureServicePrincipal> GetServiceIdentityAsync(Deploym

if (!string.IsNullOrEmpty(servicePrincipal.Password))
{
var tenantId = await azure
var tenantId = await azureService
.GetTenantIdAsync()
.ConfigureAwait(false);

var organization = await organizationRepository
.GetAsync(tenantId, deploymentScope.Organization)
.ConfigureAwait(false);

var secretClient = await azure.KeyVaults
var secretClient = await azureService.KeyVaults
.GetSecretClientAsync(organization.SecretsVaultId, ensureIdentityAccess: true)
.ConfigureAwait(false);

Expand All @@ -165,15 +176,15 @@ public virtual async Task<AzureServicePrincipal> GetServiceIdentityAsync(Deploym
}
else if (withPassword)
{
var tenantId = await azure
var tenantId = await azureService
.GetTenantIdAsync()
.ConfigureAwait(false);

var organization = await organizationRepository
.GetAsync(tenantId, deploymentScope.Organization)
.ConfigureAwait(false);

var secretClient = await azure.KeyVaults
var secretClient = await azureService.KeyVaults
.GetSecretClientAsync(organization.SecretsVaultId, ensureIdentityAccess: true)
.ConfigureAwait(false);

Expand Down
1 change: 0 additions & 1 deletion src/TeamCloud.Orchestrator/Command/CommandOrchestration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ public CommandOrchestration(ICommandHandler[] commandHandlers)
this.commandHandlers = commandHandlers;
}

// [Deterministic]
[FunctionName(nameof(CommandOrchestration))]
public async Task Execute(
[OrchestrationTrigger] IDurableOrchestrationContext orchestratorContext,
Expand Down

0 comments on commit 76a9e92

Please sign in to comment.