Compare commits
26 Commits
f38afd75b8
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 48a1d6f984 | |||
| 79090e91d6 | |||
| 7d2d27c609 | |||
| c32f3596ec | |||
| 1fd587634b | |||
| 4c17c375ae | |||
| bf38c7dc1a | |||
| afb2102702 | |||
| 9c80ad14f3 | |||
| 7b6794e7e9 | |||
| e3f093b53a | |||
| 5f18fe037c | |||
| ab2793d92a | |||
| 9fdc60ac48 | |||
| bd8198be2a | |||
| 77e6235b30 | |||
| fc432698a8 | |||
| db29ac0891 | |||
| 672e56d0aa | |||
| 9311ba2b59 | |||
| dbccb586f8 | |||
| 58576796c2 | |||
| 1a3450f6f9 | |||
| 1ee556eb4e | |||
| 159bbf399c | |||
| d478291c6b |
30
.dockerignore
Normal file
30
.dockerignore
Normal file
@@ -0,0 +1,30 @@
|
||||
**/.classpath
|
||||
**/.dockerignore
|
||||
**/.env
|
||||
**/.git
|
||||
**/.gitignore
|
||||
**/.project
|
||||
**/.settings
|
||||
**/.toolstarget
|
||||
**/.vs
|
||||
**/.vscode
|
||||
**/*.*proj.user
|
||||
**/*.dbmdl
|
||||
**/*.jfm
|
||||
**/azds.yaml
|
||||
**/bin
|
||||
**/charts
|
||||
**/docker-compose*
|
||||
**/Dockerfile*
|
||||
**/node_modules
|
||||
**/npm-debug.log
|
||||
**/obj
|
||||
**/secrets.dev.yaml
|
||||
**/values.dev.yaml
|
||||
LICENSE
|
||||
README.md
|
||||
!**/.gitignore
|
||||
!.git/HEAD
|
||||
!.git/config
|
||||
!.git/packed-refs
|
||||
!.git/refs/heads/**
|
||||
@@ -1,14 +1,14 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.2" />
|
||||
<PackageReference Include="System.Text.Json" Version="6.0.7" />
|
||||
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.19.5" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -1,51 +1,40 @@
|
||||
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;
|
||||
using AS1024.CommunityDocumentationPage.Interfaces;
|
||||
|
||||
namespace AS1024.CommunityDocumentationPage.Controllers
|
||||
{
|
||||
public class HomeController : Controller
|
||||
{
|
||||
private readonly ILogger<HomeController> _logger;
|
||||
|
||||
private IConfiguration Configuration { get; }
|
||||
private readonly IBgpCommunity _bgpCommunity;
|
||||
private readonly IConfiguration _configuration;
|
||||
|
||||
public HomeController(ILogger<HomeController> logger,
|
||||
IConfiguration configuration)
|
||||
IConfiguration configuration,
|
||||
IBgpCommunity bgpCommunity)
|
||||
{
|
||||
_logger = logger;
|
||||
Configuration = configuration;
|
||||
_configuration = configuration;
|
||||
_bgpCommunity = bgpCommunity;
|
||||
}
|
||||
|
||||
public async Task<IActionResult> IndexAsync()
|
||||
{
|
||||
var results = await ReadAPI(Configuration["APIKey"]);
|
||||
|
||||
var filtered = results.Results.Where(b => b.Name.StartsWith(Configuration["ASN"]))
|
||||
.ToList();
|
||||
|
||||
return View(filtered);
|
||||
}
|
||||
|
||||
private static async Task<RouteTargets> ReadAPI(string token)
|
||||
[ResponseCache(Duration = 3600)]
|
||||
public async Task<IActionResult> Index()
|
||||
{
|
||||
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/");
|
||||
var stringResult = await result.Content.ReadAsStringAsync();
|
||||
return JsonConvert.DeserializeObject<RouteTargets>(stringResult);
|
||||
} catch
|
||||
var result =
|
||||
await _bgpCommunity.GetCommunities();
|
||||
|
||||
return View(result);
|
||||
} catch (Exception ex)
|
||||
{
|
||||
throw new Exception("Something went wrong?");
|
||||
_logger.LogError($"Failed to obtain data\n{ex}");
|
||||
}
|
||||
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
public IActionResult Privacy()
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
using AS1024.CommunityDocumentationPage.Interfaces;
|
||||
using AS1024.CommunityDocumentationPage.Models;
|
||||
using System.Text.Json;
|
||||
using System.Net.Http.Headers;
|
||||
|
||||
namespace AS1024.CommunityDocumentationPage.DIScopes
|
||||
{
|
||||
public class NetBoxBgpCommunities : IBgpCommunity
|
||||
{
|
||||
protected readonly IConfiguration _configuration;
|
||||
public NetBoxBgpCommunities(IConfiguration configuration)
|
||||
{
|
||||
_configuration = configuration;
|
||||
}
|
||||
string IBgpCommunity.DcimName => "netbox";
|
||||
|
||||
public async Task<ICollection<CommunityTag>> GetCommunities()
|
||||
{
|
||||
var Tags = new List<CommunityTag>();
|
||||
using HttpClient client = new HttpClient();
|
||||
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Token", _configuration["APIKey"]);
|
||||
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
|
||||
HttpResponseMessage result = await client.GetAsync(BuildNetBoxURI());
|
||||
string stringResult = await result.Content.ReadAsStringAsync();
|
||||
var temp =
|
||||
JsonSerializer.Deserialize<RouteTargets>(stringResult, new JsonSerializerOptions{
|
||||
PropertyNamingPolicy = JsonNamingPolicy.SnakeCaseLower
|
||||
});
|
||||
|
||||
foreach (var route in temp.Results)
|
||||
{
|
||||
var community = new CommunityTag
|
||||
{
|
||||
ASN = int.Parse(route.Name.Split(':')[0]),
|
||||
CommunityValue = int.Parse(route.Name.Split(':')[1]),
|
||||
Description = route.Description,
|
||||
Tag = route.Tags
|
||||
};
|
||||
Tags.Add(community);
|
||||
}
|
||||
|
||||
return Tags.OrderBy(b => b.ASN)
|
||||
.ThenBy(b => b.CommunityValue)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
protected Uri BuildNetBoxURI()
|
||||
{
|
||||
UriBuilder endUrl = new UriBuilder
|
||||
{
|
||||
Path = "/api/ipam/route-targets/",
|
||||
Host = _configuration["NetBoxHost"],
|
||||
Scheme = "https"
|
||||
};
|
||||
|
||||
return endUrl.Uri;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
using AS1024.CommunityDocumentationPage.Interfaces;
|
||||
using AS1024.CommunityDocumentationPage.Models;
|
||||
using System.Net.Http.Headers;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace AS1024.CommunityDocumentationPage.DIScopes
|
||||
{
|
||||
public class NetboxBgpCommunityDocumentation : IBgpCommunityDocumentation
|
||||
{
|
||||
private readonly IConfiguration configuration;
|
||||
|
||||
public string DcimName => "netbox";
|
||||
public NetboxBgpCommunityDocumentation(IConfiguration configuration)
|
||||
{
|
||||
this.configuration = configuration;
|
||||
}
|
||||
|
||||
public async Task<RouteTargets> GetBgpCommunities()
|
||||
{
|
||||
using HttpClient client = new HttpClient();
|
||||
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Token", configuration["APIKey"]);
|
||||
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
|
||||
HttpResponseMessage result = await client.GetAsync(BuildNetBoxURI());
|
||||
string stringResult = await result.Content.ReadAsStringAsync();
|
||||
#pragma warning disable CS8603 // Possible null reference return.
|
||||
return JsonSerializer.Deserialize<RouteTargets>(stringResult,
|
||||
new JsonSerializerOptions { PropertyNamingPolicy = JsonNamingPolicy.SnakeCaseLower });
|
||||
#pragma warning restore CS8603 // Possible null reference return.
|
||||
}
|
||||
|
||||
protected Uri BuildNetBoxURI()
|
||||
{
|
||||
UriBuilder endUrl = new UriBuilder
|
||||
{
|
||||
Path = "/api/ipam/route-targets/",
|
||||
Host = configuration["NetBoxHost"],
|
||||
Scheme = "https"
|
||||
};
|
||||
|
||||
return endUrl.Uri;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
namespace AS1024.CommunityDocumentationPage.DIScopes
|
||||
{
|
||||
public static class ValidateBgpCommunity
|
||||
{
|
||||
/// <summary>
|
||||
/// validates if this is a valid standard BGP Community
|
||||
/// </summary>
|
||||
/// <param name="Community">Community string represented as NNN:XXX</param>
|
||||
/// <returns>true if it's a valid bgp community, false if it isn't</returns>
|
||||
public static bool IsValidBgpCommunity(this string Community)
|
||||
{
|
||||
string[] splitStrings =
|
||||
Community.Split(":", StringSplitOptions.RemoveEmptyEntries);
|
||||
|
||||
for (int i = 0; i < 1; i++)
|
||||
{
|
||||
if (!int.TryParse(splitStrings[i], out int communityParsed)
|
||||
&& communityParsed > 65536)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
26
AS1024.CommunityDocumentationPage/Dockerfile
Normal file
26
AS1024.CommunityDocumentationPage/Dockerfile
Normal file
@@ -0,0 +1,26 @@
|
||||
#See https://aka.ms/customizecontainer to learn how to customize your debug container and how Visual Studio uses this Dockerfile to build your images for faster debugging.
|
||||
|
||||
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
|
||||
USER app
|
||||
WORKDIR /app
|
||||
EXPOSE 8080
|
||||
|
||||
FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:8.0 AS build
|
||||
ARG BUILD_CONFIGURATION=Release
|
||||
ARG TARGETARCH
|
||||
WORKDIR /src
|
||||
COPY ["AS1024.CommunityDocumentationPage/AS1024.CommunityDocumentationPage.csproj", "AS1024.CommunityDocumentationPage/"]
|
||||
RUN dotnet restore "./AS1024.CommunityDocumentationPage/./AS1024.CommunityDocumentationPage.csproj" -a $TARGETARCH
|
||||
COPY . .
|
||||
WORKDIR "/src/AS1024.CommunityDocumentationPage"
|
||||
RUN dotnet build "./AS1024.CommunityDocumentationPage.csproj" -c $BUILD_CONFIGURATION -o /app/build -a $TARGETARCH
|
||||
|
||||
FROM --platform=$BUILDPLATFORM build AS publish
|
||||
ARG BUILD_CONFIGURATION=Release
|
||||
ARG TARGETARCH
|
||||
RUN dotnet publish "./AS1024.CommunityDocumentationPage.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false -a $TARGETARCH
|
||||
|
||||
FROM base AS final
|
||||
WORKDIR /app
|
||||
COPY --from=publish /app/publish .
|
||||
ENTRYPOINT ["dotnet", "AS1024.CommunityDocumentationPage.dll"]
|
||||
@@ -0,0 +1,35 @@
|
||||
using AS1024.CommunityDocumentationPage.Models;
|
||||
|
||||
namespace AS1024.CommunityDocumentationPage.Interfaces
|
||||
{
|
||||
/// <summary>
|
||||
/// Abstraction layer on obtaining BGP communities regardless of DCIM system
|
||||
/// </summary>
|
||||
public interface IBgpCommunityDocumentation
|
||||
{
|
||||
/// <summary>
|
||||
/// Read Only field on what the constructor grabs it's data from
|
||||
/// </summary>
|
||||
string DcimName { get; }
|
||||
/// <summary>
|
||||
/// Gets a list of BGP Communities
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
Task<RouteTargets> GetBgpCommunities();
|
||||
}
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public interface IBgpCommunity
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
string DcimName { get; }
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
Task<ICollection<CommunityTag>> GetCommunities();
|
||||
}
|
||||
}
|
||||
37
AS1024.CommunityDocumentationPage/Models/BgpCommunity.cs
Normal file
37
AS1024.CommunityDocumentationPage/Models/BgpCommunity.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
namespace AS1024.CommunityDocumentationPage.Models
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public class BgpCommunity
|
||||
{
|
||||
/// <summary>
|
||||
/// Community Tag
|
||||
/// </summary>
|
||||
public string CommunityTag { get; set; }
|
||||
/// <summary>
|
||||
/// Type of BGP Community
|
||||
/// </summary>
|
||||
public CommunityType BgpCommunityType { get; set; }
|
||||
/// <summary>
|
||||
/// What the community does
|
||||
/// </summary>
|
||||
public string CommunityDescription { get; set; }
|
||||
}
|
||||
|
||||
public enum CommunityType
|
||||
{
|
||||
/// <summary>
|
||||
/// 32 bit community
|
||||
/// </summary>
|
||||
Community,
|
||||
/// <summary>
|
||||
/// Extended community with RT
|
||||
/// </summary>
|
||||
ExtendedCommunity,
|
||||
/// <summary>
|
||||
/// Large BGP Community
|
||||
/// </summary>
|
||||
LargeCommunity
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -35,4 +35,13 @@
|
||||
public string slug { get; set; }
|
||||
public string color { get; set; }
|
||||
}
|
||||
|
||||
public class CommunityTag
|
||||
{
|
||||
public int ASN { get; set; }
|
||||
public int CommunityValue { get; set; }
|
||||
public string FormattedVaule => $"{this.ASN}:{this.CommunityValue}";
|
||||
public string? Description { get; set; }
|
||||
public IList<Tag>? Tag { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,14 @@
|
||||
using AS1024.CommunityDocumentationPage.DIScopes;
|
||||
using AS1024.CommunityDocumentationPage.Interfaces;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
// Add services to the container.
|
||||
builder.Services.AddControllersWithViews();
|
||||
|
||||
builder.Services.AddTransient<IBgpCommunityDocumentation, NetboxBgpCommunityDocumentation>();
|
||||
builder.Services.AddTransient<IBgpCommunity, NetBoxBgpCommunities>();
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
// Configure the HTTP request pipeline.
|
||||
|
||||
@@ -1,21 +1,12 @@
|
||||
{
|
||||
"iisSettings": {
|
||||
"windowsAuthentication": false,
|
||||
"anonymousAuthentication": true,
|
||||
"iisExpress": {
|
||||
"applicationUrl": "http://localhost:49374",
|
||||
"sslPort": 0
|
||||
}
|
||||
},
|
||||
{
|
||||
"profiles": {
|
||||
"AS1024.CommunityDocumentationPage": {
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
"launchBrowser": true,
|
||||
"applicationUrl": "http://localhost:5224",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
},
|
||||
"applicationUrl": "http://localhost:5224"
|
||||
},
|
||||
"IIS Express": {
|
||||
"commandName": "IISExpress",
|
||||
@@ -23,6 +14,23 @@
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
},
|
||||
"Docker": {
|
||||
"commandName": "Docker",
|
||||
"launchBrowser": true,
|
||||
"launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_HTTP_PORTS": "8080"
|
||||
},
|
||||
"publishAllPorts": true
|
||||
}
|
||||
},
|
||||
"iisSettings": {
|
||||
"windowsAuthentication": false,
|
||||
"anonymousAuthentication": true,
|
||||
"iisExpress": {
|
||||
"applicationUrl": "http://localhost:49374",
|
||||
"sslPort": 0
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
@using Microsoft.Extensions.DependencyInjection
|
||||
@inject IConfiguration Configuration
|
||||
@model List<AS1024.CommunityDocumentationPage.Models.Result>
|
||||
@model List<AS1024.CommunityDocumentationPage.Models.CommunityTag>
|
||||
@{
|
||||
ViewData["Title"] = "BGP Communities";
|
||||
}
|
||||
@@ -20,10 +20,10 @@
|
||||
</thead>
|
||||
@foreach (var item in Model) {
|
||||
<tr>
|
||||
<td scope="row">@item.Name</td>
|
||||
<td scope="row">@item.FormattedVaule</td>
|
||||
<td scope="row">@item.Description</td>
|
||||
<td scope="row">
|
||||
@foreach (var tags in item.Tags) {
|
||||
@foreach (var tags in item.Tag) {
|
||||
<div class="d-inline-flex p-2 text-white" style="background-color:#@tags.color">@tags.display</div>
|
||||
}
|
||||
</td>
|
||||
|
||||
@@ -8,5 +8,6 @@
|
||||
"APIKey": "",
|
||||
"ASN": "",
|
||||
"NOCEmail": "",
|
||||
"AllowedHosts": "*"
|
||||
"AllowedHosts": "*",
|
||||
"NetBoxHost" : ""
|
||||
}
|
||||
|
||||
@@ -25,4 +25,6 @@ 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
|
||||
- ``NetBoxHostname`` - The hostname to communicate to the netbox instance - This always assumes your netbox instance is secured by TLS running on port 443
|
||||
|
||||
Reference in New Issue
Block a user