async Task OrderCreationOfStudySpecificDatasetStorageAccount(Study study, Dataset dataset, CloudResource resourceGroup, string clientIp, ProvisioningQueueParentDto queueParent, CancellationToken cancellationToken)
        {
            try
            {
                if (resourceGroup == null)
                {
                    throw new ArgumentNullException("resourceGroup", "Resource group entry is null");
                }

                _logger.LogInformation($"CreateResourcesForStudySpecificDataset - Dataset Id: {dataset.Id}");

                var currentUser = await _userService.GetCurrentUserAsync();

                var tagsForStorageAccount = ResourceTagFactory.StudySpecificDatasourceStorageAccountTags(_config, study, dataset.Name);
                var storageAccountName    = AzureResourceNameUtil.StudySpecificDataSetStorageAccount(dataset.Name);

                var resourceEntry = await _cloudResourceCreateService.CreateStudySpecificDatasetEntryAsync(dataset.Id, resourceGroup.Id, resourceGroup.Region, resourceGroup.ResourceGroupName, storageAccountName, tagsForStorageAccount);

                ProvisioningQueueUtil.CreateChildAndAdd(queueParent, resourceEntry);

                var serverPublicIp = await _publicIpService.GetIp();

                DatasetFirewallUtils.EnsureDatasetHasFirewallRules(_logger, currentUser, dataset, clientIp, serverPublicIp);

                await _db.SaveChangesAsync();

                var stateForFirewallOperation = DatasetFirewallUtils.TranslateAllowedIpsToOperationDesiredState(dataset.FirewallRules.ToList());

                var createStorageAccountOperation = CloudResourceOperationUtil.GetCreateOperation(resourceEntry);
                var firewallUpdateOperation       = await _cloudResourceOperationCreateService.CreateUpdateOperationAsync(resourceEntry.Id, CloudResourceOperationType.ENSURE_FIREWALL_RULES, dependsOn : createStorageAccountOperation.Id, desiredState : stateForFirewallOperation);

                ProvisioningQueueUtil.CreateChildAndAdd(queueParent, firewallUpdateOperation);

                var stateForCorsRules   = DatasetCorsUtils.CreateDatasetCorsRules(_config);
                var corsUpdateOperation = await _cloudResourceOperationCreateService.CreateUpdateOperationAsync(resourceEntry.Id, CloudResourceOperationType.ENSURE_CORS_RULES, dependsOn : firewallUpdateOperation.Id, desiredState : stateForCorsRules);

                ProvisioningQueueUtil.CreateChildAndAdd(queueParent, corsUpdateOperation);
            }
            catch (Exception ex)
            {
                throw new Exception($"Failed to schedule creation of Azure Storage Account", ex);
            }
        }
Esempio n. 2
0
        async Task <Dictionary <string, string> > GetIPsAsync(HttpContext context, CancellationToken cancellation = default)
        {
            try
            {
                var remoteIpAddress = context.Connection.RemoteIpAddress;
                var localIpAddress  = context.Connection.LocalIpAddress;

                var response = new Dictionary <string, string>()
                {
                    { "Server public ip from 3rd party", await _publicIpService.GetIp() },
                    { "context.Connection.RemoteIpAddress", remoteIpAddress.ToString() },
                    { "context.Connection.RemoteIpAddress MapToIPv4", remoteIpAddress.MapToIPv4().ToString() },
                    { "context.Connection.RemoteIpAddress MapToIPv6", remoteIpAddress.MapToIPv6().ToString() },
                    { "context.Connection.RemoteIpAddress AddressFamily", remoteIpAddress.AddressFamily.ToString() },
                    { "context.Connection.LocalIpAddress", localIpAddress.ToString() },
                    { "context.Connection.LocalIpAddress MapToIPv4", localIpAddress.MapToIPv4().ToString() },
                    { "context.Connection.LocalIpAddress MapToIPv6", localIpAddress.MapToIPv6().ToString() },
                    { "context.Connection.LocalIpAddress AddressFamily", localIpAddress.AddressFamily.ToString() },
                };

                var counter = 0;

                foreach (var curDns in Dns.GetHostEntry(remoteIpAddress).AddressList)
                {
                    try
                    {
                        var description = $"{curDns} | family: {curDns.AddressFamily}";

                        if (curDns.AddressFamily == System.Net.Sockets.AddressFamily.InterNetworkV6)
                        {
                            description += $" | v4: {curDns.MapToIPv4()}";
                        }

                        response.Add($"fromDns[{counter}]", description);
                        counter++;
                    }
                    catch (Exception)
                    {
                    }
                }

                return(response);
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, $"Health check for Client IPs failed");
            }

            return(null);
        }