private static AzureEnvironment MapArmToAzureEnvironment()

in src/Authentication.Abstractions/AzureEnvironment.cs [156:248]


        private static AzureEnvironment MapArmToAzureEnvironment(ArmMetadata armMetadata)
        {
            var azureEnvironment = new AzureEnvironment
            {
                Name = armMetadata.Name,
                PublishSettingsFileUrl = GetPublishSettingsFileUrl(armMetadata.Name),
                ServiceManagementUrl = armMetadata.Authentication.Audiences[0],
                ResourceManagerUrl = armMetadata.ResourceManager,
                ManagementPortalUrl = armMetadata.Portal,
                ActiveDirectoryAuthority = armMetadata.Authentication.LoginEndpoint,
                ActiveDirectoryServiceEndpointResourceId = armMetadata.Authentication.Audiences[0],
                StorageEndpointSuffix = armMetadata.Suffixes.Storage,
                GalleryUrl = armMetadata.Gallery,
                SqlDatabaseDnsSuffix = armMetadata.Suffixes.SqlServerHostname,
                GraphUrl = armMetadata.Graph,
                //TODO, ARM endpoint doesn't have TrafficManagerDnsSuffix
                TrafficManagerDnsSuffix = GetTrafficManagerDnsSuffix(armMetadata.Name),
                AzureKeyVaultDnsSuffix = armMetadata.Suffixes.KeyVaultDns,
                //Default ARM endpoint doens't provide KeyVault service resource id. Keep it here just in case.
                AzureKeyVaultServiceEndpointResourceId = GetKeyVaultServiceEndpointResourceId(armMetadata.Name),
                AzureDataLakeAnalyticsCatalogAndJobEndpointSuffix = armMetadata.Suffixes.AzureDataLakeAnalyticsCatalogAndJob,
                AzureDataLakeStoreFileSystemEndpointSuffix = armMetadata.Suffixes.AzureDataLakeStoreFileSystem,
                DataLakeEndpointResourceId = armMetadata.ActiveDirectoryDataLake,
                GraphEndpointResourceId = armMetadata.Graph,
                BatchEndpointResourceId = armMetadata.Batch,
                AdTenant = armMetadata.Authentication.Tenant,
                ContainerRegistryEndpointSuffix = armMetadata.Suffixes.AcrLoginServer
            };

            //We reuse the value of KeyVaultDns
            if (string.IsNullOrEmpty(azureEnvironment.AzureKeyVaultServiceEndpointResourceId))
            {
                azureEnvironment.AzureKeyVaultServiceEndpointResourceId = $"https://{azureEnvironment.AzureKeyVaultDnsSuffix}";
            }

            // There are mismatches between metadata built in Azure PowerShell/CLI and from ARM endpoint.
            // Considering compatibility, below hard coded logic accommodates those mismatches
            // SqlDatabaseDnsSuffix requires value leading with period
            // ServiceManagementUrl as audience needs to end with slash
            if (azureEnvironment.SqlDatabaseDnsSuffix != null && !azureEnvironment.SqlDatabaseDnsSuffix.StartsWith("."))
            {
                azureEnvironment.SqlDatabaseDnsSuffix = "." + azureEnvironment.SqlDatabaseDnsSuffix;
            }
            if (azureEnvironment.ServiceManagementUrl != null && !azureEnvironment.ServiceManagementUrl.EndsWith("/"))
            {
                azureEnvironment.ServiceManagementUrl += "/";
            }

            if (!string.IsNullOrEmpty(armMetadata.MicrosoftGraphResourceId))
            {
                azureEnvironment.SetProperty(ExtendedEndpoint.MicrosoftGraphEndpointResourceId, armMetadata.MicrosoftGraphResourceId);
                // ARM endpoint only gives us graph resource ID (with ending slash "/"),
                // we assume the Url (endpoint to where we send requests) equals the resource ID without the slash
                if (armMetadata.MicrosoftGraphResourceId.EndsWith("/"))
                {
                    azureEnvironment.SetProperty(ExtendedEndpoint.MicrosoftGraphUrl,
                        armMetadata.MicrosoftGraphResourceId.TrimEnd('/'));
                }
            }

            if (!string.IsNullOrEmpty(armMetadata.AttestationResourceId))
            {
                azureEnvironment.SetProperty(ExtendedEndpoint.AzureAttestationServiceEndpointResourceId, armMetadata.AttestationResourceId);
                if (!string.IsNullOrEmpty(armMetadata.Suffixes.AttestationEndpoint))
                {
                    azureEnvironment.SetProperty(ExtendedEndpoint.AzureAttestationServiceEndpointSuffix, armMetadata.Suffixes.AttestationEndpoint);
                }
            }

            if (!string.IsNullOrEmpty(armMetadata.SynapseAnalyticsResourceId))
            {
                azureEnvironment.SetProperty(ExtendedEndpoint.AzureSynapseAnalyticsEndpointResourceId, armMetadata.SynapseAnalyticsResourceId);
                if (!string.IsNullOrEmpty(armMetadata.Suffixes.SynapseAnalytics))
                {
                    azureEnvironment.SetProperty(ExtendedEndpoint.AzureSynapseAnalyticsEndpointSuffix, armMetadata.Suffixes.SynapseAnalytics);
                }
            }

            if (!string.IsNullOrEmpty(armMetadata.LogAnalyticsResourceId))
            {
                azureEnvironment.SetProperty(ExtendedEndpoint.OperationalInsightsEndpointResourceId, armMetadata.LogAnalyticsResourceId);
                azureEnvironment.SetProperty(ExtendedEndpoint.OperationalInsightsEndpoint, $"{armMetadata.LogAnalyticsResourceId}/v1");
            }

            //ManagedHsmServiceEndpointSuffix currently uses Built-in endpoint.
            //In new ArmMedata, ManagedHsmServiceEndpointSuffix is provided as so 'MhsmDns'.
            //But it doesn't' make sense to just refresh ManagedHsmServiceEndpointSuffix from ARM without AzureManagedHsmServiceEndpointResourceId.
            //If we want to refresh AzureManagedHsmServiceEndpointResourceId with reference to ManagedHsmServiceEndpointSuffix,
            //we need to check with Arm team and service team. And so we can do this when we receive the request from the service team.
            //ContainerRegistryEndpointSuffix(AcrLoginServer) is the same case.

            return azureEnvironment;
        }