Skip to content

Commit

Permalink
Avoid API break
Browse files Browse the repository at this point in the history
  • Loading branch information
drewnoakes committed Sep 23, 2024
1 parent 6053f18 commit a506f6a
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 22 deletions.
19 changes: 17 additions & 2 deletions src/Aspire.Hosting/ApplicationModel/CustomResourceSnapshot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,23 @@ public sealed record VolumeSnapshot(string? Source, string Target, string MountT
/// </summary>
/// <param name="Name">The name of the property.</param>
/// <param name="Value">The value of the property.</param>
/// <param name="IsSensitive">Whether this property is considered sensitive or not.</param>
public sealed record ResourcePropertySnapshot(string Name, object? Value, bool IsSensitive);
public sealed record ResourcePropertySnapshot(string Name, object? Value)
{
/// <summary>
/// Whether this property is considered sensitive or not.
/// </summary>
/// <remarks>
/// Sensitive properties are masked when displayed in UI and require an explicit user action to reveal.
/// </remarks>
public bool IsSensitive { get; init; }

internal void Deconstruct(out string name, out object? value, out bool isSensitive)
{
name = Name;
value = Value;
isSensitive = IsSensitive;
}
}

/// <summary>
/// A snapshot of a resource command.
Expand Down
30 changes: 15 additions & 15 deletions src/Aspire.Hosting/Dcp/ApplicationExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -618,11 +618,11 @@ private CustomResourceSnapshot ToSnapshot(Container container, CustomResourceSna
// Map a container exit code of -1 (unknown) to null
ExitCode = container.Status?.ExitCode is null or Conventions.UnknownExitCode ? null : container.Status.ExitCode,
Properties = [
new(KnownProperties.Container.Image, container.Spec.Image, IsSensitive: false),
new(KnownProperties.Container.Id, containerId, IsSensitive: false),
new(KnownProperties.Container.Command, container.Spec.Command, IsSensitive: false),
new(KnownProperties.Container.Args, container.Status?.EffectiveArgs ?? [], IsSensitive: true),
new(KnownProperties.Container.Ports, GetPorts(), IsSensitive: false),
new(KnownProperties.Container.Image, container.Spec.Image),
new(KnownProperties.Container.Id, containerId),
new(KnownProperties.Container.Command, container.Spec.Command),
new(KnownProperties.Container.Args, container.Status?.EffectiveArgs ?? []) { IsSensitive = true },
new(KnownProperties.Container.Ports, GetPorts()),
],
EnvironmentVariables = environment,
CreationTimeStamp = container.Metadata.CreationTimestamp?.ToLocalTime(),
Expand Down Expand Up @@ -678,11 +678,11 @@ private CustomResourceSnapshot ToSnapshot(Executable executable, CustomResourceS
State = state,
ExitCode = executable.Status?.ExitCode,
Properties = [
new(KnownProperties.Executable.Path, executable.Spec.ExecutablePath, IsSensitive: false),
new(KnownProperties.Executable.WorkDir, executable.Spec.WorkingDirectory, IsSensitive: false),
new(KnownProperties.Executable.Args, executable.Status?.EffectiveArgs ?? [], IsSensitive: true),
new(KnownProperties.Executable.Pid, executable.Status?.ProcessId, IsSensitive: false),
new(KnownProperties.Project.Path, projectPath, IsSensitive: false)
new(KnownProperties.Executable.Path, executable.Spec.ExecutablePath),
new(KnownProperties.Executable.WorkDir, executable.Spec.WorkingDirectory),
new(KnownProperties.Executable.Args, executable.Status?.EffectiveArgs ?? []) { IsSensitive = true },
new(KnownProperties.Executable.Pid, executable.Status?.ProcessId),
new(KnownProperties.Project.Path, projectPath)
],
EnvironmentVariables = environment,
CreationTimeStamp = executable.Metadata.CreationTimestamp?.ToLocalTime(),
Expand All @@ -696,10 +696,10 @@ private CustomResourceSnapshot ToSnapshot(Executable executable, CustomResourceS
State = state,
ExitCode = executable.Status?.ExitCode,
Properties = [
new(KnownProperties.Executable.Path, executable.Spec.ExecutablePath, IsSensitive: false),
new(KnownProperties.Executable.WorkDir, executable.Spec.WorkingDirectory, IsSensitive: false),
new(KnownProperties.Executable.Args, executable.Status?.EffectiveArgs ?? [], IsSensitive: true),
new(KnownProperties.Executable.Pid, executable.Status?.ProcessId, IsSensitive: false)
new(KnownProperties.Executable.Path, executable.Spec.ExecutablePath),
new(KnownProperties.Executable.WorkDir, executable.Spec.WorkingDirectory),
new(KnownProperties.Executable.Args, executable.Status?.EffectiveArgs ?? []) { IsSensitive = true },
new(KnownProperties.Executable.Pid, executable.Status?.ProcessId)
],
EnvironmentVariables = environment,
CreationTimeStamp = executable.Metadata.CreationTimestamp?.ToLocalTime(),
Expand Down Expand Up @@ -1482,7 +1482,7 @@ await notificationService.PublishUpdateAsync(cr.ModelResource, s => s with
{
State = "Starting",
Properties = [
new(KnownProperties.Container.Image, cr.ModelResource.TryGetContainerImageName(out var imageName) ? imageName : "", IsSensitive: false),
new(KnownProperties.Container.Image, cr.ModelResource.TryGetContainerImageName(out var imageName) ? imageName : ""),
],
ResourceType = KnownResourceTypes.Container
})
Expand Down
8 changes: 4 additions & 4 deletions src/Aspire.Hosting/ParameterResourceBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,21 +139,21 @@ internal static IResourceBuilder<ParameterResource> AddParameter(this IDistribut
// hide parameters by default
State = KnownResourceStates.Hidden,
Properties = [
new("parameter.secret", secret.ToString(), IsSensitive: false),
new(CustomResourceKnownProperties.Source, configurationKey, IsSensitive: secret)
new("parameter.secret", secret.ToString()),
new(CustomResourceKnownProperties.Source, configurationKey) { IsSensitive = secret }
]
};

try
{
state = state with { Properties = [.. state.Properties, new("Value", resource.Value, IsSensitive: secret)] };
state = state with { Properties = [.. state.Properties, new("Value", resource.Value) { IsSensitive = secret }] };
}
catch (DistributedApplicationException ex)
{
state = state with
{
State = new ResourceStateSnapshot("Configuration missing", KnownResourceStateStyles.Error),
Properties = [.. state.Properties, new("Value", ex.Message, IsSensitive: false)]
Properties = [.. state.Properties, new("Value", ex.Message)]
};

builder.Services.AddLifecycleHook((sp) => new WriteParameterLogsHook(
Expand Down
1 change: 1 addition & 0 deletions src/Aspire.Hosting/PublicAPI.Shipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ Aspire.Hosting.ApplicationModel.ResourceNotificationService.WatchAsync(System.Th
Aspire.Hosting.ApplicationModel.ResourcePropertySnapshot
Aspire.Hosting.ApplicationModel.ResourcePropertySnapshot.Name.get -> string!
Aspire.Hosting.ApplicationModel.ResourcePropertySnapshot.Name.init -> void
Aspire.Hosting.ApplicationModel.ResourcePropertySnapshot.ResourcePropertySnapshot(string! Name, object? Value) -> void
Aspire.Hosting.ApplicationModel.ResourcePropertySnapshot.Value.get -> object?
Aspire.Hosting.ApplicationModel.ResourcePropertySnapshot.Value.init -> void
Aspire.Hosting.ApplicationModel.ResourceSnapshotAnnotation
Expand Down
1 change: 0 additions & 1 deletion src/Aspire.Hosting/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ Aspire.Hosting.ApplicationModel.ResourceNotificationService.ResourceNotification
Aspire.Hosting.ApplicationModel.ResourceNotificationService.WaitForResourceAsync(string! resourceName, System.Func<Aspire.Hosting.ApplicationModel.ResourceEvent!, bool>! predicate, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.Task<Aspire.Hosting.ApplicationModel.ResourceEvent!>!
Aspire.Hosting.ApplicationModel.ResourcePropertySnapshot.IsSensitive.get -> bool
Aspire.Hosting.ApplicationModel.ResourcePropertySnapshot.IsSensitive.init -> void
Aspire.Hosting.ApplicationModel.ResourcePropertySnapshot.ResourcePropertySnapshot(string! Name, object? Value, bool IsSensitive) -> void
Aspire.Hosting.ApplicationModel.UpdateCommandStateContext
Aspire.Hosting.ApplicationModel.UpdateCommandStateContext.ResourceSnapshot.get -> Aspire.Hosting.ApplicationModel.CustomResourceSnapshot!
Aspire.Hosting.ApplicationModel.UpdateCommandStateContext.ResourceSnapshot.init -> void
Expand Down

0 comments on commit a506f6a

Please sign in to comment.