| | 1 | | // Copyright (c) Microsoft Corporation. All rights reserved. |
| | 2 | | // Licensed under the MIT License. See License.txt in the project root for license information. |
| | 3 | |
|
| | 4 | | namespace BatchTestCommon |
| | 5 | | { |
| | 6 | | using System; |
| | 7 | | using System.Collections.Generic; |
| | 8 | | using System.Linq; |
| | 9 | |
|
| | 10 | | public static class TestCommon |
| | 11 | | { |
| | 12 | | public class TestConfiguration |
| | 13 | | { |
| | 14 | | public const string BatchSubscriptionEnivronmentSettingName = "MABOM_BatchAccountSubscriptionId"; |
| | 15 | |
|
| | 16 | | public const string BatchManagementUrlEnvironmentSettingName = "MABOM_BatchManagementEndpoint"; |
| | 17 | |
|
| | 18 | | public const string BatchAccountKeyEnvironmentSettingName = "MABOM_BatchAccountKey"; |
| | 19 | |
|
| | 20 | | public const string BatchAccountNameEnvironmentSettingName = "MABOM_BatchAccountName"; |
| | 21 | |
|
| | 22 | | public const string BatchAccountUrlEnvironmentSettingName = "MABOM_BatchAccountEndpoint"; |
| | 23 | |
|
| | 24 | | public const string StorageAccountKeyEnvironmentSettingName = "MABOM_StorageKey"; |
| | 25 | |
|
| | 26 | | public const string StorageAccountNameEnvironmentSettingName = "MABOM_StorageAccount"; |
| | 27 | |
|
| | 28 | | public const string StorageAccountBlobEndpointEnvironmentSettingName = "MABOM_BlobEndpoint"; |
| | 29 | |
|
| | 30 | | public const string BatchAccountResourceGroupEnvironmentSettingName = "MABOM_BatchAccountResourceGroupName"; |
| | 31 | |
|
| | 32 | | public const string StorageAccountResourceGroupEnvironmentSettingName = "MABOM_StorageAccountResourceGroupNa |
| | 33 | |
|
| | 34 | | // Required only for Microsoft pre-production test environments |
| | 35 | |
|
| | 36 | | // The client Id from the Azure Active Directory, this is used for connecting to the management api. |
| | 37 | | public const string AzureAuthenticationClientIdEnvironmentSettingName = "MABOM_AzureAuthenticationClientId"; |
| | 38 | |
|
| | 39 | | // The client key from the Azure Active Directory app. |
| | 40 | | public const string AzureAuthenticationClientSecretEnvironmentSettingName = "MABOM_AzureAuthenticationClient |
| | 41 | |
|
| | 42 | | public const string BatchAuthorityUrlEnvironmentSettingName = "MABOM_BatchAuthorityUrl"; |
| | 43 | |
|
| | 44 | | public const string BatchTRPCertificateThumbprintEnvironmentSettingName = "MABOM_BatchTRPCertificateThumbpri |
| | 45 | |
|
| | 46 | | //Should be a string like so: header1=value1;header2=value2;... |
| | 47 | | // Required only for Microsoft pre-production test environments |
| | 48 | | public const string BatchTRPExtraHeadersEnvironmentSettingName = "MABOM_BatchTRPExtraHeaders"; |
| | 49 | |
|
| 0 | 50 | | public readonly string BatchSubscription = GetEnvironmentVariableOrThrow(BatchSubscriptionEnivronmentSetting |
| | 51 | |
|
| 0 | 52 | | public readonly string BatchManagementUrl = GetEnvironmentVariableOrThrow(BatchManagementUrlEnvironmentSetti |
| | 53 | |
|
| 0 | 54 | | public readonly string BatchAccountKey = GetEnvironmentVariableOrThrow(BatchAccountKeyEnvironmentSettingName |
| | 55 | |
|
| 0 | 56 | | public readonly string BatchAccountName = GetEnvironmentVariableOrThrow(BatchAccountNameEnvironmentSettingNa |
| | 57 | |
|
| 0 | 58 | | public readonly string BatchAccountUrl = GetEnvironmentVariableOrThrow(BatchAccountUrlEnvironmentSettingName |
| | 59 | |
|
| 0 | 60 | | public readonly string StorageAccountKey = GetEnvironmentVariableOrThrow(StorageAccountKeyEnvironmentSetting |
| | 61 | |
|
| 0 | 62 | | public readonly string StorageAccountName = GetEnvironmentVariableOrThrow(StorageAccountNameEnvironmentSetti |
| | 63 | |
|
| 0 | 64 | | public readonly string StorageAccountBlobEndpoint = GetEnvironmentVariableOrThrow(StorageAccountBlobEndpoint |
| | 65 | |
|
| 0 | 66 | | public readonly string BatchAccountResourceGroup = GetEnvironmentVariableOrThrow(BatchAccountResourceGroupEn |
| | 67 | |
|
| 0 | 68 | | public readonly string StorageAccountResourceGroup = GetEnvironmentVariableOrThrow(StorageAccountResourceGro |
| | 69 | |
|
| 0 | 70 | | public readonly Func<string> BatchTRPCertificateThumbprint = () => GetEnvironmentVariableOrThrow(BatchTRPCer |
| | 71 | |
|
| 0 | 72 | | public readonly string AzureAuthenticationClientId = GetEnvironmentVariableOrThrow(AzureAuthenticationClient |
| | 73 | |
|
| 0 | 74 | | public readonly string AzureAuthenticationClientSecret = GetEnvironmentVariableOrThrow(AzureAuthenticationCl |
| | 75 | |
|
| 0 | 76 | | public readonly IReadOnlyDictionary<string, string> BatchTRPExtraHeaders = ParseHeaderEnvironmentVariable(Ba |
| | 77 | |
|
| 0 | 78 | | public readonly string BatchAuthorityUrl = GetEnvironmentVariableOrDefault(BatchAuthorityUrlEnvironmentSetti |
| | 79 | |
|
| | 80 | | private static IReadOnlyDictionary<string, string> ParseHeaderEnvironmentVariable(string environmentSettingN |
| | 81 | | { |
| 0 | 82 | | string settingString = Environment.GetEnvironmentVariable(environmentSettingName); |
| 0 | 83 | | IReadOnlyDictionary<string, string> result = new Dictionary<string, string>(); |
| | 84 | |
|
| 0 | 85 | | if (!string.IsNullOrEmpty(settingString)) |
| | 86 | | { |
| 0 | 87 | | IEnumerable<string> pairs = settingString.Split(';'); |
| 0 | 88 | | result = pairs.ToDictionary(pair => pair.Split('=')[0], pair => pair.Split('=')[1]); |
| | 89 | | } |
| | 90 | |
|
| 0 | 91 | | return result; |
| | 92 | | } |
| | 93 | |
|
| | 94 | | private static string GetEnvironmentVariableOrThrow(string environmentSettingName) |
| | 95 | | { |
| 0 | 96 | | string result = Environment.GetEnvironmentVariable(environmentSettingName); |
| 0 | 97 | | if (string.IsNullOrEmpty(result)) |
| | 98 | | { |
| 0 | 99 | | throw new ArgumentException(string.Format("Missing required environment variable {0}", environmentSe |
| | 100 | | } |
| | 101 | |
|
| 0 | 102 | | return result; |
| | 103 | | } |
| | 104 | |
|
| | 105 | | private static string GetEnvironmentVariableOrDefault(string environmentSettingName, string defaultValue) |
| | 106 | | { |
| 0 | 107 | | string result = Environment.GetEnvironmentVariable(environmentSettingName); |
| 0 | 108 | | if (string.IsNullOrEmpty(result)) |
| | 109 | | { |
| 0 | 110 | | return defaultValue; |
| | 111 | | } |
| | 112 | |
|
| 0 | 113 | | return result; |
| | 114 | | } |
| | 115 | | } |
| | 116 | |
|
| 0 | 117 | | private static readonly Lazy<TestConfiguration> configurationInstance = new Lazy<TestConfiguration>(() => new Te |
| | 118 | |
|
| | 119 | | public static TestConfiguration Configuration |
| | 120 | | { |
| 0 | 121 | | get { return configurationInstance.Value; } |
| | 122 | | } |
| | 123 | | } |
| | 124 | | } |