Mark things as non-static and remove unused code.

Also, build the URI instead of hardcoding things. Assume HTTPS over 443 unless specified
This commit is contained in:
Jeff Leung 2022-12-13 09:16:32 -08:00
parent d478291c6b
commit 159bbf399c
2 changed files with 16 additions and 2943 deletions

View File

@ -1,7 +1,6 @@
using AS1024.CommunityDocumentationPage.Models;
using Microsoft.AspNetCore.Mvc;
using System.Diagnostics;
using NetBox;
using System.Net.Http;
using System.Net.Http.Headers;
using Newtonsoft.Json;
@ -31,7 +30,8 @@ namespace AS1024.CommunityDocumentationPage.Controllers
return View(filtered);
}
private static async Task<RouteTargets> ReadAPI(string token)
[NonAction]
private async Task<RouteTargets> ReadAPI(string token)
{
try
{
@ -39,7 +39,7 @@ namespace AS1024.CommunityDocumentationPage.Controllers
client.DefaultRequestHeaders.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Token", token);
var result = await client.GetAsync("https://netbox.as1024.net/api/ipam/route-targets/");
var result = await client.GetAsync(BuildNetBoxURI());
var stringResult = await result.Content.ReadAsStringAsync();
return JsonConvert.DeserializeObject<RouteTargets>(stringResult);
} catch
@ -48,6 +48,18 @@ namespace AS1024.CommunityDocumentationPage.Controllers
}
}
[NonAction]
protected Uri BuildNetBoxURI()
{
var endUrl = new UriBuilder();
endUrl.Path = "/api/ipam/route-targets";
endUrl.Host = Configuration["NetBoxHost"];
endUrl.Scheme = "https";
return endUrl.Uri;
}
public IActionResult Privacy()
{
return View();

File diff suppressed because it is too large Load Diff