mirror of
https://github.com/collinbarrett/FilterLists.git
synced 2026-03-11 09:04:27 +00:00
ren Settings classes
This commit is contained in:
parent
d0b76d7b1c
commit
3ed85260c5
5 changed files with 27 additions and 19 deletions
|
|
@ -1,8 +1,6 @@
|
|||
namespace FilterLists.Agent.AppSettings
|
||||
{
|
||||
#pragma warning disable CA1724
|
||||
public class ApplicationInsights
|
||||
#pragma warning restore CA1724
|
||||
public class ApplicationInsightsSettings
|
||||
{
|
||||
public string InstrumentationKey { get; set; }
|
||||
}
|
||||
|
|
@ -3,7 +3,7 @@
|
|||
namespace FilterLists.Agent.AppSettings
|
||||
{
|
||||
[UsedImplicitly]
|
||||
public class ConnectionStrings
|
||||
public class ConnectionStringsSettings
|
||||
{
|
||||
public string FilterListsConnection { get; set; }
|
||||
}
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
namespace FilterLists.Agent.AppSettings
|
||||
{
|
||||
public class GitHub
|
||||
public class GitHubSettings
|
||||
{
|
||||
public string ProductHeaderValue { get; set; }
|
||||
public string PersonalAccessToken { get; set; }
|
||||
|
|
@ -1,4 +1,5 @@
|
|||
using System.Net.Http;
|
||||
using System;
|
||||
using System.Net.Http;
|
||||
using CommandLine;
|
||||
using FilterLists.Agent.AppSettings;
|
||||
using FilterLists.Agent.Core.Interfaces;
|
||||
|
|
@ -36,9 +37,17 @@ private static void AddConfiguration(this IServiceCollection services)
|
|||
.AddJsonFile("appsettings.Development.json", true, true)
|
||||
#endif
|
||||
.Build();
|
||||
services.Configure<ApplicationInsights>(config.GetSection(nameof(ApplicationInsights)));
|
||||
services.Configure<ConnectionStrings>(config.GetSection(nameof(ConnectionStrings)));
|
||||
services.Configure<GitHub>(config.GetSection(nameof(GitHub)));
|
||||
services.Configure<ApplicationInsightsSettings>(
|
||||
config.GetSection(nameof(ApplicationInsightsSettings).RemoveSettingsSuffix()));
|
||||
services.Configure<ConnectionStringsSettings>(
|
||||
config.GetSection(nameof(ConnectionStringsSettings).RemoveSettingsSuffix()));
|
||||
services.Configure<GitHubSettings>(
|
||||
config.GetSection(nameof(GitHubSettings).RemoveSettingsSuffix()));
|
||||
}
|
||||
|
||||
private static string RemoveSettingsSuffix(this string section)
|
||||
{
|
||||
return section.Replace("Settings", "", StringComparison.Ordinal);
|
||||
}
|
||||
|
||||
private static void AddLoggingCustom(this IServiceCollection services)
|
||||
|
|
@ -46,7 +55,8 @@ private static void AddLoggingCustom(this IServiceCollection services)
|
|||
services.AddLogging(b =>
|
||||
{
|
||||
b.AddConsole();
|
||||
var appInsightsConfig = b.Services.BuildServiceProvider().GetService<IOptions<ApplicationInsights>>();
|
||||
var appInsightsConfig = b.Services.BuildServiceProvider()
|
||||
.GetService<IOptions<ApplicationInsightsSettings>>();
|
||||
b.AddApplicationInsights(appInsightsConfig.Value.InstrumentationKey);
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,16 +20,16 @@ public class AgentGitHubClient : IAgentGitHubClient
|
|||
{
|
||||
private const string ExceptionMessageSuffix = " from the GitHub API.";
|
||||
private readonly GitHubClient _gitHubClient;
|
||||
private readonly GitHub _gitHubOptions;
|
||||
private readonly GitHubSettings _gitHubSettings;
|
||||
private readonly ILogger<AgentGitHubClient> _logger;
|
||||
|
||||
public AgentGitHubClient(IOptions<GitHub> gitHubOptions, ILogger<AgentGitHubClient> logger)
|
||||
public AgentGitHubClient(IOptions<GitHubSettings> gitHubSettings, ILogger<AgentGitHubClient> logger)
|
||||
{
|
||||
_gitHubOptions = gitHubOptions.Value;
|
||||
_gitHubSettings = gitHubSettings.Value;
|
||||
_logger = logger;
|
||||
_gitHubClient = new GitHubClient(new ProductHeaderValue(_gitHubOptions.ProductHeaderValue))
|
||||
_gitHubClient = new GitHubClient(new ProductHeaderValue(_gitHubSettings.ProductHeaderValue))
|
||||
{
|
||||
Credentials = new Credentials(_gitHubOptions.PersonalAccessToken)
|
||||
Credentials = new Credentials(_gitHubSettings.PersonalAccessToken)
|
||||
};
|
||||
}
|
||||
|
||||
|
|
@ -37,8 +37,8 @@ public async Task<IReadOnlyList<Issue>> GetAllIssues(RepositoryIssueRequest repo
|
|||
{
|
||||
try
|
||||
{
|
||||
return await _gitHubClient.Issue.GetAllForRepository(_gitHubOptions.RepositoryOwner,
|
||||
_gitHubOptions.Repository, repositoryIssueRequest);
|
||||
return await _gitHubClient.Issue.GetAllForRepository(_gitHubSettings.RepositoryOwner,
|
||||
_gitHubSettings.Repository, repositoryIssueRequest);
|
||||
}
|
||||
catch (ApiException ex)
|
||||
{
|
||||
|
|
@ -51,7 +51,7 @@ public async Task<Issue> CreateIssue(NewIssue newIssue)
|
|||
{
|
||||
try
|
||||
{
|
||||
return await _gitHubClient.Issue.Create(_gitHubOptions.RepositoryOwner, _gitHubOptions.Repository,
|
||||
return await _gitHubClient.Issue.Create(_gitHubSettings.RepositoryOwner, _gitHubSettings.Repository,
|
||||
newIssue);
|
||||
}
|
||||
catch (ApiException ex)
|
||||
|
|
@ -65,7 +65,7 @@ public async Task<Issue> UpdateIssue(int issueNumber, IssueUpdate issueUpdate)
|
|||
{
|
||||
try
|
||||
{
|
||||
return await _gitHubClient.Issue.Update(_gitHubOptions.RepositoryOwner, _gitHubOptions.Repository,
|
||||
return await _gitHubClient.Issue.Update(_gitHubSettings.RepositoryOwner, _gitHubSettings.Repository,
|
||||
issueNumber, issueUpdate);
|
||||
}
|
||||
catch (ApiException ex)
|
||||
|
|
|
|||
Loading…
Reference in a new issue