-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from danielklecha/master
support GitHub token, cancellation token, custom configuration name
- Loading branch information
Showing
31 changed files
with
147 additions
and
93 deletions.
There are no files selected for viewing
This file contains 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 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 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 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
File renamed without changes.
File renamed without changes.
This file contains 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,12 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace DotnetThirdPartyNotices.Models; | ||
|
||
internal class ResolverOptions | ||
{ | ||
public string? GitHubToken { get; set; } | ||
} |
File renamed without changes.
1 change: 1 addition & 0 deletions
1
src/DotnetThirdPartyNotices/Program.cs → DotnetThirdPartyNotices/Program.cs
This file contains 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
File renamed without changes.
16 changes: 11 additions & 5 deletions
16
...ices/Services/GithubRawLicenseResolver.cs → ...ices/Services/GithubRawLicenseResolver.cs
This file contains 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 |
---|---|---|
@@ -1,20 +1,26 @@ | ||
namespace DotnetThirdPartyNotices.Services; | ||
using DotnetThirdPartyNotices.Models; | ||
using System.Net.Http.Headers; | ||
using System.Text; | ||
|
||
namespace DotnetThirdPartyNotices.Services; | ||
|
||
internal class GithubRawLicenseResolver(IHttpClientFactory httpClientFactory) : ILicenseUriLicenseResolver | ||
{ | ||
public bool CanResolve(Uri uri) => uri.Host == "github.com"; | ||
public Task<bool> CanResolveAsync(Uri uri, ResolverOptions resolverOptions, CancellationToken cancellationToken) => Task.FromResult(uri.Host == "github.com"); | ||
|
||
public async Task<string?> Resolve(Uri uri) | ||
public async Task<string?> ResolveAsync(Uri uri, ResolverOptions resolverOptions, CancellationToken cancellationToken) | ||
{ | ||
var uriBuilder = new UriBuilder(uri) { Host = "raw.githubusercontent.com" }; | ||
uriBuilder.Path = uriBuilder.Path.Replace("/blob", string.Empty); | ||
var httpClient = httpClientFactory.CreateClient(); | ||
// https://developer.github.com/v3/#user-agent-required | ||
httpClient.DefaultRequestHeaders.Add("User-Agent", "DotnetLicense"); | ||
var httpResponseMessage = await httpClient.GetAsync(uriBuilder.Uri); | ||
if (!string.IsNullOrEmpty(resolverOptions.GitHubToken)) | ||
httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", resolverOptions.GitHubToken); | ||
var httpResponseMessage = await httpClient.GetAsync(uriBuilder.Uri, cancellationToken); | ||
if (!httpResponseMessage.IsSuccessStatusCode | ||
|| httpResponseMessage.Content.Headers.ContentType?.MediaType != "text/plain") | ||
return null; | ||
return await httpResponseMessage.Content.ReadAsStringAsync(); | ||
return await httpResponseMessage.Content.ReadAsStringAsync(cancellationToken); | ||
} | ||
} |
This file contains 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
11 changes: 11 additions & 0 deletions
11
DotnetThirdPartyNotices/Services/IFileVersionInfoLicenseResolver.cs
This file contains 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 @@ | ||
using DotnetThirdPartyNotices.Models; | ||
using System.Diagnostics; | ||
using System.Threading.Tasks; | ||
|
||
namespace DotnetThirdPartyNotices.Services; | ||
|
||
internal interface IFileVersionInfoLicenseResolver : ILicenseResolver | ||
{ | ||
Task<bool> CanResolveAsync(FileVersionInfo fileVersionInfo, CancellationToken cancellationToken); | ||
Task<string?> ResolveAsync(FileVersionInfo fileVersionInfo, ResolverOptions resolverOptions, CancellationToken cancellationToken); | ||
} |
File renamed without changes.
This file contains 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,8 @@ | ||
using DotnetThirdPartyNotices.Models; | ||
|
||
namespace DotnetThirdPartyNotices.Services; | ||
|
||
internal interface ILicenseService | ||
{ | ||
Task<string?> ResolveFromResolvedFileInfoAsync(ResolvedFileInfo resolvedFileInfo, ResolverOptions resolverOptions, CancellationToken cancellationToken); | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains 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,9 @@ | ||
using DotnetThirdPartyNotices.Models; | ||
|
||
namespace DotnetThirdPartyNotices.Services; | ||
|
||
internal interface IUriLicenseResolver | ||
{ | ||
Task<bool> CanResolveAsync(Uri licenseUri, ResolverOptions resolverOptions, CancellationToken cancellationToken); | ||
Task<string?> ResolveAsync(Uri licenseUri, ResolverOptions resolverOptions, CancellationToken cancellationToken); | ||
} |
Oops, something went wrong.