Skip to content

Commit 9ad8747

Browse files
Fixed a bug in AZD integration code (Azure#46791)
* improved code that rewrites appsettings.json * removed unused namespaces
1 parent f8154ee commit 9ad8747

File tree

5 files changed

+61
-13
lines changed

5 files changed

+61
-13
lines changed

sdk/provisioning/Azure.Provisioning.CloudMachine/Azure.CloudMachine.sln

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,18 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Azure.Provisioning.CloudMac
77
EndProject
88
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Azure.Provisioning.CloudMachine.Tests", "tests\Azure.Provisioning.CloudMachine.Tests.csproj", "{46DCEF27-4157-4FB6-A283-B8484EC45665}"
99
EndProject
10+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Azure.Provisioning", "..\Azure.Provisioning\src\Azure.Provisioning.csproj", "{2F492C07-8182-41E2-8C68-27D353C9AB74}"
11+
EndProject
12+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Azure.Provisioning.KeyVault", "..\Azure.Provisioning.KeyVault\src\Azure.Provisioning.KeyVault.csproj", "{DA43BF21-558B-438B-9DBF-1A88130C944A}"
13+
EndProject
14+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Azure.Provisioning.ServiceBus", "..\Azure.Provisioning.ServiceBus\src\Azure.Provisioning.ServiceBus.csproj", "{48D33345-B5A8-4F94-84D6-A61F8E16271D}"
15+
EndProject
16+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Azure.Provisioning.EventGrid", "..\Azure.Provisioning.EventGrid\src\Azure.Provisioning.EventGrid.csproj", "{BCBAF45F-E078-4230-9BDC-4DE9F2FBEE9A}"
17+
EndProject
18+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Azure.Provisioning.CognitiveServices", "..\Azure.Provisioning.CognitiveServices\src\Azure.Provisioning.CognitiveServices.csproj", "{987279D2-202C-488A-BA47-37FCEEA51536}"
19+
EndProject
20+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Azure.Provisioning.Storage", "..\Azure.Provisioning.Storage\src\Azure.Provisioning.Storage.csproj", "{813E7228-2B59-41D2-9AFC-BF4092EC7090}"
21+
EndProject
1022
Global
1123
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1224
Debug|Any CPU = Debug|Any CPU
@@ -21,6 +33,30 @@ Global
2133
{46DCEF27-4157-4FB6-A283-B8484EC45665}.Debug|Any CPU.Build.0 = Debug|Any CPU
2234
{46DCEF27-4157-4FB6-A283-B8484EC45665}.Release|Any CPU.ActiveCfg = Release|Any CPU
2335
{46DCEF27-4157-4FB6-A283-B8484EC45665}.Release|Any CPU.Build.0 = Release|Any CPU
36+
{2F492C07-8182-41E2-8C68-27D353C9AB74}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
37+
{2F492C07-8182-41E2-8C68-27D353C9AB74}.Debug|Any CPU.Build.0 = Debug|Any CPU
38+
{2F492C07-8182-41E2-8C68-27D353C9AB74}.Release|Any CPU.ActiveCfg = Release|Any CPU
39+
{2F492C07-8182-41E2-8C68-27D353C9AB74}.Release|Any CPU.Build.0 = Release|Any CPU
40+
{DA43BF21-558B-438B-9DBF-1A88130C944A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
41+
{DA43BF21-558B-438B-9DBF-1A88130C944A}.Debug|Any CPU.Build.0 = Debug|Any CPU
42+
{DA43BF21-558B-438B-9DBF-1A88130C944A}.Release|Any CPU.ActiveCfg = Release|Any CPU
43+
{DA43BF21-558B-438B-9DBF-1A88130C944A}.Release|Any CPU.Build.0 = Release|Any CPU
44+
{48D33345-B5A8-4F94-84D6-A61F8E16271D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
45+
{48D33345-B5A8-4F94-84D6-A61F8E16271D}.Debug|Any CPU.Build.0 = Debug|Any CPU
46+
{48D33345-B5A8-4F94-84D6-A61F8E16271D}.Release|Any CPU.ActiveCfg = Release|Any CPU
47+
{48D33345-B5A8-4F94-84D6-A61F8E16271D}.Release|Any CPU.Build.0 = Release|Any CPU
48+
{BCBAF45F-E078-4230-9BDC-4DE9F2FBEE9A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
49+
{BCBAF45F-E078-4230-9BDC-4DE9F2FBEE9A}.Debug|Any CPU.Build.0 = Debug|Any CPU
50+
{BCBAF45F-E078-4230-9BDC-4DE9F2FBEE9A}.Release|Any CPU.ActiveCfg = Release|Any CPU
51+
{BCBAF45F-E078-4230-9BDC-4DE9F2FBEE9A}.Release|Any CPU.Build.0 = Release|Any CPU
52+
{987279D2-202C-488A-BA47-37FCEEA51536}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
53+
{987279D2-202C-488A-BA47-37FCEEA51536}.Debug|Any CPU.Build.0 = Debug|Any CPU
54+
{987279D2-202C-488A-BA47-37FCEEA51536}.Release|Any CPU.ActiveCfg = Release|Any CPU
55+
{987279D2-202C-488A-BA47-37FCEEA51536}.Release|Any CPU.Build.0 = Release|Any CPU
56+
{813E7228-2B59-41D2-9AFC-BF4092EC7090}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
57+
{813E7228-2B59-41D2-9AFC-BF4092EC7090}.Debug|Any CPU.Build.0 = Debug|Any CPU
58+
{813E7228-2B59-41D2-9AFC-BF4092EC7090}.Release|Any CPU.ActiveCfg = Release|Any CPU
59+
{813E7228-2B59-41D2-9AFC-BF4092EC7090}.Release|Any CPU.Build.0 = Release|Any CPU
2460
EndGlobalSection
2561
GlobalSection(SolutionProperties) = preSolution
2662
HideSolutionNode = FALSE

sdk/provisioning/Azure.Provisioning.CloudMachine/src/Azure.Provisioning.CloudMachine.csproj

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,11 @@
2020
</ItemGroup>
2121

2222
<ItemGroup>
23+
<ProjectReference Include="..\..\Azure.Provisioning.CognitiveServices\src\Azure.Provisioning.CognitiveServices.csproj" />
2324
<ProjectReference Include="..\..\Azure.Provisioning.EventGrid\src\Azure.Provisioning.EventGrid.csproj" />
25+
<ProjectReference Include="..\..\Azure.Provisioning.KeyVault\src\Azure.Provisioning.KeyVault.csproj" />
2426
<ProjectReference Include="..\..\Azure.Provisioning.ServiceBus\src\Azure.Provisioning.ServiceBus.csproj" />
2527
<ProjectReference Include="..\..\Azure.Provisioning.Storage\src\Azure.Provisioning.Storage.csproj" />
26-
<ProjectReference Include="..\..\Azure.Provisioning.KeyVault\src\Azure.Provisioning.KeyVault.csproj" />
27-
<ProjectReference Include="..\..\Azure.Provisioning.CognitiveServices\src\Azure.Provisioning.CognitiveServices.csproj" />
2828
</ItemGroup>
29+
2930
</Project>

sdk/provisioning/Azure.Provisioning.CloudMachine/src/CDKLevel3/Azd.cs renamed to sdk/provisioning/Azure.Provisioning.CloudMachine/src/CDKLevel3/AzdHelpers.cs

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
namespace Azure.CloudMachine;
1515

16-
internal static class Azd
16+
internal static class AzdHelpers
1717
{
1818
private const string MainBicepName = "main";
1919
private const string ResourceGroupVersion = "2024-03-01";
@@ -115,18 +115,29 @@ internal static string ReadOrCreateCmid()
115115
return cmid;
116116
}
117117
else
118-
{ // add CM configuration to existing file
119-
JsonNode? root = JsonValue.Parse(appsettings);
120-
if (root is null)
121-
throw new NotImplementedException();
122-
123-
if (root is not JsonObject obj)
124-
throw new NotImplementedException();
118+
{ // add CM configuration to existing file
119+
json.Seek(0, SeekOrigin.Begin);
120+
JsonNode? root = JsonNode.Parse(json);
121+
json.Close();
122+
if (root is null || root is not JsonObject obj) throw new InvalidOperationException("Existing appsettings.json is not a valid JSON object");
125123

126124
var cmProperties = new JsonObject();
127125
cmid = GenerateCloudMachineId();
128126
cmProperties.Add("ID", cmid);
129127
obj.Add("CloudMachine", cmProperties);
128+
129+
using FileStream file = File.OpenWrite(appsettings);
130+
JsonWriterOptions writerOptions = new()
131+
{
132+
Indented = true,
133+
};
134+
Utf8JsonWriter writer = new(file, writerOptions);
135+
JsonSerializerOptions options = new()
136+
{
137+
WriteIndented = true,
138+
};
139+
root.WriteTo(writer, options);
140+
writer.Flush();
130141
}
131142

132143
return cmid;

sdk/provisioning/Azure.Provisioning.CloudMachine/src/CDKLevel3/CloudMachineInfrastructure.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ public static bool Configure(string[] args, Action<CloudMachineInfrastructure>?
277277
return false;
278278
}
279279

280-
string cmid = Azd.ReadOrCreateCmid();
280+
string cmid = AzdHelpers.ReadOrCreateCmid();
281281

282282
CloudMachineInfrastructure cmi = new(cmid);
283283
if (configure != default)
@@ -286,7 +286,7 @@ public static bool Configure(string[] args, Action<CloudMachineInfrastructure>?
286286
}
287287

288288
string infraDirectory = Path.Combine(".", "infra");
289-
Azd.Init(infraDirectory, cmi);
289+
AzdHelpers.Init(infraDirectory, cmi);
290290
return true;
291291
}
292292
}

sdk/provisioning/Azure.Provisioning.CloudMachine/src/OFX/CloudMachineWorkspace.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public CloudMachineWorkspace(TokenCredential? credential = default, IConfigurati
3232
string? cmid;
3333
if (configuration == default)
3434
{
35-
cmid = Azd.ReadOrCreateCmid();
35+
cmid = AzdHelpers.ReadOrCreateCmid();
3636
}
3737
else
3838
{

0 commit comments

Comments
 (0)