-
Notifications
You must be signed in to change notification settings - Fork 151
Generate fake proj for dependabot #1336
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
46324be
Generate fake proj for dependabot
colin-higgins 3c3a480
Typo in the fake proj
colin-higgins b988e21
Add dependabot config
colin-higgins 7fa60a6
Use accurate label and newlines
colin-higgins ba115c0
Limit dependabot to only the vendors proj for now
colin-higgins 0a6b2ed
use proper extension
colin-higgins 94a6b5c
Add links to have easy way to verify packages exist
colin-higgins ccd9967
rename file with template word
colin-higgins File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
version: 1 | ||
update_configs: | ||
- package_manager: "dotnet:nuget" | ||
directory: "/honeypot" | ||
update_schedule: "daily" | ||
default_labels: | ||
- "vendors" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<Project Sdk="Microsoft.NET.Sdk.Web"> | ||
|
||
<PropertyGroup> | ||
<TargetFrameworks>netcoreapp3.1</TargetFrameworks> | ||
<RootNamespace>Datadog.Dependabot.Honeypot</RootNamespace> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<!-- https://www.nuget.org/packages/Serilog/2.8.0 --> | ||
<PackageReference Include="Serilog" Version="2.8.0" /> | ||
|
||
<!-- https://www.nuget.org/packages/Serilog.Sinks.File/4.0.0 --> | ||
<PackageReference Include="Serilog.Sinks.File" Version="4.0.0" /> | ||
|
||
<!-- https://www.nuget.org/packages/StatsdClient/6.0.0 --> | ||
<PackageReference Include="StatsdClient" Version="6.0.0" /> | ||
|
||
<!-- https://www.nuget.org/packages/MessagePack/1.9.3 --> | ||
<PackageReference Include="MessagePack" Version="1.9.3" /> | ||
|
||
<!-- https://www.nuget.org/packages/Newtonsoft.Json/12.0.1 --> | ||
<PackageReference Include="Newtonsoft.Json" Version="12.0.1" /> | ||
|
||
</ItemGroup> | ||
|
||
</Project> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<Project Sdk="Microsoft.NET.Sdk.Web"> | ||
|
||
<PropertyGroup> | ||
<TargetFrameworks>netcoreapp3.1</TargetFrameworks> | ||
<RootNamespace>Datadog.Dependabot.Honeypot</RootNamespace> | ||
</PropertyGroup> | ||
|
||
<ItemGroup>##PACKAGE_REFS## | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Text; | ||
using System.Text.RegularExpressions; | ||
|
||
namespace UpdateVendors | ||
{ | ||
public class VendoredDependency | ||
{ | ||
private const string AutoGeneratedMessage = @"//------------------------------------------------------------------------------ | ||
// <auto-generated /> | ||
// This file was automatically generated by the UpdateVendors tool. | ||
//------------------------------------------------------------------------------ | ||
"; | ||
|
||
static VendoredDependency() | ||
{ | ||
Add( | ||
libraryName: "Serilog", | ||
version: "2.8.0", | ||
downloadUrl: "https://github.com/serilog/serilog/archive/v2.8.0.zip", | ||
pathToSrc: new[] { "serilog-2.8.0", "src", "Serilog" }, | ||
transform: filePath => RewriteCsFileWithStandardTransform(filePath, originalNamespace: "Serilog")); | ||
|
||
Add( | ||
libraryName: "Serilog.Sinks.File", | ||
version: "4.0.0", | ||
downloadUrl: "https://github.com/serilog/serilog-sinks-file/archive/v4.0.0.zip", | ||
pathToSrc: new[] { "serilog-sinks-file-4.0.0", "src", "Serilog.Sinks.File" }, | ||
transform: filePath => RewriteCsFileWithStandardTransform(filePath, originalNamespace: "Serilog")); | ||
|
||
Add( | ||
libraryName: "StatsdClient", | ||
version: "6.0.0", | ||
downloadUrl: "https://github.com/DataDog/dogstatsd-csharp-client/archive/6.0.0.zip", | ||
pathToSrc: new[] { "dogstatsd-csharp-client-6.0.0", "src", "StatsdClient" }, | ||
transform: filePath => RewriteCsFileWithStandardTransform(filePath, originalNamespace: "StatsdClient")); | ||
|
||
Add( | ||
libraryName: "MessagePack", | ||
version: "1.9.3", | ||
downloadUrl: "https://github.com/neuecc/MessagePack-CSharp/archive/v1.9.3.zip", | ||
pathToSrc: new[] { "MessagePack-CSharp-1.9.3", "src", "MessagePack" }, | ||
transform: filePath => RewriteCsFileWithStandardTransform(filePath, originalNamespace: "MessagePack")); | ||
|
||
Add( | ||
libraryName: "Newtonsoft.Json", | ||
version: "12.0.1", | ||
downloadUrl: "https://github.com/JamesNK/Newtonsoft.Json/archive/12.0.1.zip", | ||
pathToSrc: new[] { "Newtonsoft.Json-12.0.1", "src", "Newtonsoft.Json" }, | ||
transform: filePath => RewriteCsFileWithStandardTransform(filePath, originalNamespace: "Newtonsoft.Json")); | ||
} | ||
|
||
public static List<VendoredDependency> All { get; set; } = new List<VendoredDependency>(); | ||
|
||
public string LibraryName { get; set; } | ||
|
||
public string Version { get; set; } | ||
|
||
public string DownloadUrl { get; set; } | ||
|
||
public string[] PathToSrc { get; set; } | ||
|
||
public Action<string> Transform { get; set; } | ||
|
||
private static void Add( | ||
string libraryName, | ||
string version, | ||
string downloadUrl, | ||
string[] pathToSrc, | ||
Action<string> transform) | ||
{ | ||
All.Add(new VendoredDependency() | ||
{ | ||
LibraryName = libraryName, | ||
Version = version, | ||
DownloadUrl = downloadUrl, | ||
PathToSrc = pathToSrc, | ||
Transform = transform, | ||
}); | ||
} | ||
|
||
private static void RewriteCsFileWithStandardTransform(string filePath, string originalNamespace, Func<string, string, string> extraTransform = null) | ||
{ | ||
if (string.Equals(Path.GetExtension(filePath), ".cs", StringComparison.OrdinalIgnoreCase)) | ||
{ | ||
RewriteFileWithTransform( | ||
filePath, | ||
content => | ||
{ | ||
// Disable analyzer | ||
var builder = new StringBuilder(AutoGeneratedMessage, content.Length * 2); | ||
|
||
builder.Append(content); | ||
|
||
// Special Newtonsoft.Json processing | ||
if (originalNamespace.Equals("Newtonsoft.Json")) | ||
{ | ||
builder.Replace($"using ErrorEventArgs = Newtonsoft.Json.Serialization.ErrorEventArgs", "using ErrorEventArgs = Datadog.Trace.Vendors.Newtonsoft.Json.Serialization.ErrorEventArgs"); | ||
|
||
if (content.Contains("using Newtonsoft.Json.Serialization;")) | ||
{ | ||
builder.Replace($"Func<", $"System.Func<"); | ||
builder.Replace($"Action<", $"System.Action<"); | ||
} | ||
} | ||
|
||
// Prevent namespace conflicts | ||
builder.Replace($"using {originalNamespace}", $"using Datadog.Trace.Vendors.{originalNamespace}"); | ||
builder.Replace($"namespace {originalNamespace}", $"namespace Datadog.Trace.Vendors.{originalNamespace}"); | ||
builder.Replace($"[CLSCompliant(false)]", $"// [CLSCompliant(false)]"); | ||
|
||
// Don't expose anything we don't intend to | ||
// by replacing all "public" access modifiers with "internal" | ||
return Regex.Replace( | ||
builder.ToString(), | ||
@"public(\s+((abstract|sealed|static)\s+)?(partial\s+)?(class|readonly\s+struct|struct|interface|enum|delegate))", | ||
match => $"internal{match.Groups[1]}"); | ||
}); | ||
} | ||
} | ||
|
||
private static void RewriteFileWithTransform(string filePath, Func<string, string> transform) | ||
{ | ||
var fileContent = File.ReadAllText(filePath); | ||
fileContent = transform(fileContent); | ||
// Normalize text to use CRLF line endings so we have deterministic results | ||
fileContent = fileContent.Replace("\r\n", "\n").Replace("\n", "\r\n"); | ||
File.WriteAllText( | ||
filePath, | ||
fileContent, | ||
new UTF8Encoding(encoderShouldEmitUTF8Identifier: false)); | ||
} | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why
Honeypot
?Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seemed like an apt name.
https://en.wikipedia.org/wiki/Honeypot_(computing)
It's not an attacker, but it isn't a REAL project: It's a fake project designed to attract the dependabot.
🍯 🐝 🐝 🐝
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I didn't think of it that way. Thanks.