Baby steps on code refactoring
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
using AS1024.CommunityDocumentationPage.Interfaces;
|
||||
using AS1024.CommunityDocumentationPage.Models;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Newtonsoft.Json;
|
||||
using System.Net.Http.Headers;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace AS1024.CommunityDocumentationPage.DIScopes
|
||||
{
|
||||
public class NetboxBgpCommunityDocumentation : IBgpCommunityDocumentation
|
||||
{
|
||||
private readonly IConfiguration configuration;
|
||||
|
||||
public string DcimName => "netbox";
|
||||
private HttpClient client;
|
||||
|
||||
public NetboxBgpCommunityDocumentation(IConfiguration configuration)
|
||||
{
|
||||
this.configuration = configuration;
|
||||
client = new HttpClient();
|
||||
}
|
||||
|
||||
public async Task<RouteTargets> GetBgpCommunities()
|
||||
{
|
||||
client.DefaultRequestHeaders.Clear();
|
||||
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
|
||||
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Token", configuration["APIKey"]);
|
||||
var result = await client.GetAsync(BuildNetBoxURI().AbsoluteUri);
|
||||
var stringResult = await result.Content.ReadAsStringAsync();
|
||||
#pragma warning disable CS8603 // Possible null reference return.
|
||||
return JsonConvert.DeserializeObject<RouteTargets>(stringResult);
|
||||
#pragma warning restore CS8603 // Possible null reference return.
|
||||
}
|
||||
|
||||
protected Uri BuildNetBoxURI()
|
||||
{
|
||||
var endUrl = new UriBuilder
|
||||
{
|
||||
Path = "/api/ipam/route-targets",
|
||||
Host = configuration["NetBoxHost"],
|
||||
Scheme = "https"
|
||||
};
|
||||
|
||||
return endUrl.Uri;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user