Skip to content

Commit 6656af4

Browse files
authored
Switch to null as default for owner and group in WithContainerFiles (#8557)
* Switch to null as default for owner and group in WithContainerFiles * Fix failing test * Update doc comment * Call out that 0 is root
1 parent c09db91 commit 6656af4

File tree

4 files changed

+18
-16
lines changed

4 files changed

+18
-16
lines changed

src/Aspire.Hosting/ApplicationModel/ContainerFileSystemCallbackAnnotation.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,14 +82,14 @@ public sealed class ContainerFileSystemCallbackAnnotation : IResourceAnnotation
8282
public required string DestinationPath { get; init; }
8383

8484
/// <summary>
85-
/// The UID of the default owner for files/directories to be created or updated in the container. Defaults to 0 for root.
85+
/// The UID of the default owner for files/directories to be created or updated in the container. The UID defaults to 0 for root if null.
8686
/// </summary>
87-
public int DefaultOwner { get; init; }
87+
public int? DefaultOwner { get; init; }
8888

8989
/// <summary>
90-
/// The GID of the default group for files/directories to be created or updated in the container. Defaults to 0 for root.
90+
/// The GID of the default group for files/directories to be created or updated in the container. The GID defaults to 0 for root if null.
9191
/// </summary>
92-
public int DefaultGroup { get; init; }
92+
public int? DefaultGroup { get; init; }
9393

9494
/// <summary>
9595
/// The umask to apply to files or folders without an explicit mode permission. If set to null, a default umask value of 0022 (octal) will be used.

src/Aspire.Hosting/ContainerResourceBuilderExtensions.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -706,8 +706,8 @@ public static IResourceBuilder<T> WithBuildSecret<T>(this IResourceBuilder<T> bu
706706
/// <param name="builder">The resource builder for the container resource.</param>
707707
/// <param name="destinationPath">The destination (absolute) path in the container.</param>
708708
/// <param name="entries">The file system entries to create.</param>
709-
/// <param name="defaultOwner">The default owner UID for the created or updated file system. Defaults to 0 for root.</param>
710-
/// <param name="defaultGroup">The default group ID for the created or updated file system. Defaults to 0 for root.</param>
709+
/// <param name="defaultOwner">The default owner UID for the created or updated file system. Defaults to 0 for root if not set.</param>
710+
/// <param name="defaultGroup">The default group ID for the created or updated file system. Defaults to 0 for root if not set.</param>
711711
/// <param name="umask">The umask <see cref="UnixFileMode"/> permissions to exclude from the default file and folder permissions. This takes away (rather than granting) default permissions to files and folders without an explicit mode permission set.</param>
712712
/// <returns>The <see cref="IResourceBuilder{T}"/>.</returns>
713713
/// <remarks>
@@ -741,7 +741,7 @@ public static IResourceBuilder<T> WithBuildSecret<T>(this IResourceBuilder<T> bu
741741
/// defaultOwner: 1000);
742742
/// </code>
743743
/// </example>
744-
public static IResourceBuilder<T> WithContainerFiles<T>(this IResourceBuilder<T> builder, string destinationPath, IEnumerable<ContainerFileSystemItem> entries, int defaultOwner = 0, int defaultGroup = 0, UnixFileMode? umask = null) where T : ContainerResource
744+
public static IResourceBuilder<T> WithContainerFiles<T>(this IResourceBuilder<T> builder, string destinationPath, IEnumerable<ContainerFileSystemItem> entries, int? defaultOwner = null, int? defaultGroup = null, UnixFileMode? umask = null) where T : ContainerResource
745745
{
746746
ArgumentNullException.ThrowIfNull(builder);
747747
ArgumentNullException.ThrowIfNull(destinationPath);
@@ -769,8 +769,8 @@ public static IResourceBuilder<T> WithContainerFiles<T>(this IResourceBuilder<T>
769769
/// <param name="builder">The resource builder for the container resource.</param>
770770
/// <param name="destinationPath">The destination (absolute) path in the container.</param>
771771
/// <param name="callback">The callback that will be invoked when the resource is being created.</param>
772-
/// <param name="defaultOwner">The default owner UID for the created or updated file system. Defaults to 0 for root.</param>
773-
/// <param name="defaultGroup">The default group ID for the created or updated file system. Defaults to 0 for root.</param>
772+
/// <param name="defaultOwner">The default owner UID for the created or updated file system. Defaults to 0 for root if not set.</param>
773+
/// <param name="defaultGroup">The default group ID for the created or updated file system. Defaults to 0 for root if not set.</param>
774774
/// <param name="umask">The umask <see cref="UnixFileMode"/> permissions to exclude from the default file and folder permissions. This takes away (rather than granting) default permissions to files and folders without an explicit mode permission set.</param>
775775
/// <returns>The <see cref="IResourceBuilder{T}"/>.</returns>
776776
/// <remarks>
@@ -814,7 +814,7 @@ public static IResourceBuilder<T> WithContainerFiles<T>(this IResourceBuilder<T>
814814
/// });
815815
/// </code>
816816
/// </example>
817-
public static IResourceBuilder<T> WithContainerFiles<T>(this IResourceBuilder<T> builder, string destinationPath, Func<ContainerFileSystemCallbackContext, CancellationToken, Task<IEnumerable<ContainerFileSystemItem>>> callback, int defaultOwner = 0, int defaultGroup = 0, UnixFileMode? umask = null) where T : ContainerResource
817+
public static IResourceBuilder<T> WithContainerFiles<T>(this IResourceBuilder<T> builder, string destinationPath, Func<ContainerFileSystemCallbackContext, CancellationToken, Task<IEnumerable<ContainerFileSystemItem>>> callback, int? defaultOwner = null, int? defaultGroup = null, UnixFileMode? umask = null) where T : ContainerResource
818818
{
819819
ArgumentNullException.ThrowIfNull(builder);
820820
ArgumentNullException.ThrowIfNull(destinationPath);

src/Aspire.Hosting/Dcp/Model/Container.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -295,11 +295,13 @@ internal sealed class ContainerCreateFileSystem : IEquatable<ContainerCreateFile
295295

296296
// The default owner UID to use for created (or updated) file system entries. Defaults to 0 for root.
297297
[JsonPropertyName("defaultOwner")]
298-
public int DefaultOwner { get; set; }
298+
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
299+
public int? DefaultOwner { get; set; }
299300

300301
// The default group GID to use for created (or updated) file system entries. Defaults to 0 for root.
301302
[JsonPropertyName("defaultGroup")]
302-
public int DefaultGroup { get; set; }
303+
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
304+
public int? DefaultGroup { get; set; }
303305

304306
// The umask for created files and folders without explicit permissions set (defaults to 022 if null)
305307
[JsonPropertyName("umask")]

tests/Aspire.Hosting.PostgreSQL.Tests/AddPostgresTests.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -476,8 +476,8 @@ public async Task WithPostgresProducesValidServersJsonFile()
476476

477477
Assert.Equal("/pgadmin4", createServers.DestinationPath);
478478
Assert.Null(createServers.Umask);
479-
Assert.Equal(0, createServers.DefaultOwner);
480-
Assert.Equal(0, createServers.DefaultGroup);
479+
Assert.Null(createServers.DefaultOwner);
480+
Assert.Null(createServers.DefaultGroup);
481481

482482
var entries = await createServers.Callback(new() { Model = pgadmin, ServiceProvider = app.Services }, CancellationToken.None);
483483

@@ -547,8 +547,8 @@ public async Task WithPgwebProducesValidBookmarkFiles()
547547

548548
Assert.Equal("/", createBookmarks.DestinationPath);
549549
Assert.Null(createBookmarks.Umask);
550-
Assert.Equal(0, createBookmarks.DefaultOwner);
551-
Assert.Equal(0, createBookmarks.DefaultGroup);
550+
Assert.Null(createBookmarks.DefaultOwner);
551+
Assert.Null(createBookmarks.DefaultGroup);
552552

553553
var entries = await createBookmarks.Callback(new() { Model = pgweb, ServiceProvider = app.Services }, CancellationToken.None);
554554

0 commit comments

Comments
 (0)