public static async Task InitializeAsync() { // Load secret from local config var secrets = LocalConfigSecretHelper.Load(); foreach (var pair in secrets) { Substitutes.Add(pair.Key, pair.Value); } // Initialize azure environment - only from web.config var azureEnvironmentHelper = new AzureEnvironmentHelper(GetConfiguration("CloudEnvironment")); AzureEnvironmentName = azureEnvironmentHelper.AzureEnvironmentName; AuthenticationEndpoint = azureEnvironmentHelper.AuthenticationEndpoint; ResourceManagerEndpoint = azureEnvironmentHelper.ResourceManagerEndpoint; StorageEndpointSuffix = azureEnvironmentHelper.StorageEndpointSuffix; DeploymentId = ConfigurationManager.AppSettings["DeploymentId"]; if (DeploymentId == "local_debug") { DeploymentId += $"_{Environment.MachineName}"; } // Load configuration - from local config or web.config KeyVaultBaseUri = GetConfiguration("KeyVaultBaseUri"); ApplicationId = GetConfiguration("ApplicationId"); AppCertThumbprint = GetConfiguration("AppCertThumbprint"); // Load secret from key vault if the substitute is not in the local config secrets = await KeyVaultSecretHelper.LoadAsync( KeyVaultBaseUri, ApplicationId, AppCertThumbprint); foreach (var pair in secrets) { if (Substitutes.ContainsKey(pair.Key)) { Trace.TraceInformation($"Secret {pair.Key} from keyVault is ignored due to duplicated one in local config"); continue; } Substitutes.Add(pair.Key, pair.Value); } // Load configuration - from local config, key vault or web.config ApplicationSecret = GetConfiguration("ApplicationSecret"); ReplyUri = GetConfiguration("ReplyUri"); DatabaseConnectionString = GetConfiguration("CCMEDB"); StorageAccountConnectionString = EnsureEndpointSuffix(GetConfiguration("StorageAccountConnectionString")); ConfigStorageAccountConnectionString = EnsureEndpointSuffix(GetConfiguration("ConfigStorageAccountConnectionString")); ApplicationInsightsKey = GetConfiguration("ApplicationInsightsKey"); }
public void ParseAzureEnvironment() { var globalEnv = AzureEnvironmentHelper.ParseAzureEnvironment("AzureGlobalCloud"); Assert.NotNull(globalEnv); var defaultEnv = AzureEnvironmentHelper.ParseAzureEnvironment(""); Assert.Equal(globalEnv, defaultEnv); var germanEnv = AzureEnvironmentHelper.ParseAzureEnvironment("AzureGermanCloud"); Assert.NotEqual(globalEnv, germanEnv); Assert.Throws <Exception>(() => AzureEnvironmentHelper.ParseAzureEnvironment("unknown")); }
public void GetStorageEndpointSuffix() { var azureGlobalCloudSuffix = AzureEnvironmentHelper.GetStorageEndpointSuffix("AzureGlobalCloud"); Assert.False(string.IsNullOrEmpty(azureGlobalCloudSuffix)); Assert.Equal(azureGlobalCloudSuffix, AzureEnvironmentHelper.GetStorageEndpointSuffix("")); Assert.Equal(azureGlobalCloudSuffix, AzureEnvironmentHelper.GetStorageEndpointSuffix("AzureGlobalCloud")); var azureGermanCloudSuffix = AzureEnvironmentHelper.GetStorageEndpointSuffix("AzureGermanCloud"); Assert.False(string.IsNullOrEmpty(azureGermanCloudSuffix)); Assert.NotEqual(azureGlobalCloudSuffix, azureGermanCloudSuffix); Assert.Equal(azureGermanCloudSuffix, AzureEnvironmentHelper.GetStorageEndpointSuffix("azuregermancloud")); Assert.Throws <Exception>(() => AzureEnvironmentHelper.GetStorageEndpointSuffix("a")); }
private static async Task RunAsync(Options opts, string usageReportContent) { var azureEnvironmentHelper = new AzureEnvironmentHelper(opts.AzureEnvironmentName); ParsedUsageReport usageReport = null; string accessToken = null; if (usageReportContent == null) { var authenticationResult = await TokenProvider.AcquireTokenAsync( azureEnvironmentHelper.AuthenticationEndpoint, opts.TenantId, azureEnvironmentHelper.ResourceManagerEndpoint); accessToken = authenticationResult.AccessToken; } else { usageReport = UsageFileHelper.Parse(usageReportContent); } var context = new AssessmentContext( usageReport: usageReport, subscriptionNames: opts.SubscriptionNames, subscriptionIds: opts.SubscriptionIds, resourceGroupNames: opts.ResourceGroupNames, accessToken: accessToken, armBaseUri: azureEnvironmentHelper.ResourceManagerEndpoint, resourceCachePath: opts.ResourceCachePath, configManager: ConfigManagerFactory.CreateStorageAccountConfigManager(Settings.Default.ConnectionString), telemetryManager: new TelemetryManager( new AppInsightsTelemetryProvider(ConfigurationManager.AppSettings["ApplicationInsightsKey"]), new Dictionary <string, string> { { "DeploymentId", $"console_debug_{Environment.MachineName}" } })); var assessmentService = new AssessmentService(); var assessmentReport = await assessmentService.GenerateReportAsync(context, opts.TargetLocation); if (File.Exists(assessmentReport.ReportFilePath)) { Process.Start(assessmentReport.ReportFilePath); } }