Skip to content

Commit 289c081

Browse files
Copilotdavidfowl
andcommitted
Address code review feedback
- Fix temp file creation logic in UserSecretsManagerFactory to write content before moving - Change JsonFlattener from public to internal (consistent with Internal namespace) - Remove trailing empty line in test file All tests still passing after fixes. Co-authored-by: davidfowl <[email protected]>
1 parent e4ed362 commit 289c081

File tree

3 files changed

+15
-8
lines changed

3 files changed

+15
-8
lines changed

src/Aspire.Hosting/Publishing/Internal/JsonFlattener.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace Aspire.Hosting.Publishing.Internal;
88
/// <summary>
99
/// Provides utility methods for flattening and unflattening JSON objects using colon-separated keys.
1010
/// </summary>
11-
public static class JsonFlattener
11+
internal static class JsonFlattener
1212
{
1313
/// <summary>
1414
/// Flattens a JsonObject using colon-separated keys for configuration compatibility.

src/Aspire.Hosting/UserSecrets/UserSecretsManagerFactory.cs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -253,15 +253,19 @@ private void Save(Dictionary<string, string?> secrets)
253253
contents[secret.Key] = secret.Value;
254254
}
255255

256+
var json = contents.ToJsonString(s_jsonSerializerOptions);
257+
256258
// Create a temp file with the correct Unix file mode before moving it to the expected path.
257259
if (!OperatingSystem.IsWindows())
258260
{
259261
var tempFilename = Path.GetTempFileName();
262+
File.WriteAllText(tempFilename, json, Encoding.UTF8);
260263
File.Move(tempFilename, FilePath, overwrite: true);
261264
}
262-
263-
var json = contents.ToJsonString(s_jsonSerializerOptions);
264-
File.WriteAllText(FilePath, json, Encoding.UTF8);
265+
else
266+
{
267+
File.WriteAllText(FilePath, json, Encoding.UTF8);
268+
}
265269
}
266270

267271
private async Task SaveAsync(Dictionary<string, string?> secrets, CancellationToken cancellationToken)
@@ -272,15 +276,19 @@ private async Task SaveAsync(Dictionary<string, string?> secrets, CancellationTo
272276
contents[secret.Key] = secret.Value;
273277
}
274278

279+
var json = contents.ToJsonString(s_jsonSerializerOptions);
280+
275281
// Create a temp file with the correct Unix file mode before moving it to the expected path.
276282
if (!OperatingSystem.IsWindows())
277283
{
278284
var tempFilename = Path.GetTempFileName();
285+
await File.WriteAllTextAsync(tempFilename, json, Encoding.UTF8, cancellationToken).ConfigureAwait(false);
279286
File.Move(tempFilename, FilePath, overwrite: true);
280287
}
281-
282-
var json = contents.ToJsonString(s_jsonSerializerOptions);
283-
await File.WriteAllTextAsync(FilePath, json, Encoding.UTF8, cancellationToken).ConfigureAwait(false);
288+
else
289+
{
290+
await File.WriteAllTextAsync(FilePath, json, Encoding.UTF8, cancellationToken).ConfigureAwait(false);
291+
}
284292
}
285293

286294
private void EnsureUserSecretsDirectory()

tests/Aspire.Hosting.Tests/UserSecretsParameterDefaultTests.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,4 +261,3 @@ public override void WriteToManifest(ManifestPublishingContext context)
261261
}
262262
}
263263
}
264-

0 commit comments

Comments
 (0)