コード例 #1
0
        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);
        }
コード例 #2
0
        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();
            }
        }
コード例 #3
0
        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();
            }
        }
コード例 #4
0
        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);
                }
            }
        }
コード例 #5
0
        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);
            }
        }