Skip to content

Commit

Permalink
Sanitize another Docker telemetry event (#1164)
Browse files Browse the repository at this point in the history
  • Loading branch information
grvillic authored Jun 7, 2024
1 parent 341b036 commit 2b5b657
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/Microsoft.ComponentDetection.Common/DockerService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public async Task<bool> ImageExistsLocallyAsync(string image, CancellationToken
};
try
{
var imageInspectResponse = await Client.Images.InspectImageAsync(image, cancellationToken);
var imageInspectResponse = await this.InspectImageAndSanitizeVarsAsync(image, cancellationToken);
record.ImageInspectResponse = JsonSerializer.Serialize(imageInspectResponse);
return true;
}
Expand All @@ -82,6 +82,13 @@ public async Task<bool> ImageExistsLocallyAsync(string image, CancellationToken
}
}

private async Task<ImageInspectResponse> InspectImageAndSanitizeVarsAsync(string image, CancellationToken cancellationToken = default)
{
var imageInspectResponse = await Client.Images.InspectImageAsync(image, cancellationToken);
this.SanitizeEnvironmentVariables(imageInspectResponse);
return imageInspectResponse;
}

public async Task<bool> TryPullImageAsync(string image, CancellationToken cancellationToken = default)
{
using var record = new DockerServiceTryPullImageTelemetryRecord
Expand Down Expand Up @@ -135,10 +142,7 @@ public async Task<ContainerDetails> InspectImageAsync(string image, Cancellation
};
try
{
var imageInspectResponse = await Client.Images.InspectImageAsync(image, cancellationToken);

this.SanitizeEnvironmentVariables(imageInspectResponse);

var imageInspectResponse = await this.InspectImageAndSanitizeVarsAsync(image, cancellationToken);
record.ImageInspectResponse = JsonSerializer.Serialize(imageInspectResponse);

var baseImageRef = string.Empty;
Expand Down

0 comments on commit 2b5b657

Please sign in to comment.