Skip to content

Commit fdc2d0b

Browse files
committed
Show warning instead of throw exception when StorageAccountName doesn't match
1 parent a37b4e9 commit fdc2d0b

File tree

1 file changed

+20
-31
lines changed

1 file changed

+20
-31
lines changed

src/ServiceManagement/Compute/Commands.ServiceManagement/Extensions/Diagnostics/BaseAzureServiceDiagnosticsExtension.cs

Lines changed: 20 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -115,59 +115,48 @@ protected override void ValidateConfiguration()
115115
}
116116
}
117117

118-
var publicConfigElem = DiagnosticsHelper.GetPublicConfigXElementFromXmlFile(this.DiagnosticsConfigurationPath);
119-
if (publicConfigElem == null)
120-
{
121-
throw new ArgumentException(Resources.DiagnosticsExtensionNullPublicConfig);
122-
}
123-
publicConfigElem.SetAttributeValue("xmlns", XmlNamespace);
124-
PublicConfiguration = publicConfigElem.ToString();
125-
126118
XmlDocument doc = new XmlDocument();
127119
XmlNamespaceManager ns = new XmlNamespaceManager(doc.NameTable);
128120
ns.AddNamespace("ns", XmlNamespace);
129121
doc.Load(DiagnosticsConfigurationPath);
130122

131-
// Make sure the configuration element exist
132-
var configElement = doc.SelectSingleNode("//ns:WadCfg", ns) ?? doc.SelectSingleNode("//ns:WadCfgBlob", ns);
133-
if (configElement == null)
123+
// Make sure the configuration elements exist
124+
var publicConfigElement = doc.SelectSingleNode("//ns:PublicConfig", ns);
125+
if (publicConfigElement == null)
126+
{
127+
throw new ArgumentException(Resources.DiagnosticsExtensionNullPublicConfig);
128+
}
129+
130+
var wadConfigElement = doc.SelectSingleNode("//ns:WadCfg", ns) ?? doc.SelectSingleNode("//ns:WadCfgBlob", ns);
131+
if (wadConfigElement == null)
134132
{
135133
throw new ArgumentException(Resources.DiagnosticsExtensionPaaSConfigElementNotDefined);
136134
}
137135

138136
// The element <StorageAccount> is not meant to be set by the user in the public config.
139137
// Make sure it matches the storage account in the private config.
140138
var storageAccountElement = doc.SelectSingleNode("//ns:StorageAccount", ns);
141-
if(storageAccountElement != null)
139+
if (storageAccountElement == null)
142140
{
143-
// The StorageAccount is empty, we must set it
144-
if (string.IsNullOrEmpty(storageAccountElement.InnerText))
145-
{
146-
storageAccountElement.InnerText = StorageAccountName;
147-
PublicConfiguration = doc.OuterXml;
148-
}
149-
else if (!string.IsNullOrEmpty(storageAccountElement.InnerText) && string.Compare(storageAccountElement.InnerText, StorageAccountName, true) != 0)
150-
{
151-
throw new ArgumentException(Resources.DiagnosticsExtensionNoMatchStorageAccount);
152-
}
153-
}
154-
else
155-
{
156-
// The StorageAccount is not there. we must set it
141+
// The StorageAccount element is not there, we create one
157142
storageAccountElement = doc.CreateElement("StorageAccount", XmlNamespace);
158-
storageAccountElement.InnerText = StorageAccountName;
143+
wadConfigElement.ParentNode.AppendChild(storageAccountElement);
144+
}
159145

160-
// Insert it after <WadCfg> or <WadCfgBlob>
161-
configElement.ParentNode.AppendChild(storageAccountElement);
162-
PublicConfiguration = doc.OuterXml;
146+
if (!string.IsNullOrEmpty(storageAccountElement.InnerText) && string.Compare(storageAccountElement.InnerText, StorageAccountName, true) != 0)
147+
{
148+
WriteWarning(Resources.DiagnosticsExtensionNoMatchStorageAccount);
163149
}
164150

151+
storageAccountElement.InnerText = StorageAccountName;
152+
PublicConfiguration = publicConfigElement.OuterXml;
153+
165154
// Make sure the storage account name in PrivateConfig matches.
166155
var privateConfigStorageAccountName = DiagnosticsHelper.GetStorageAccountInfoFromPrivateConfig(this.DiagnosticsConfigurationPath, DiagnosticsHelper.PrivConfNameAttr);
167156
if (!string.IsNullOrEmpty(privateConfigStorageAccountName)
168157
&& !string.Equals(StorageAccountName, privateConfigStorageAccountName, StringComparison.OrdinalIgnoreCase))
169158
{
170-
throw new ArgumentException(Resources.DiagnosticsExtensionNoMatchPrivateStorageAccount);
159+
WriteWarning(Resources.DiagnosticsExtensionNoMatchPrivateStorageAccount);
171160
}
172161

173162
PrivateConfigurationXml = new XDocument(PrivateConfigurationXmlTemplate);

0 commit comments

Comments
 (0)