Compare commits

...

3 Commits

Author SHA1 Message Date
Jeff Leung 1ee556eb4e Add an option to configure the netbox host 2022-12-13 09:16:59 -08:00
Jeff Leung 159bbf399c Mark things as non-static and remove unused code.
Also, build the URI instead of hardcoding things. Assume HTTPS over 443 unless specified
2022-12-13 09:16:32 -08:00
Jeff Leung d478291c6b Update readme 2022-12-10 20:53:00 -08:00
4 changed files with 20 additions and 2945 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,15 +30,16 @@ namespace AS1024.CommunityDocumentationPage.Controllers
return View(filtered);
}
private static async Task<RouteTargets> ReadAPI(string token)
[NonAction]
private async Task<RouteTargets> ReadAPI(string token)
{
try
{
HttpClient client = new();
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/");
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Token", token);
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

View File

@ -8,5 +8,6 @@
"APIKey": "",
"ASN": "",
"NOCEmail": "",
"AllowedHosts": "*"
"AllowedHosts": "*",
"NetBoxHost" : ""
}

View File

@ -25,4 +25,5 @@ This web app must be configured with asppsettings.json with the following values
## Values
- ``APIKey`` - This is a netbox API Key. We strongly recommend that you do this as a read only thing
- ``ASN`` - This is required, without it, the AS's will not display properly
- ``ASN`` - This is required, without it, the AS's will not display properly
- ``NOCEmail`` - This is to display for NOC E-Mail Inquries