-
Notifications
You must be signed in to change notification settings - Fork 330
Move Test Config to Jsonc #4297
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 2 commits
025d441
2d1aa7e
0a0830b
ffa9a9b
992fb31
4474f38
5269fe9
57e9b41
ef6e8df
37b4f64
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,70 +6,63 @@ | |
| using System.IO; | ||
| using Newtonsoft.Json; | ||
|
|
||
| #nullable enable | ||
|
|
||
| namespace Microsoft.Data.SqlClient.TestUtilities | ||
| { | ||
| public class Config | ||
| { | ||
| public string TCPConnectionString = null; | ||
| public string NPConnectionString = null; | ||
| public string TCPConnectionStringHGSVBS = null; | ||
| public string TCPConnectionStringNoneVBS = null; | ||
| public string TCPConnectionStringAASSGX = null; | ||
| public string AADAuthorityURL = null; | ||
| public string AADPasswordConnectionString = null; | ||
| public string AADServicePrincipalId = null; | ||
| public string AADServicePrincipalSecret = null; | ||
| public string AzureKeyVaultURL = null; | ||
| public string AzureKeyVaultTenantId = null; | ||
| public string LocalDbAppName = null; | ||
| public string LocalDbSharedInstanceName = null; | ||
| public string? TCPConnectionString = null; | ||
| public string? NPConnectionString = null; | ||
| public string? TCPConnectionStringHGSVBS = null; | ||
| public string? TCPConnectionStringNoneVBS = null; | ||
| public string? TCPConnectionStringAASSGX = null; | ||
| public bool EnclaveEnabled = false; | ||
| public bool TracingEnabled = false; | ||
| public string? AADAuthorityURL = null; | ||
| public string? AADPasswordConnectionString = null; | ||
| public string? AADServicePrincipalId = null; | ||
| public string? AADServicePrincipalSecret = null; | ||
| public string? AzureKeyVaultURL = null; | ||
| public string? AzureKeyVaultTenantId = null; | ||
| public bool SupportsIntegratedSecurity = false; | ||
| public bool ManagedIdentitySupported = true; | ||
| public string FileStreamDirectory = null; | ||
| public string? LocalDbAppName = null; | ||
| public string? LocalDbSharedInstanceName = null; | ||
| public string? FileStreamDirectory = null; | ||
| public bool UseManagedSNIOnWindows = false; | ||
| public string DNSCachingConnString = null; | ||
| public string DNSCachingServerCR = null; // this is for the control ring | ||
| public string DNSCachingServerTR = null; // this is for the tenant ring | ||
| public bool IsAzureSynapse = false; // True for Azure Data Warehouse/Synapse | ||
| public string? DNSCachingConnString = null; | ||
| public string? DNSCachingServerCR = null; // this is for the control ring | ||
| public string? DNSCachingServerTR = null; // this is for the tenant ring | ||
| public bool IsDNSCachingSupportedCR = false; // this is for the control ring | ||
| public bool IsDNSCachingSupportedTR = false; // this is for the tenant ring | ||
| public string EnclaveAzureDatabaseConnString = null; | ||
| public string UserManagedIdentityClientId = null; | ||
| public string PowerShellPath = null; | ||
| public string KerberosDomainPassword = null; | ||
| public string KerberosDomainUser = null; | ||
| public string? EnclaveAzureDatabaseConnString = null; | ||
| public bool ManagedIdentitySupported = true; | ||
| public string? UserManagedIdentityClientId = null; | ||
| public string? PowerShellPath = null; | ||
| public string? AliasName = null; | ||
| public string? KerberosDomainPassword = null; | ||
| public string? KerberosDomainUser = null; | ||
| public bool IsManagedInstance = false; | ||
| public string AliasName = null; | ||
|
|
||
| public static Config Load(string configPath = @"config.json") | ||
| public static Config Load(string configPath) | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was added as an escape hatch for preserving the behavior of ExtUtilities project. I have plans to remove the ExtUtilities project, so this method will hopefully go away someday. |
||
| { | ||
| // Allow an override of the config path via an environment variable. | ||
| configPath = Environment.GetEnvironmentVariable("TEST_MDS_CONFIG") ?? configPath; | ||
| Config config = LoadInternal(Environment.GetEnvironmentVariable("TEST_MDS_CONFIG")) ?? | ||
| LoadInternal(configPath) ?? | ||
| throw new FileNotFoundException("Could not find test configuration file."); | ||
|
|
||
|
benrr101 marked this conversation as resolved.
|
||
| Config config; | ||
| try | ||
| { | ||
| using (StreamReader r = new StreamReader(configPath)) | ||
| { | ||
| config = JsonConvert.DeserializeObject<Config>(r.ReadToEnd()) | ||
| ?? throw new InvalidOperationException($"Failed to deserialize config from '{configPath}'."); | ||
| } | ||
| } | ||
| catch | ||
| { | ||
| throw; | ||
| } | ||
| // Allow environment variables to override individual config values. | ||
| SetFromEnv("MDS_TCPConnectionString", ref config.TCPConnectionString); | ||
|
|
||
| static void SetFromEnv(string envVar, ref string configValue) | ||
| { | ||
| string envValue = Environment.GetEnvironmentVariable(envVar); | ||
| if (!string.IsNullOrEmpty(envValue)) | ||
| { | ||
| configValue = envValue; | ||
| } | ||
| } | ||
| return config; | ||
| } | ||
|
|
||
| public static Config Load() | ||
| { | ||
| // Load config from environment variable first, jsonc file second, json file last. | ||
| Config config = LoadInternal(Environment.GetEnvironmentVariable("TEST_MDS_CONFIG")) ?? | ||
| LoadInternal("config.jsonc") ?? | ||
| LoadInternal("config.json") ?? | ||
| throw new FileNotFoundException("Could not find test configuration file."); | ||
|
|
||
| // Allow environment variables to override individual config values. | ||
| SetFromEnv("MDS_TCPConnectionString", ref config.TCPConnectionString); | ||
|
|
@@ -82,5 +75,34 @@ public static void UpdateConfig(Config updatedConfig, string configPath = @"conf | |
| string config = JsonConvert.SerializeObject(updatedConfig); | ||
| File.WriteAllText(configPath, config); | ||
| } | ||
|
|
||
| private static Config? LoadInternal(string? configPath) | ||
| { | ||
| if (configPath is null) | ||
| { | ||
| return null; | ||
| } | ||
|
|
||
|
benrr101 marked this conversation as resolved.
|
||
| try | ||
| { | ||
| using StreamReader sr = new StreamReader(configPath); | ||
| return JsonConvert.DeserializeObject<Config>(sr.ReadToEnd()) ?? | ||
|
benrr101 marked this conversation as resolved.
Outdated
|
||
| throw new InvalidOperationException($"Failed to deserialize config from '{configPath}'"); | ||
| } | ||
| catch (FileNotFoundException) | ||
| { | ||
| // File did not exist at the path given. We will try a different location. | ||
|
benrr101 marked this conversation as resolved.
benrr101 marked this conversation as resolved.
benrr101 marked this conversation as resolved.
|
||
| return null; | ||
| } | ||
| } | ||
|
|
||
| private static void SetFromEnv(string envVar, ref string? configValue) | ||
| { | ||
| string? envValue = Environment.GetEnvironmentVariable(envVar); | ||
| if (!string.IsNullOrEmpty(envValue)) | ||
| { | ||
| configValue = envValue; | ||
| } | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,19 +22,20 @@ | |
| "SupportsIntegratedSecurity": true, | ||
| "LocalDbAppName": "", | ||
| "LocalDbSharedInstanceName": "", | ||
| "SupportsFileStream": false, | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This field did not exist in the Config class. |
||
| "FileStreamDirectory": "", | ||
| "UseManagedSNIOnWindows": false, | ||
| "DNSCachingConnString": "", | ||
| "DNSCachingServerCR": "", | ||
| "DNSCachingServerTR": "", | ||
| "IsDNSCachingSupportedCR": false, | ||
| "IsDNSCachingSupportedTR": false, | ||
| "IsAzureSynapse": false, | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This field existed in the Config class, but was removed since it's unused. |
||
| "EnclaveAzureDatabaseConnString": "", | ||
| "ManagedIdentitySupported": true, | ||
| "UserManagedIdentityClientId": "", | ||
| "PowerShellPath": "", | ||
| "AliasName": "", | ||
| "WorkloadIdentityFederationServiceConnectionId": "" | ||
| "WorkloadIdentityFederationServiceConnectionId": "", | ||
| "KerberosDomainPassword": "", | ||
| "KerberosDomainuser": "", | ||
| "IsManagedInstance": false | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These fields exist in Config class, but did not in the json file. |
||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was removed as it is not used.