public async Task RunActivity( [ActivityTrigger] IDurableActivityContext functionContext) { if (functionContext is null) { throw new ArgumentNullException(nameof(functionContext)); } var project = functionContext.GetInput <Project>(); var keyVault = await azureResourceService .GetResourceAsync <AzureKeyVaultResource>(project.KeyVault.VaultId, throwIfNotExists : true) .ConfigureAwait(false); var projectIdentityJson = await keyVault .GetSecretAsync(nameof(ProjectIdentity)) .ConfigureAwait(false); if (!string.IsNullOrEmpty(projectIdentityJson)) { await azureDirectoryService .DeleteServicePrincipalAsync(project.Id.ToString()) .ConfigureAwait(false); } await keyVault .SetSecretAsync(nameof(ProjectIdentity), null) .ConfigureAwait(false); }
public async Task RunActivity( [ActivityTrigger] IDurableActivityContext activityContext, ILogger log) { if (activityContext is null) { throw new ArgumentNullException(nameof(activityContext)); } try { var project = activityContext.GetInput <ProjectDocument>(); if (!string.IsNullOrEmpty(project.Identity?.Id)) { await azureDirectoryService .DeleteServicePrincipalAsync(project.Id.ToString()) .ConfigureAwait(false); } } catch (Exception exc) { log.LogError(exc, $"{nameof(ProjectIdentityDeleteActivity)} failed with error: {exc.Message}"); throw exc.AsSerializable(); } }
public async Task <ProjectIdentity> RunActivity( [ActivityTrigger] IDurableActivityContext activityContext, ILogger log) { if (activityContext is null) { throw new ArgumentNullException(nameof(activityContext)); } try { var project = activityContext.GetInput <ProjectDocument>(); if (string.IsNullOrEmpty(project.Identity?.Id)) { var servicePrincipal = await azureDirectoryService .CreateServicePrincipalAsync(project.Id.ToString()) .ConfigureAwait(false); try { var projectIdentity = new ProjectIdentity { Id = servicePrincipal.ObjectId.ToString(), ApplicationId = servicePrincipal.ApplicationId, TenantId = servicePrincipal.TenantId, Secret = servicePrincipal.Password }; return(projectIdentity); } catch { await azureDirectoryService .DeleteServicePrincipalAsync(project.Id.ToString()) .ConfigureAwait(false); } } return(project.Identity); } catch (Exception exc) { log.LogError(exc, $"{nameof(ProjectIdentityCreateActivity)} failed with error: {exc.Message}"); throw exc.AsSerializable(); } }
public async Task RunActivity( [ActivityTrigger] IDurableActivityContext functionContext) { if (functionContext is null) { throw new ArgumentNullException(nameof(functionContext)); } var project = functionContext.GetInput <Project>(); var keyVault = await azureResourceService .GetResourceAsync <AzureKeyVaultResource>(project.KeyVault.VaultId, throwIfNotExists : true) .ConfigureAwait(false); var projectIdentityJson = await keyVault .GetSecretAsync(nameof(ProjectIdentity)) .ConfigureAwait(false); if (string.IsNullOrEmpty(projectIdentityJson)) { var servicePrincipal = await azureDirectoryService .CreateServicePrincipalAsync(project.Id.ToString()) .ConfigureAwait(false); try { var projectIdentity = new ProjectIdentity() { Id = servicePrincipal.ObjectId.ToString(), ApplicationId = servicePrincipal.ApplicationId, Secret = servicePrincipal.Password }; projectIdentityJson = JsonConvert.SerializeObject(projectIdentity); await keyVault .SetSecretAsync(nameof(ProjectIdentity), projectIdentityJson) .ConfigureAwait(false); } catch { await azureDirectoryService .DeleteServicePrincipalAsync(project.Id.ToString()) .ConfigureAwait(false); } } }
public async Task RunActivity( [ActivityTrigger] IDurableActivityContext functionContext) { if (functionContext is null) { throw new ArgumentNullException(nameof(functionContext)); } var project = functionContext.GetInput <ProjectDocument>(); if (!string.IsNullOrEmpty(project.Identity?.Id)) { await azureDirectoryService .DeleteServicePrincipalAsync(project.Id.ToString()) .ConfigureAwait(false); } }