Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Embedded files support; determinism #1

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions NuGet.config
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@
<package pattern="Microsoft.Build.*" />
<package pattern="Microsoft.Build" />
<package pattern="Microsoft.NET.StringTools" />
</packageSource>
<packageSource key="offline-packages">
<package pattern="Microsoft.Build.*" />
<package pattern="Microsoft.Build" />
<package pattern="Microsoft.NET.StringTools" />
</packageSource>
</packageSourceMapping>

Expand Down
3 changes: 2 additions & 1 deletion Packages.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<Project>
<Import Project="dependabot\Packages.props" />
<ItemGroup>
<PackageVersion Include="Microsoft.Build" Version="17.8.0-preview-23424-02" />
<!-- <PackageVersion Include="Microsoft.Build" Version="17.8.0-preview-23424-02" /> -->
<PackageVersion Include="Microsoft.Build" Version="17.8.0-dev-23465-01" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@ namespace Microsoft.Build.BinlogRedactor.BinaryLog;

public interface IBinlogProcessor
{
/// <summary>
/// Passes all string data from the input file to the <see cref="ISensitiveDataProcessor"/> and writes the
/// resulting binlog file so that only the appropriate textual data is altered, while result is still valid binlog.
/// </summary>
Task<BinlogRedactorErrorCode> ProcessBinlog(
string inputFileName,
string outputFileName,
ISensitiveDataProcessor sensitiveDataProcessor,
CancellationToken cancellationToken);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

public interface ISensitiveDataProcessor
{
/// <summary>
/// Processes the given text and if needed, replaces sensitive data with a placeholder.
/// </summary>
string ReplaceSensitiveData(string text);
bool IsSensitiveData(string text);
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,29 @@ public Task<BinlogRedactorErrorCode> ProcessBinlog(
// Quick way:
//
BinaryLogReplayEventSource originalEventsSource = new BinaryLogReplayEventSource();
BinaryLogger bl = new BinaryLogger()
BuildEventArgsReader originalBuildEventsReader =
BinaryLogReplayEventSource.OpenBuildEventsReader(inputFileName);
BinaryLogger outputBinlog = new BinaryLogger()
{
Parameters = $"LogFile={outputFileName}",
Parameters = $"LogFile={outputFileName};ProjectImports=Replay;ReplayInitialInfo",
};
bl.Initialize(originalEventsSource);
originalEventsSource.NotificationsSourceCreated += notifications => notifications.StringReadDone += args =>
args.StringToBeUsed = sensitiveDataProcessor.ReplaceSensitiveData(args.OriginalString);
originalEventsSource.Replay(inputFileName, cancellationToken);

originalBuildEventsReader.StringReadDone += HandleStringRead;
originalBuildEventsReader.ArchiveFileEncountered += ((Action<StringReadEventArgs>)HandleStringRead).ToArchiveFileHandler();

outputBinlog.Initialize(originalEventsSource);
originalEventsSource.Replay(originalBuildEventsReader, cancellationToken);
cancellationToken.ThrowIfCancellationRequested();
bl.Shutdown();
outputBinlog.Shutdown();

// TODO: error handling

return Task.FromResult(BinlogRedactorErrorCode.Success);

void HandleStringRead(StringReadEventArgs args)
{
args.StringToBeUsed = sensitiveDataProcessor.ReplaceSensitiveData(args.OriginalString);
}
}


Expand Down
Loading