/// <summary> /// Sloppily serialize the tenant configuration as a string with one /// property per line. This is only used for test recording. /// </summary> /// <param name="config">The tenant configuration.</param> /// <param name="sanitize"> /// Whether to santize AccountKeys in the serialized value. The /// default is true. /// </param> /// <returns>A string represenation of the tenant configuration.</returns> public static string Serialize(TenantConfiguration config, bool sanitize = true) => string.Join( "\n", // Keep these in the same order as Parse below! config.TenantName, config.AccountName, !sanitize ? config.AccountKey : Convert.ToBase64String(Encoding.UTF8.GetBytes(SanitizeValue)), config.BlobServiceEndpoint, config.FileServiceEndpoint, config.QueueServiceEndpoint, config.TableServiceEndpoint, config.BlobSecurePortOverride, config.FileSecurePortOverride, config.TableSecurePortOverride, config.QueueSecurePortOverride, config.BlobServiceSecondaryEndpoint, config.FileServiceSecondaryEndpoint, config.QueueServiceSecondaryEndpoint, config.TableServiceSecondaryEndpoint, config.ActiveDirectoryApplicationId, !sanitize ? config.ActiveDirectoryApplicationSecret : SanitizeValue, config.ActiveDirectoryTenantId, config.ActiveDirectoryAuthEndpoint, config.TenantType.ToString(), !sanitize ? config.ConnectionString : config.BuildConnectionString(sanitize), config.EncryptionScope);
/// <summary> /// Parse an XML representation into a TenantConfiguration value. /// </summary> /// <param name="tenant">The XML element to parse.</param> /// <returns>A TenantConfiguration value.</returns> public static TenantConfiguration Parse(XElement tenant) { string Get(string name) => (string)tenant.Element(name); var config = new TenantConfiguration { TenantName = Get("TenantName"), AccountName = Get("AccountName"), AccountKey = Get("AccountKey"), BlobServiceEndpoint = Get("BlobServiceEndpoint"), FileServiceEndpoint = Get("FileServiceEndpoint"), QueueServiceEndpoint = Get("QueueServiceEndpoint"), TableServiceEndpoint = Get("TableServiceEndpoint"), BlobServiceSecondaryEndpoint = Get("BlobServiceSecondaryEndpoint"), FileServiceSecondaryEndpoint = Get("FileServiceSecondaryEndpoint"), QueueServiceSecondaryEndpoint = Get("QueueServiceSecondaryEndpoint"), TableServiceSecondaryEndpoint = Get("TableServiceSecondaryEndpoint"), TenantType = ParseTenantType(Get("TenantType")), BlobSecurePortOverride = Get("BlobSecurePortOverride"), FileSecurePortOverride = Get("FileSecurePortOverride"), QueueSecurePortOverride = Get("QueueSecurePortOverride"), TableSecurePortOverride = Get("TableSecurePortOverride"), ActiveDirectoryApplicationId = Get("ActiveDirectoryApplicationId"), ActiveDirectoryApplicationSecret = Get("ActiveDirectoryApplicationSecret"), ActiveDirectoryTenantId = Get("ActiveDirectoryTenantId"), ActiveDirectoryAuthEndpoint = Get("ActiveDirectoryAuthEndpoint"), ConnectionString = Get("ConnectionString"), EncryptionScope = Get("EncryptionScope"), ResourceGroupName = Get("ResourceGroupName"), SubscriptionId = Get("SubscriptionId") }; // Build a connection string from the other properties if one // wasn't provided with the configuration if (string.IsNullOrWhiteSpace(config.ConnectionString)) { config.ConnectionString = config.BuildConnectionString(false); } return(config); }