Compare commits
37 Commits
704d6b24dc
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 5cad97c9ac | |||
| cc61b02959 | |||
| 0dfe68656d | |||
| 6544dc5a3d | |||
| 08e518c340 | |||
| e82d198ee7 | |||
| 4c6a9e6dec | |||
| feb1326cee | |||
| 626ab99888 | |||
| 9c8189bc33 | |||
| 956aa8b3b0 | |||
| 7d5b2a7aac | |||
| 5f089fb01f | |||
| af3cc81180 | |||
| e0189381f1 | |||
| 3a56e2426e | |||
| 0c3edd64f3 | |||
| 2d95fcb1a1 | |||
| 7c952c134a | |||
| 7721dfb669 | |||
| c1ed05a335 | |||
| 690a117ffd | |||
| 9dfbded5b8 | |||
| 7b7d422890 | |||
| 2d6083f530 | |||
| 0e56d778bc | |||
| 8523ddd60f | |||
| 83826cc930 | |||
| cc1717e4a3 | |||
| 48932ec2a5 | |||
| 42aacf497c | |||
| e8152186c1 | |||
| 43b34143a3 | |||
| 8ed021754c | |||
| a44b4f9421 | |||
| 810993cbf3 | |||
| 8d6999c95c |
@@ -1,23 +0,0 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.0" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="8.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="8.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Http" Version="8.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\AS1024.GeoFeed.Core\AS1024.GeoFeed.Core.csproj" />
|
||||
<ProjectReference Include="..\AS1024.GeoFeed.Models\AS1024.GeoFeed.Models.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -1,93 +0,0 @@
|
||||
using AS1024.GeoFeed.Core.Interfaces;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace AS1024.GeoFeed.Core.GeoFeedLocalCache
|
||||
{
|
||||
public class GeoFeedCacheService : IHostedService
|
||||
{
|
||||
private readonly ILogger<GeoFeedCacheService> logger;
|
||||
private readonly IGeoFeedProvider feedProvider;
|
||||
private readonly IHost host;
|
||||
|
||||
public GeoFeedCacheService(ILogger<GeoFeedCacheService> logger,
|
||||
IGeoFeedProvider feedProvider,
|
||||
IHost host)
|
||||
{
|
||||
this.logger = logger;
|
||||
this.feedProvider = feedProvider;
|
||||
this.host = host;
|
||||
}
|
||||
|
||||
public Task StartAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
_ = StartPerioidicSync(cancellationToken);
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public Task StopAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public async Task<bool> StartPerioidicSync(CancellationToken Token)
|
||||
{
|
||||
await DBContextMigrate();
|
||||
|
||||
List<GeoFeedCacheEntry> geoFeedCacheEntry = [];
|
||||
while (!Token.IsCancellationRequested)
|
||||
{
|
||||
logger.LogInformation("Running on disk fallback cache process...");
|
||||
try
|
||||
{
|
||||
using var scope = host.Services.CreateScope();
|
||||
using var dbContext = scope.ServiceProvider.GetRequiredService<GeoFeedCacheDbContext>();
|
||||
var results = await feedProvider.GetGeoFeedData();
|
||||
|
||||
results.ForEach(x =>
|
||||
{
|
||||
geoFeedCacheEntry.Add(new()
|
||||
{
|
||||
Prefix = x.Prefix,
|
||||
GeolocCity = x.GeolocCity,
|
||||
GeolocCountry = x.GeolocCountry,
|
||||
GeolocHasLocation = x.GeolocHasLocation,
|
||||
GeolocPostalCode = x.GeolocPostalCode,
|
||||
GeolocRegion = x.GeolocRegion
|
||||
});
|
||||
});
|
||||
|
||||
if (dbContext.GeoFeedCacheEntries.Any())
|
||||
{
|
||||
dbContext.GeoFeedCacheEntries.RemoveRange(dbContext.GeoFeedCacheEntries.ToArray());
|
||||
}
|
||||
await dbContext.AddRangeAsync(geoFeedCacheEntry, Token);
|
||||
await dbContext.SaveChangesAsync(Token);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogWarning("On disk cache failed to run. Waiting on 30 minutes before retry...");
|
||||
}
|
||||
await Task.Delay(TimeSpan.FromMinutes(30));
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private async Task DBContextMigrate()
|
||||
{
|
||||
using IServiceScope scope = host.Services.CreateScope();
|
||||
using GeoFeedCacheDbContext? dbContext =
|
||||
scope.ServiceProvider.GetService<GeoFeedCacheDbContext>();
|
||||
#pragma warning disable CS8602 // Dereference of a possibly null reference.
|
||||
if (dbContext.Database.GetPendingMigrations().Any()) {
|
||||
await dbContext.Database.MigrateAsync();
|
||||
}
|
||||
#pragma warning restore CS8602 // Dereference of a possibly null reference.
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.0" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="8.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\AS1024.GeoFeed.Core\AS1024.GeoFeed.Core.csproj" />
|
||||
<ProjectReference Include="..\AS1024.GeoFeed.Models\AS1024.GeoFeed.Models.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -1,6 +1,6 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace AS1024.GeoFeed.Core.GeoFeedLocalCache
|
||||
namespace AS1024.GeoFeed.Core.GeoFeedSqliteLocalCache
|
||||
{
|
||||
public class GeoFeedCacheDbContext : DbContext
|
||||
{
|
||||
@@ -1,7 +1,7 @@
|
||||
using AS1024.GeoFeed.Models;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace AS1024.GeoFeed.Core.GeoFeedLocalCache
|
||||
namespace AS1024.GeoFeed.Core.GeoFeedSqliteLocalCache
|
||||
{
|
||||
public class GeoFeedCacheEntry : IPGeoFeed
|
||||
{
|
||||
@@ -1,7 +1,8 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Design;
|
||||
|
||||
namespace AS1024.GeoFeed.Core.GeoFeedLocalCache
|
||||
namespace AS1024.GeoFeed.Core.GeoFeedSqliteLocalCache
|
||||
|
||||
{
|
||||
public class GeoFeedDesignTimeMigration : IDesignTimeDbContextFactory<GeoFeedCacheDbContext>
|
||||
{
|
||||
72
AS1024.GeoFeed.Core.SqliteGeoFeedCache/GeoFeedSqliteCache.cs
Normal file
72
AS1024.GeoFeed.Core.SqliteGeoFeedCache/GeoFeedSqliteCache.cs
Normal file
@@ -0,0 +1,72 @@
|
||||
using AS1024.GeoFeed.Core.Interfaces;
|
||||
using AS1024.GeoFeed.Core.Tools;
|
||||
using AS1024.GeoFeed.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
|
||||
namespace AS1024.GeoFeed.Core.GeoFeedSqliteLocalCache
|
||||
{
|
||||
public class GeoFeedSqliteCache : IGeoFeedPersistentCacheProvider
|
||||
{
|
||||
protected readonly GeoFeedCacheDbContext dbContext;
|
||||
private readonly IGeoFeedProvider feedProvider;
|
||||
|
||||
public GeoFeedSqliteCache(GeoFeedCacheDbContext geoFeedCacheDb,
|
||||
IHost host,
|
||||
IGeoFeedProvider provider)
|
||||
{
|
||||
dbContext = geoFeedCacheDb;
|
||||
feedProvider = provider;
|
||||
}
|
||||
|
||||
public string ProviderName => "sqlite";
|
||||
|
||||
public async Task<bool> CacheGeoFeed(IList<IPGeoFeed> pGeoFeeds)
|
||||
{
|
||||
await DBContextMigrate();
|
||||
List<GeoFeedCacheEntry> geoFeedCacheEntry = [];
|
||||
|
||||
var results = pGeoFeeds.ToList();
|
||||
|
||||
results.ForEach(x =>
|
||||
{
|
||||
geoFeedCacheEntry.Add(new()
|
||||
{
|
||||
Prefix = x.Prefix,
|
||||
GeolocCity = x.GeolocCity,
|
||||
GeolocCountry = x.GeolocCountry,
|
||||
GeolocHasLocation = x.GeolocHasLocation,
|
||||
GeolocPostalCode = x.GeolocPostalCode,
|
||||
GeolocRegion = x.GeolocRegion
|
||||
});
|
||||
});
|
||||
|
||||
if (dbContext.GeoFeedCacheEntries.Any())
|
||||
{
|
||||
dbContext.GeoFeedCacheEntries.RemoveRange(dbContext.GeoFeedCacheEntries.ToArray());
|
||||
}
|
||||
await dbContext.AddRangeAsync(geoFeedCacheEntry);
|
||||
await dbContext.SaveChangesAsync();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public string GetGeoFeed()
|
||||
{
|
||||
var results =
|
||||
dbContext.GeoFeedCacheEntries.ToList();
|
||||
List<IPGeoFeed> cachedData = [];
|
||||
results.ForEach(cachedData.Add);
|
||||
|
||||
return cachedData.ToGeoFeedCsv(true, true);
|
||||
}
|
||||
|
||||
private async Task DBContextMigrate()
|
||||
{
|
||||
if (dbContext.Database.GetPendingMigrations().Any())
|
||||
{
|
||||
await dbContext.Database.MigrateAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using AS1024.GeoFeed.Core.GeoFeedLocalCache;
|
||||
using AS1024.GeoFeed.Core.GeoFeedSqliteLocalCache;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
@@ -8,10 +8,10 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace AS1024.GeoFeed.Core.Migrations
|
||||
namespace AS1024.GeoFeed.Core.SqliteGeoFeedCache.Migrations
|
||||
{
|
||||
[DbContext(typeof(GeoFeedCacheDbContext))]
|
||||
[Migration("20240113204143_InitialMigration")]
|
||||
[Migration("20240114002908_InitialMigration")]
|
||||
partial class InitialMigration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
@@ -20,7 +20,7 @@ namespace AS1024.GeoFeed.Core.Migrations
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder.HasAnnotation("ProductVersion", "8.0.0");
|
||||
|
||||
modelBuilder.Entity("AS1024.GeoFeed.Core.GeoFeedLocalCache.GeoFeedCacheEntry", b =>
|
||||
modelBuilder.Entity("AS1024.GeoFeed.Core.GeoFeedSqliteLocalCache.GeoFeedCacheEntry", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace AS1024.GeoFeed.Core.Migrations
|
||||
namespace AS1024.GeoFeed.Core.SqliteGeoFeedCache.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class InitialMigration : Migration
|
||||
@@ -1,13 +1,13 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using AS1024.GeoFeed.Core.GeoFeedLocalCache;
|
||||
using AS1024.GeoFeed.Core.GeoFeedSqliteLocalCache;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace AS1024.GeoFeed.Core.Migrations
|
||||
namespace AS1024.GeoFeed.Core.SqliteGeoFeedCache.Migrations
|
||||
{
|
||||
[DbContext(typeof(GeoFeedCacheDbContext))]
|
||||
partial class GeoFeedCacheDbContextModelSnapshot : ModelSnapshot
|
||||
@@ -17,7 +17,7 @@ namespace AS1024.GeoFeed.Core.Migrations
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder.HasAnnotation("ProductVersion", "8.0.0");
|
||||
|
||||
modelBuilder.Entity("AS1024.GeoFeed.Core.GeoFeedLocalCache.GeoFeedCacheEntry", b =>
|
||||
modelBuilder.Entity("AS1024.GeoFeed.Core.GeoFeedSqliteLocalCache.GeoFeedCacheEntry", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
@@ -0,0 +1,14 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<OutputType>Library</OutputType>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\AS1024.GeoFeed.Core\AS1024.GeoFeed.Core.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
72
AS1024.GeoFeed.Core.WebLogic/GeoFeedRetrurn.cs
Normal file
72
AS1024.GeoFeed.Core.WebLogic/GeoFeedRetrurn.cs
Normal file
@@ -0,0 +1,72 @@
|
||||
using AS1024.GeoFeed.Core.Interfaces;
|
||||
using AS1024.GeoFeed.Core.Tools;
|
||||
using AS1024.GeoFeed.Models;
|
||||
using Microsoft.Extensions.Caching.Memory;
|
||||
using System.Text;
|
||||
|
||||
namespace AS1024.GeoFeed.Core.WebLogic
|
||||
{
|
||||
public class GeoFeedReturn
|
||||
{
|
||||
private const string GeoFeedCacheKey = "GeoFeedData";
|
||||
private const string GeoFeedMimeTypeReturn = "text/csv";
|
||||
private const string GeoFeedFileName = "geofeed.csv";
|
||||
private readonly IGeoFeedProvider provider;
|
||||
private readonly ILogger<GeoFeedReturn> logger;
|
||||
private readonly IGeoFeedPersistentCacheProvider cacheProvider;
|
||||
private readonly IMemoryCache memoryCache;
|
||||
private readonly IWebHostEnvironment environment;
|
||||
|
||||
public GeoFeedReturn(IGeoFeedProvider provider,
|
||||
ILogger<GeoFeedReturn> logger,
|
||||
IGeoFeedPersistentCacheProvider cacheProvider,
|
||||
IMemoryCache memoryCache,
|
||||
IWebHostEnvironment environment)
|
||||
{
|
||||
this.provider = provider;
|
||||
this.logger = logger;
|
||||
this.cacheProvider = cacheProvider;
|
||||
this.memoryCache = memoryCache;
|
||||
this.environment = environment;
|
||||
}
|
||||
|
||||
public async Task<IResult> GetGeoFeed()
|
||||
{
|
||||
bool isCached = true;
|
||||
try
|
||||
{
|
||||
if (!memoryCache.TryGetValue(GeoFeedCacheKey, out List<IPGeoFeed>? feed))
|
||||
{
|
||||
isCached = false;
|
||||
feed = await provider.GetGeoFeedDataAsync();
|
||||
if (environment.IsProduction())
|
||||
{
|
||||
MemoryCacheEntryOptions cacheEntryOptions = new MemoryCacheEntryOptions()
|
||||
.SetSlidingExpiration(TimeSpan.FromMinutes(15));
|
||||
memoryCache.Set(GeoFeedCacheKey, feed, cacheEntryOptions);
|
||||
}
|
||||
}
|
||||
|
||||
return Results.File(Encoding.UTF8.GetBytes(feed.ToGeoFeedCsv(true, isCached)),
|
||||
GeoFeedMimeTypeReturn,
|
||||
GeoFeedFileName);
|
||||
|
||||
}
|
||||
catch (HttpRequestException ex)
|
||||
{
|
||||
logger.LogWarning($"Temporary failure of retrieving GeoData from upstream. {ex}");
|
||||
string geoFeedData = cacheProvider.GetGeoFeed();
|
||||
|
||||
return Results.File(Encoding.UTF8.GetBytes(geoFeedData),
|
||||
GeoFeedMimeTypeReturn,
|
||||
GeoFeedFileName);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError($"Error: {ex}");
|
||||
}
|
||||
|
||||
return Results.NoContent();
|
||||
}
|
||||
}
|
||||
}
|
||||
12
AS1024.GeoFeed.Core.WebLogic/Properties/launchSettings.json
Normal file
12
AS1024.GeoFeed.Core.WebLogic/Properties/launchSettings.json
Normal file
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"profiles": {
|
||||
"AS1024.GeoFeed.Core.WebLogic": {
|
||||
"commandName": "Project",
|
||||
"launchBrowser": true,
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
},
|
||||
"applicationUrl": "https://localhost:54455;http://localhost:54456"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,9 +4,11 @@
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<OutputType>Library</OutputType>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.Caching.Abstractions" Version="8.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="8.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="8.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Http" Version="8.0.0" />
|
||||
|
||||
58
AS1024.GeoFeed.Core/CacheService/GeoFeedCacheService.cs
Normal file
58
AS1024.GeoFeed.Core/CacheService/GeoFeedCacheService.cs
Normal file
@@ -0,0 +1,58 @@
|
||||
using AS1024.GeoFeed.Core.Interfaces;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace AS1024.GeoFeed.Core.CacheService
|
||||
{
|
||||
public class GeoFeedCacheService : IHostedService
|
||||
{
|
||||
private readonly ILogger<GeoFeedCacheService> logger;
|
||||
private readonly IGeoFeedProvider feedProvider;
|
||||
private readonly IHost host;
|
||||
|
||||
public GeoFeedCacheService(ILogger<GeoFeedCacheService> logger,
|
||||
IGeoFeedProvider feedProvider,
|
||||
IHost host)
|
||||
{
|
||||
this.logger = logger;
|
||||
this.feedProvider = feedProvider;
|
||||
this.host = host;
|
||||
}
|
||||
|
||||
public Task StartAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
_ = StartPerioidicSync(cancellationToken);
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public Task StopAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public async Task<bool> StartPerioidicSync(CancellationToken Token)
|
||||
{
|
||||
while (!Token.IsCancellationRequested)
|
||||
{
|
||||
try
|
||||
{
|
||||
var scope = host.Services.CreateScope();
|
||||
|
||||
var persistentCacheProvider =
|
||||
scope.ServiceProvider.GetRequiredService<IGeoFeedPersistentCacheProvider>();
|
||||
|
||||
var results = await feedProvider.GetGeoFeedDataAsync();
|
||||
await persistentCacheProvider.CacheGeoFeed(results);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
logger.LogWarning("On disk cache failed to run. Waiting on 30 minutes before retry...");
|
||||
}
|
||||
await Task.Delay(TimeSpan.FromMinutes(30));
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
49
AS1024.GeoFeed.Core/CacheService/GeoFeedLocalFileCache.cs
Normal file
49
AS1024.GeoFeed.Core/CacheService/GeoFeedLocalFileCache.cs
Normal file
@@ -0,0 +1,49 @@
|
||||
using AS1024.GeoFeed.Core.Interfaces;
|
||||
using AS1024.GeoFeed.Core.Tools;
|
||||
using AS1024.GeoFeed.Models;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace AS1024.GeoFeed.Core.CacheService
|
||||
{
|
||||
public class GeoFeedLocalFileCache : IGeoFeedPersistentCacheProvider
|
||||
{
|
||||
private readonly IConfiguration configuration;
|
||||
private readonly ILogger<GeoFeedLocalFileCache> logger;
|
||||
|
||||
public GeoFeedLocalFileCache(IConfiguration _configuration,
|
||||
ILogger<GeoFeedLocalFileCache> logger)
|
||||
{
|
||||
configuration = _configuration;
|
||||
this.logger = logger;
|
||||
}
|
||||
|
||||
string IGeoFeedPersistentCacheProvider.ProviderName => "file";
|
||||
|
||||
Task<bool> IGeoFeedPersistentCacheProvider.CacheGeoFeed(IList<IPGeoFeed> pGeoFeeds)
|
||||
{
|
||||
string? tempPath = GetTempPath();
|
||||
logger.LogInformation($"Writing geofeed data to: {tempPath}");
|
||||
File.WriteAllText(tempPath, pGeoFeeds.ToList().
|
||||
ToGeoFeedCsv());
|
||||
|
||||
return Task.FromResult(true);
|
||||
}
|
||||
|
||||
private string GetTempPath()
|
||||
{
|
||||
string? tempPath = Path.Combine(Path.GetTempPath(), "geoFeedCache.csv");
|
||||
|
||||
logger.LogInformation($"Getting GeoFeed data from: {tempPath}");
|
||||
|
||||
if (!string.IsNullOrEmpty(configuration["TempCache"]))
|
||||
tempPath = configuration["TempCache"];
|
||||
return tempPath;
|
||||
}
|
||||
|
||||
string IGeoFeedPersistentCacheProvider.GetGeoFeed()
|
||||
{
|
||||
return File.ReadAllText(GetTempPath());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using AS1024.GeoFeed.Core.Interfaces;
|
||||
using AS1024.GeoFeed.Models;
|
||||
using Microsoft.Extensions.Caching.Memory;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Logging;
|
||||
@@ -40,7 +41,7 @@ namespace AS1024.GeoFeed.Core.GeoFeedPreloader
|
||||
private async Task StartPreLoad()
|
||||
{
|
||||
logger.LogInformation("Preloading GeoFeed data in memory...");
|
||||
List<Models.IPGeoFeed> feed = await provider.GetGeoFeedData();
|
||||
List<IPGeoFeed> feed = await provider.GetGeoFeedDataAsync();
|
||||
MemoryCacheEntryOptions cacheEntryOptions = new MemoryCacheEntryOptions().SetAbsoluteExpiration(TimeSpan.FromMinutes(45));
|
||||
memoryCache.Set(GeoFeedCacheKey, feed, cacheEntryOptions);
|
||||
}
|
||||
@@ -1,129 +1,14 @@
|
||||
using AS1024.GeoFeed.Core.Interfaces;
|
||||
using AS1024.GeoFeed.Models;
|
||||
using System.Text.Json;
|
||||
using System.Net.Http.Headers;
|
||||
using System.Net.Sockets;
|
||||
using System.Web;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace AS1024.GeoFeed.Core.GeoFeedProviders
|
||||
{
|
||||
public class NetBoxGeoFeedProvider : IGeoFeedProvider
|
||||
public class NetBoxGeoFeedProvider : NetBoxGeoFeedProviderBase, IGeoFeedProvider
|
||||
{
|
||||
private readonly IConfiguration configuration;
|
||||
private readonly ILogger<NetBoxGeoFeedProvider> logger;
|
||||
private readonly IList<AddressFamily> addressFamilies = new List<AddressFamily>()
|
||||
public NetBoxGeoFeedProvider(IConfiguration configuration, ILogger<NetBoxGeoFeedProvider> logger, IHttpClientFactory httpClientFactory)
|
||||
: base(configuration, logger, httpClientFactory)
|
||||
{
|
||||
AddressFamily.InterNetwork,
|
||||
AddressFamily.InterNetworkV6
|
||||
};
|
||||
private readonly IHttpClientFactory httpClientFactory;
|
||||
|
||||
string IGeoFeedProvider.GeoFeedProviderName => "netbox";
|
||||
|
||||
public NetBoxGeoFeedProvider(IConfiguration configuration,
|
||||
ILogger<NetBoxGeoFeedProvider> logger,
|
||||
IHttpClientFactory httpClientFactory)
|
||||
{
|
||||
this.configuration = configuration;
|
||||
this.logger = logger;
|
||||
this.httpClientFactory = httpClientFactory;
|
||||
}
|
||||
|
||||
public async Task<List<IPGeoFeed>> GetGeoFeedData()
|
||||
{
|
||||
List<IPGeoFeed> geoFeed = [];
|
||||
using HttpClient client = httpClientFactory.CreateClient();
|
||||
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Token", configuration["APIKey"]);
|
||||
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
|
||||
|
||||
foreach (AddressFamily family in addressFamilies)
|
||||
{
|
||||
Uri uri = BuildNetBoxURI(family);
|
||||
NetboxData? jsonData = null;
|
||||
|
||||
while (true)
|
||||
{
|
||||
logger.LogDebug($"Making request to {uri}...");
|
||||
|
||||
using HttpResponseMessage result = await client.GetAsync(uri);
|
||||
if (!result.IsSuccessStatusCode)
|
||||
{
|
||||
break;
|
||||
}
|
||||
string stringResult = await result.Content.ReadAsStringAsync();
|
||||
jsonData = JsonSerializer.Deserialize<NetboxData>(stringResult, new JsonSerializerOptions
|
||||
{
|
||||
PropertyNamingPolicy = JsonNamingPolicy.SnakeCaseLower
|
||||
});
|
||||
|
||||
if (jsonData?.Results == null || jsonData.Results.Count == 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
foreach (Result data in jsonData.Results)
|
||||
{
|
||||
try
|
||||
{
|
||||
geoFeed.Add(new IPGeoFeed
|
||||
{
|
||||
Prefix = data.Prefix,
|
||||
GeolocCity = data.CustomFields.GeolocCity,
|
||||
GeolocRegion = data.CustomFields.GeolocRegion,
|
||||
GeolocCountry = data.CustomFields.GeolocCountry,
|
||||
GeolocHasLocation = data.CustomFields.GeolocHasLocation,
|
||||
GeolocPostalCode = data.CustomFields.GeolocPostalCode
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(jsonData.Next))
|
||||
{
|
||||
uri = new Uri(jsonData.Next);
|
||||
continue;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return geoFeed;
|
||||
}
|
||||
|
||||
protected Uri BuildNetBoxURI(AddressFamily family)
|
||||
{
|
||||
System.Collections.Specialized.NameValueCollection queryParameters = HttpUtility.ParseQueryString(string.Empty);
|
||||
queryParameters["cf_geoloc_has_location"] = "true";
|
||||
queryParameters["limit"] = "50";
|
||||
|
||||
switch (family)
|
||||
{
|
||||
case AddressFamily.InterNetwork:
|
||||
queryParameters["mask_length__lte"] = "24";
|
||||
queryParameters["family"] = "4";
|
||||
break;
|
||||
|
||||
case AddressFamily.InterNetworkV6:
|
||||
queryParameters["mask_length__lte"] = "48";
|
||||
queryParameters["family"] = "6";
|
||||
break;
|
||||
}
|
||||
|
||||
UriBuilder endUrl = new UriBuilder
|
||||
{
|
||||
Path = "api/ipam/prefixes/",
|
||||
Query = queryParameters.ToString(),
|
||||
Host = configuration["NetBoxHost"],
|
||||
Scheme = "https"
|
||||
};
|
||||
|
||||
return endUrl.Uri;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,134 @@
|
||||
using AS1024.GeoFeed.Core.Interfaces;
|
||||
using AS1024.GeoFeed.Models;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System.Net.Http.Headers;
|
||||
using System.Net.Sockets;
|
||||
using System.Text.Json;
|
||||
using System.Web;
|
||||
|
||||
namespace AS1024.GeoFeed.Core.GeoFeedProviders
|
||||
{
|
||||
public abstract class NetBoxGeoFeedProviderBase : IGeoFeedProvider
|
||||
{
|
||||
protected readonly IConfiguration configuration;
|
||||
protected readonly ILogger<NetBoxGeoFeedProvider> logger;
|
||||
protected readonly IList<AddressFamily> addressFamilies = new List<AddressFamily>()
|
||||
{
|
||||
AddressFamily.InterNetwork,
|
||||
AddressFamily.InterNetworkV6
|
||||
};
|
||||
protected readonly IHttpClientFactory httpClientFactory;
|
||||
|
||||
string IGeoFeedProvider.GeoFeedProviderName => "netbox";
|
||||
|
||||
public NetBoxGeoFeedProviderBase(IConfiguration configuration,
|
||||
ILogger<NetBoxGeoFeedProvider> logger,
|
||||
IHttpClientFactory httpClientFactory)
|
||||
{
|
||||
this.configuration = configuration;
|
||||
this.logger = logger;
|
||||
this.httpClientFactory = httpClientFactory;
|
||||
}
|
||||
|
||||
public async Task<List<IPGeoFeed>> GetGeoFeedDataAsync()
|
||||
{
|
||||
List<IPGeoFeed> geoFeed = [];
|
||||
using HttpClient client = httpClientFactory.CreateClient();
|
||||
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Token", configuration["APIKey"]);
|
||||
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
|
||||
|
||||
foreach (AddressFamily family in addressFamilies)
|
||||
{
|
||||
Uri uri = BuildNetBoxURI(family);
|
||||
NetboxData? jsonData = null;
|
||||
|
||||
while (true)
|
||||
{
|
||||
logger.LogDebug($"Making request to {uri}...");
|
||||
|
||||
using HttpResponseMessage result = await client.GetAsync(uri);
|
||||
if (!result.IsSuccessStatusCode)
|
||||
{
|
||||
break;
|
||||
}
|
||||
var stringResult = await result.Content.ReadAsStreamAsync();
|
||||
jsonData = DeserializeJsonData(stringResult);
|
||||
|
||||
if (jsonData?.Results == null || jsonData.Results.Count == 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
foreach (Result data in jsonData.Results)
|
||||
{
|
||||
try
|
||||
{
|
||||
geoFeed.Add(new IPGeoFeed
|
||||
{
|
||||
Prefix = data.Prefix,
|
||||
GeolocCity = data.CustomFields.GeolocCity,
|
||||
GeolocRegion = data.CustomFields.GeolocRegion,
|
||||
GeolocCountry = data.CustomFields.GeolocCountry,
|
||||
GeolocHasLocation = data.CustomFields.GeolocHasLocation,
|
||||
GeolocPostalCode = data.CustomFields.GeolocPostalCode
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(jsonData.Next))
|
||||
{
|
||||
uri = new Uri(jsonData.Next);
|
||||
continue;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return geoFeed;
|
||||
}
|
||||
|
||||
protected virtual NetboxData? DeserializeJsonData(Stream stringResult)
|
||||
{
|
||||
return JsonSerializer.Deserialize<NetboxData>(stringResult, new JsonSerializerOptions
|
||||
{
|
||||
PropertyNamingPolicy = JsonNamingPolicy.SnakeCaseLower
|
||||
});
|
||||
}
|
||||
|
||||
protected Uri BuildNetBoxURI(AddressFamily family)
|
||||
{
|
||||
System.Collections.Specialized.NameValueCollection queryParameters = HttpUtility.ParseQueryString(string.Empty);
|
||||
queryParameters["cf_geoloc_has_location"] = "true";
|
||||
queryParameters["limit"] = "50";
|
||||
|
||||
switch (family)
|
||||
{
|
||||
case AddressFamily.InterNetwork:
|
||||
queryParameters["mask_length__lte"] = "24";
|
||||
queryParameters["family"] = "4";
|
||||
break;
|
||||
|
||||
case AddressFamily.InterNetworkV6:
|
||||
queryParameters["mask_length__lte"] = "48";
|
||||
queryParameters["family"] = "6";
|
||||
break;
|
||||
}
|
||||
|
||||
UriBuilder endUrl = new UriBuilder
|
||||
{
|
||||
Path = "api/ipam/prefixes/",
|
||||
Query = queryParameters.ToString(),
|
||||
Host = configuration["NetBoxHost"],
|
||||
Scheme = "https"
|
||||
};
|
||||
|
||||
return endUrl.Uri;
|
||||
}
|
||||
}
|
||||
}
|
||||
26
AS1024.GeoFeed.Core/Interfaces/IGeoFeedCacheProvider.cs
Normal file
26
AS1024.GeoFeed.Core/Interfaces/IGeoFeedCacheProvider.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
using AS1024.GeoFeed.Models;
|
||||
|
||||
namespace AS1024.GeoFeed.Core.Interfaces
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a persistent cache GeoFeed provider
|
||||
/// </summary>
|
||||
public interface IGeoFeedPersistentCacheProvider
|
||||
{
|
||||
/// <summary>
|
||||
/// Name of the provider
|
||||
/// </summary>
|
||||
public string ProviderName { get; }
|
||||
/// <summary>
|
||||
/// Returns the GeoFeed
|
||||
/// </summary>
|
||||
/// <returns>String of the CSV geofeed</returns>
|
||||
public string GetGeoFeed();
|
||||
/// <summary>
|
||||
/// Stores the GeoFeed in the cache backend
|
||||
/// </summary>
|
||||
/// <param name="pGeoFeeds">GeoFeed retrieved from the backend</param>
|
||||
/// <returns></returns>
|
||||
public Task<bool> CacheGeoFeed(IList<IPGeoFeed> pGeoFeeds);
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,6 @@ namespace AS1024.GeoFeed.Core.Interfaces
|
||||
public interface IGeoFeedProvider
|
||||
{
|
||||
public string GeoFeedProviderName { get; }
|
||||
public Task<List<IPGeoFeed>> GetGeoFeedData();
|
||||
public Task<List<IPGeoFeed>> GetGeoFeedDataAsync();
|
||||
}
|
||||
}
|
||||
@@ -5,16 +5,35 @@ namespace AS1024.GeoFeed.Core.Tools
|
||||
{
|
||||
public static class GeoFeedTools
|
||||
{
|
||||
public static string ToGeoFeedCsv(this List<IPGeoFeed> geoFeeds)
|
||||
/// <summary>
|
||||
/// Returns a CSV string for a given GeoFeed retrieved from various sources.
|
||||
/// </summary>
|
||||
/// <param name="geoFeeds">GeoFeed returned from the source of truth.</param>
|
||||
/// <param name="timeStamp">If a timestamp should be appended at the header.</param>
|
||||
/// <param name="isCached">If the result is cached.</param>
|
||||
/// <returns>CSV formatted string of GeoFeed data.</returns>
|
||||
public static string ToGeoFeedCsv(this List<IPGeoFeed> geoFeeds, bool timeStamp = false, bool isCached = false)
|
||||
{
|
||||
if (geoFeeds == null) throw new ArgumentNullException(nameof(geoFeeds));
|
||||
|
||||
StringBuilder csvContent = new();
|
||||
|
||||
// Append timestamp header if required
|
||||
if (timeStamp)
|
||||
csvContent.AppendFormat("# GeoFeed generated on {0:R}\n", DateTime.UtcNow);
|
||||
|
||||
// Append cache status if required
|
||||
if (isCached)
|
||||
csvContent.AppendLine("# Geofeed data is returned from local in memory cache");
|
||||
|
||||
// Iterate over each GeoFeed entry to append its details to the CSV content
|
||||
foreach (IPGeoFeed feed in geoFeeds)
|
||||
{
|
||||
csvContent.AppendLine($"{feed.Prefix},{feed.GeolocCountry},{feed.GeolocRegion},{feed.GeolocCity},{feed.GeolocPostalCode}");
|
||||
// Using AppendFormat for a cleaner and more readable approach to constructing CSV lines
|
||||
csvContent.AppendFormat("{0},{1},{2},{3},{4}\n", feed.Prefix, feed.GeolocCountry, feed.GeolocRegion, feed.GeolocCity, feed.GeolocPostalCode);
|
||||
}
|
||||
|
||||
return csvContent.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,4 +13,9 @@
|
||||
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.19.5" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\AS1024.GeoFeed.Core.WebLogic\AS1024.GeoFeed.Core.WebLogic.csproj" />
|
||||
<ProjectReference Include="..\AS1024.GeoFeed.Core\AS1024.GeoFeed.Core.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
15
AS1024.GeoFeed.MinimalAPI/AppJsonSerializerContext.cs
Normal file
15
AS1024.GeoFeed.MinimalAPI/AppJsonSerializerContext.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
using AS1024.GeoFeed.Models;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace AS1024.GeoFeed.MinimalAPI
|
||||
{
|
||||
[JsonSerializable(typeof(NetboxData))]
|
||||
[JsonSerializable(typeof(Result))]
|
||||
[JsonSerializable(typeof(CustomFields))]
|
||||
[JsonSourceGenerationOptions(PropertyNamingPolicy = JsonKnownNamingPolicy.SnakeCaseLower)]
|
||||
internal partial class AppJsonSerializerContext : JsonSerializerContext
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,11 +1,11 @@
|
||||
#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
|
||||
FROM mcr.microsoft.com/dotnet/runtime:8.0-jammy-chiseled AS base
|
||||
USER app
|
||||
WORKDIR /app
|
||||
EXPOSE 8080
|
||||
|
||||
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
|
||||
FROM mcr.microsoft.com/dotnet/sdk:8.0-jammy AS build
|
||||
# Install clang/zlib1g-dev dependencies for publishing to native
|
||||
RUN apt-get update \
|
||||
&& apt-get install -y --no-install-recommends \
|
||||
@@ -20,9 +20,9 @@ RUN dotnet build "./AS1024.GeoFeed.MinimalAPI.csproj" -c $BUILD_CONFIGURATION -o
|
||||
|
||||
FROM build AS publish
|
||||
ARG BUILD_CONFIGURATION=Release
|
||||
RUN dotnet publish "./AS1024.GeoFeed.MinimalAPI.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=true
|
||||
RUN dotnet publish "./AS1024.GeoFeed.MinimalAPI.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=true /p:DebugType=None /p:DebugSymbols=false
|
||||
|
||||
FROM mcr.microsoft.com/dotnet/runtime-deps:8.0 AS final
|
||||
FROM base AS final
|
||||
WORKDIR /app
|
||||
EXPOSE 8080
|
||||
COPY --from=publish /app/publish .
|
||||
|
||||
55
AS1024.GeoFeed.MinimalAPI/Dockerfile.alpine-selfcontained
Normal file
55
AS1024.GeoFeed.MinimalAPI/Dockerfile.alpine-selfcontained
Normal file
@@ -0,0 +1,55 @@
|
||||
#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 alpine:latest AS base
|
||||
ENV \
|
||||
# UID of the non-root user 'app'
|
||||
APP_UID=1654 \
|
||||
# Configure web servers to bind to port 8080 when present
|
||||
ASPNETCORE_HTTP_PORTS=8080 \
|
||||
# Enable detection of running in a container
|
||||
DOTNET_RUNNING_IN_CONTAINER=true \
|
||||
# Set the invariant mode since ICU package isn't included (see https://github.com/dotnet/announcements/issues/20)
|
||||
DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=true
|
||||
|
||||
#RUN apk add --upgrade --no-cache \
|
||||
# ca-certificates-bundle \
|
||||
# \
|
||||
# # .NET dependencies
|
||||
# libgcc \
|
||||
# libssl3 \
|
||||
# libstdc++ \
|
||||
# zlib
|
||||
|
||||
# Create a non-root user and group
|
||||
RUN addgroup \
|
||||
--gid=$APP_UID \
|
||||
app \
|
||||
&& adduser \
|
||||
--uid=$APP_UID \
|
||||
--ingroup=app \
|
||||
--disabled-password \
|
||||
app
|
||||
WORKDIR /app
|
||||
USER app
|
||||
EXPOSE 8080
|
||||
|
||||
FROM mcr.microsoft.com/dotnet/sdk:8.0-alpine AS build
|
||||
# Install clang/zlib1g-dev dependencies for publishing to native
|
||||
RUN apk add clang zlib-dev musl-dev libc6-compat
|
||||
ARG BUILD_CONFIGURATION=Release
|
||||
WORKDIR /src
|
||||
COPY ["AS1024.GeoFeed.MinimalAPI/AS1024.GeoFeed.MinimalAPI.csproj", "AS1024.GeoFeed.MinimalAPI/"]
|
||||
RUN dotnet restore "./AS1024.GeoFeed.MinimalAPI/./AS1024.GeoFeed.MinimalAPI.csproj"
|
||||
COPY . .
|
||||
WORKDIR "/src/AS1024.GeoFeed.MinimalAPI"
|
||||
RUN dotnet build "./AS1024.GeoFeed.MinimalAPI.csproj" -c $BUILD_CONFIGURATION -o /app/build
|
||||
|
||||
FROM build AS publish
|
||||
ARG BUILD_CONFIGURATION=Release
|
||||
RUN dotnet publish "./AS1024.GeoFeed.MinimalAPI.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=true /p:DebugType=None /p:DebugSymbols=false
|
||||
|
||||
FROM base AS final
|
||||
WORKDIR /app
|
||||
EXPOSE 8080
|
||||
COPY --from=publish /app/publish .
|
||||
ENTRYPOINT ["./AS1024.GeoFeed.MinimalAPI"]
|
||||
24
AS1024.GeoFeed.MinimalAPI/Dockerfile.bare-image
Normal file
24
AS1024.GeoFeed.MinimalAPI/Dockerfile.bare-image
Normal file
@@ -0,0 +1,24 @@
|
||||
#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/sdk:8.0-alpine AS build
|
||||
# Install clang/zlib1g-dev dependencies for publishing to native
|
||||
RUN apk add clang zlib-static zlib-dev musl-dev libc6-compat cmake autoconf make openssl-dev openssl-libs-static icu-static icu-dev
|
||||
ARG BUILD_CONFIGURATION=Release
|
||||
WORKDIR /src
|
||||
COPY ["AS1024.GeoFeed.MinimalAPI/AS1024.GeoFeed.MinimalAPI.csproj", "AS1024.GeoFeed.MinimalAPI/"]
|
||||
RUN dotnet restore "./AS1024.GeoFeed.MinimalAPI/./AS1024.GeoFeed.MinimalAPI.csproj"
|
||||
COPY . .
|
||||
WORKDIR "/src/AS1024.GeoFeed.MinimalAPI"
|
||||
RUN dotnet build "./AS1024.GeoFeed.MinimalAPI.csproj" -c $BUILD_CONFIGURATION -o /app/build
|
||||
|
||||
FROM build AS publish
|
||||
ARG BUILD_CONFIGURATION=Release
|
||||
RUN dotnet publish "./AS1024.GeoFeed.MinimalAPI.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:StaticOpenSslLinking=true /p:StaticExecutable=true /p:StaticallyLinked=true /p:StripSymbols=true /p:DebugType=None /p:DebugSymbols=false
|
||||
|
||||
FROM scratch AS final
|
||||
WORKDIR /tmp
|
||||
WORKDIR /app
|
||||
EXPOSE 8080
|
||||
COPY --from=publish /app/publish .
|
||||
COPY --from=build /etc/ssl/certs/* /etc/ssl/certs/
|
||||
ENTRYPOINT ["./AS1024.GeoFeed.MinimalAPI"]
|
||||
22
AS1024.GeoFeed.MinimalAPI/GeoFeedAoTProvider.cs
Normal file
22
AS1024.GeoFeed.MinimalAPI/GeoFeedAoTProvider.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
using AS1024.GeoFeed.Core.GeoFeedProviders;
|
||||
using AS1024.GeoFeed.Core.Interfaces;
|
||||
using AS1024.GeoFeed.Models;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace AS1024.GeoFeed.MinimalAPI
|
||||
{
|
||||
internal class NetboxAoTGeoFeedProvider : NetBoxGeoFeedProvider, IGeoFeedProvider
|
||||
{
|
||||
public NetboxAoTGeoFeedProvider(IConfiguration configuration,
|
||||
ILogger<NetBoxGeoFeedProvider> logger,
|
||||
IHttpClientFactory httpClientFactory)
|
||||
: base(configuration, logger, httpClientFactory)
|
||||
{
|
||||
}
|
||||
|
||||
protected override NetboxData? DeserializeJsonData(Stream stringResult)
|
||||
{
|
||||
return JsonSerializer.Deserialize(stringResult, AppJsonSerializerContext.Default.NetboxData);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,18 +1,41 @@
|
||||
using System.Text.Json.Serialization;
|
||||
using AS1024.GeoFeed.Core.CacheService;
|
||||
using AS1024.GeoFeed.Core.GeoFeedPreloader;
|
||||
using AS1024.GeoFeed.Core.Interfaces;
|
||||
using AS1024.GeoFeed.Core.WebLogic;
|
||||
|
||||
namespace AS1024.GeoFeed.MinimalAPI
|
||||
{
|
||||
public class Program
|
||||
{
|
||||
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
var builder = WebApplication.CreateSlimBuilder(args);
|
||||
|
||||
builder.Services.AddTransient<IGeoFeedProvider, NetboxAoTGeoFeedProvider>();
|
||||
builder.Services.AddHostedService<GeoFeedCacheService>();
|
||||
builder.Services.AddHostedService<PreLoadGeoFeed>();
|
||||
builder.Services.AddTransient<IGeoFeedPersistentCacheProvider, GeoFeedLocalFileCache>();
|
||||
builder.Services.AddScoped<GeoFeedReturn>();
|
||||
builder.Services.AddMemoryCache();
|
||||
builder.Services.AddLogging();
|
||||
builder.Services.AddHttpClient();
|
||||
builder.Services.ConfigureHttpJsonOptions(options =>
|
||||
{
|
||||
options.SerializerOptions.TypeInfoResolverChain.Insert(0, AppJsonSerializerContext.Default);
|
||||
});
|
||||
var app = builder.Build();
|
||||
var geoFeed = app.MapGroup("/geofeed.csv");
|
||||
|
||||
app.Map("/geofeed.csv", async (GeoFeedReturn feedReturn) =>
|
||||
{
|
||||
return await feedReturn.GetGeoFeed();
|
||||
});
|
||||
|
||||
app.Map("/geofeed", async (GeoFeedReturn feedReturn) =>
|
||||
{
|
||||
return await feedReturn.GetGeoFeed();
|
||||
});
|
||||
|
||||
app.Run();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
"http": {
|
||||
"commandName": "Project",
|
||||
"launchBrowser": true,
|
||||
"launchUrl": "todos",
|
||||
"launchUrl": "geofeed.csv",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
},
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
using System.Text.Json.Serialization;
|
||||
namespace AS1024.GeoFeed.Models
|
||||
namespace AS1024.GeoFeed.Models
|
||||
{
|
||||
public class NetboxData
|
||||
{
|
||||
public List<Result>? Results { get; set; }
|
||||
public string? Next { get; set; }
|
||||
public string? Previous { get; set; }
|
||||
public string? Previous { get; set; }
|
||||
}
|
||||
|
||||
public class Result
|
||||
@@ -41,7 +40,8 @@ namespace AS1024.GeoFeed.Models
|
||||
/// <summary>
|
||||
/// This class represents the IP GeoFeed Entry
|
||||
/// </summary>
|
||||
public class IPGeoFeed : CustomFields {
|
||||
public class IPGeoFeed : CustomFields
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents the IP Prefix for the associated GeoFeed entry
|
||||
/// </summary>
|
||||
|
||||
@@ -14,7 +14,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AS1024.GeoFeed.Core", "AS10
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AS1024.GeoFeed.MinimalAPI", "AS1024.GeoFeed.MinimalAPI\AS1024.GeoFeed.MinimalAPI.csproj", "{36F2958C-8D0E-463B-9BF3-D6E55E6FC0B8}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AS1024.GeoFeed.Core.GeoFeedLocalCache", "AS1024.GeoFeed.Core.GeoFeedLocalCache\AS1024.GeoFeed.Core.GeoFeedLocalCache.csproj", "{C474F55D-AE8E-4DF3-A241-FB017551C74A}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AS1024.GeoFeed.Core.SqliteGeoFeedCache", "AS1024.GeoFeed.Core.SqliteGeoFeedCache\AS1024.GeoFeed.Core.SqliteGeoFeedCache.csproj", "{3459BB31-FA7A-44D1-872D-C5338ACFBF80}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AS1024.GeoFeed.Core.WebLogic", "AS1024.GeoFeed.Core.WebLogic\AS1024.GeoFeed.Core.WebLogic.csproj", "{58BDCE89-FCC0-478F-BBDE-B89833712AAB}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
@@ -38,10 +40,14 @@ Global
|
||||
{36F2958C-8D0E-463B-9BF3-D6E55E6FC0B8}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{36F2958C-8D0E-463B-9BF3-D6E55E6FC0B8}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{36F2958C-8D0E-463B-9BF3-D6E55E6FC0B8}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{C474F55D-AE8E-4DF3-A241-FB017551C74A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{C474F55D-AE8E-4DF3-A241-FB017551C74A}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{C474F55D-AE8E-4DF3-A241-FB017551C74A}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{C474F55D-AE8E-4DF3-A241-FB017551C74A}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{3459BB31-FA7A-44D1-872D-C5338ACFBF80}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{3459BB31-FA7A-44D1-872D-C5338ACFBF80}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{3459BB31-FA7A-44D1-872D-C5338ACFBF80}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{3459BB31-FA7A-44D1-872D-C5338ACFBF80}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{58BDCE89-FCC0-478F-BBDE-B89833712AAB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{58BDCE89-FCC0-478F-BBDE-B89833712AAB}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{58BDCE89-FCC0-478F-BBDE-B89833712AAB}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{58BDCE89-FCC0-478F-BBDE-B89833712AAB}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
||||
@@ -22,7 +22,8 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\AS1024.GeoFeed.Core.GeoFeedLocalCache\AS1024.GeoFeed.Core.GeoFeedLocalCache.csproj" />
|
||||
<ProjectReference Include="..\AS1024.GeoFeed.Core.SqliteGeoFeedCache\AS1024.GeoFeed.Core.SqliteGeoFeedCache.csproj" />
|
||||
<ProjectReference Include="..\AS1024.GeoFeed.Core.WebLogic\AS1024.GeoFeed.Core.WebLogic.csproj" />
|
||||
<ProjectReference Include="..\AS1024.GeoFeed.Core\AS1024.GeoFeed.Core.csproj" />
|
||||
<ProjectReference Include="..\AS1024.GeoFeed.Models\AS1024.GeoFeed.Models.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
@@ -1,10 +1,5 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using AS1024.GeoFeed.Core.Interfaces;
|
||||
using Microsoft.Extensions.Caching.Memory;
|
||||
using AS1024.GeoFeed.Models;
|
||||
using System.Text;
|
||||
using AS1024.GeoFeed.Core.GeoFeedLocalCache;
|
||||
using AS1024.GeoFeed.Core.Tools;
|
||||
using AS1024.GeoFeed.Core.WebLogic;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace AS1024.GeoFeed.Controllers
|
||||
{
|
||||
@@ -14,72 +9,18 @@ namespace AS1024.GeoFeed.Controllers
|
||||
|
||||
public class GeofeedController : ControllerBase
|
||||
{
|
||||
private readonly IGeoFeedProvider builder;
|
||||
private readonly IMemoryCache memoryCache;
|
||||
private readonly IWebHostEnvironment environment;
|
||||
private readonly ILogger<GeofeedController> logger;
|
||||
private readonly GeoFeedCacheDbContext dbContext;
|
||||
private const string GeoFeedCacheKey = "GeoFeedData";
|
||||
private readonly GeoFeedReturn feedReturn;
|
||||
|
||||
public GeofeedController(IGeoFeedProvider builder,
|
||||
IMemoryCache memoryCache,
|
||||
IWebHostEnvironment environment,
|
||||
ILogger<GeofeedController> logger,
|
||||
GeoFeedCacheDbContext dbContext) {
|
||||
this.logger = logger;
|
||||
this.dbContext = dbContext;
|
||||
this.builder = builder;
|
||||
this.memoryCache = memoryCache;
|
||||
this.environment = environment;
|
||||
public GeofeedController(GeoFeedReturn feedReturn)
|
||||
{
|
||||
this.feedReturn = feedReturn;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[Route("")]
|
||||
public async Task<IActionResult> Get()
|
||||
public async Task<IResult> Get()
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!memoryCache.TryGetValue(GeoFeedCacheKey, out List<IPGeoFeed>? feed))
|
||||
{
|
||||
feed = await builder.GetGeoFeedData();
|
||||
if (environment.IsProduction())
|
||||
{
|
||||
MemoryCacheEntryOptions cacheEntryOptions = new MemoryCacheEntryOptions()
|
||||
.SetSlidingExpiration(TimeSpan.FromMinutes(15));
|
||||
memoryCache.Set(GeoFeedCacheKey, feed, cacheEntryOptions);
|
||||
}
|
||||
}
|
||||
|
||||
return ReturnFile(feed);
|
||||
} catch (HttpRequestException ex)
|
||||
{
|
||||
logger.LogWarning($"Temporary failure of retrieving GeoData from upstream. {ex}");
|
||||
var results =
|
||||
dbContext.GeoFeedCacheEntries.ToList();
|
||||
List<IPGeoFeed> cachedData = [];
|
||||
results.ForEach(cachedData.Add);
|
||||
return ReturnFile(cachedData);
|
||||
}
|
||||
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError($"Geofeed generation failed. Exception: {ex}");
|
||||
return StatusCode(500);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
[NonAction]
|
||||
private IActionResult ReturnFile(List<IPGeoFeed>? feed)
|
||||
{
|
||||
string csvContent = feed.ToGeoFeedCsv(); // Assuming ToGeoFeedCsv() returns a string in CSV format.
|
||||
byte[] contentBytes = Encoding.UTF8.GetBytes(csvContent);
|
||||
string contentType = "text/csv";
|
||||
|
||||
return new FileContentResult(contentBytes, contentType)
|
||||
{
|
||||
FileDownloadName = "geofeed.csv"
|
||||
};
|
||||
return await feedReturn.GetGeoFeed();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
using AS1024.GeoFeed.Core.Interfaces;
|
||||
using AS1024.GeoFeed.Core.CacheService;
|
||||
using AS1024.GeoFeed.Core.GeoFeedPreloader;
|
||||
using AS1024.GeoFeed.Core.GeoFeedLocalCache;
|
||||
using AS1024.GeoFeed.Core.GeoFeedProviders;
|
||||
using AS1024.GeoFeed.Core.GeoFeedSqliteLocalCache;
|
||||
using AS1024.GeoFeed.Core.Interfaces;
|
||||
using AS1024.GeoFeed.Core.WebLogic;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace AS1024.GeoFeed
|
||||
@@ -14,11 +16,14 @@ namespace AS1024.GeoFeed
|
||||
|
||||
builder.Services.AddHostedService<PreLoadGeoFeed>();
|
||||
builder.Services.AddTransient<IGeoFeedProvider, NetBoxGeoFeedProvider>();
|
||||
builder.Services.AddScoped<GeoFeedReturn>();
|
||||
builder.Services.AddDbContext<GeoFeedCacheDbContext>(
|
||||
options =>
|
||||
{
|
||||
options.UseSqlite(builder.Configuration.GetConnectionString("LocalFeedCache"));
|
||||
});
|
||||
builder.Services.AddScoped<IGeoFeedPersistentCacheProvider, GeoFeedSqliteCache>();
|
||||
builder.Services.AddHostedService<GeoFeedCacheService>();
|
||||
builder.Services.AddDbContext<GeoFeedCacheDbContext>(options =>
|
||||
{
|
||||
options.UseSqlite(builder.Configuration.GetConnectionString("LocalFeedCache"));
|
||||
});
|
||||
builder.Services.AddHttpClient();
|
||||
builder.Services.AddMemoryCache();
|
||||
// Add services to the container.
|
||||
|
||||
68
README.md
68
README.md
@@ -4,25 +4,46 @@
|
||||
|
||||
This web application provides a self-published IP geolocation feed, conforming to the standards set out in [RFC 8805](https://www.rfc-editor.org/rfc/rfc8805). It is designed to interface with NetBox, a web-based infrastructure resource modeling (IRM) tool, to retrieve and format geolocation data for IP addresses.
|
||||
|
||||
The application is implemented in C# using .NET 8.0, ensuring a robust and modern back-end architecture. It's built to communicate securely over HTTPS with the NetBox API, adhering to best practices for data transmission and security.
|
||||
The application is implemented in C# using .NET 8.0, ensuring a robust and modern back-end architecture. It's built to communicate securely over HTTPS with the NetBox API, adhering to best practices for data transmission and security.
|
||||
|
||||
This project was inspired by the GitHub project [GeoBox](https://github.com/FrumentumNL/GeoBox), which provided foundational ideas for the development of this application.
|
||||
|
||||
## Application Variants
|
||||
|
||||
### AS1024.GeoFeed - MVC Version (Recommended)
|
||||
|
||||
The standard version of this application, named `AS1024.GeoFeed`, is built using the Model-View-Controller (MVC) architecture. This variant is fully supported and recommended for most use cases. It offers a complete set of features and is optimized for robustness and scalability.
|
||||
|
||||
### AS1024.GeoFeed.MinimalAPI - MinimalAPI Version (Experimental)
|
||||
|
||||
In addition to the standard MVC version, there is an experimental MinimalAPI version of the application named `AS1024.GeoFeed.MinimalAPI`. This variant is designed for environments that require extremely fast startup times, such as serverless containers. However, it comes with limited support and a reduced feature set. We recommend using the `AS1024.GeoFeed.MinimalAPI` version only if your deployment environment necessitates near-instant startup times and you are comfortable with its experimental nature and limitations.
|
||||
|
||||
**Note**: While the `AS1024.GeoFeed.MinimalAPI` version offers performance benefits in specific scenarios, we strongly recommend deploying the `AS1024.GeoFeed` MVC version for most applications to ensure full functionality and support.
|
||||
|
||||
## Features
|
||||
|
||||
- **GeoFeed Generation**: Dynamically generates a geolocation feed in CSV format as specified in RFC 8805.
|
||||
- **Caching Mechanism**: Implements an efficient caching strategy to reduce redundant API calls and enhance performance.
|
||||
- **Local Disk Fallback Caching Mechanism**: In the event of a failure to communicate with the NetBox instance specified, the web app will return data that is locally cached inside a SQLite database.
|
||||
- **Local Disk Fallback Caching Mechanism**: In the event of a failure to communicate with the NetBox instance specified, the web app will return data that is locally cached inside a SQLite database. In the minimal API version of the GeoFeed application, this will be stored as a file, rather than a SQLite database as Minimal API does not yet support Entity Framework Core at this time.
|
||||
- **Secure Communication**: Ensures secure data retrieval from NetBox over HTTPS.
|
||||
|
||||
## Configuration
|
||||
|
||||
The application requires the following configuration variables to be set:
|
||||
The application requires the following configuration variables to be set, depending on the version you are using:
|
||||
|
||||
### For AS1024.GeoFeed - MVC Version
|
||||
1. **APIKey**: This is the API key used for authenticating with the NetBox API. Ensure this key has the necessary permissions to access the required resources.
|
||||
2. **NetBoxHost**: The hostname of the NetBox instance from which the application retrieves data. For example, `netbox.example.com`.
|
||||
3. **LocalFeedCache**: This connection string is for a local SQLite Database that caches the geofeed data from Netbox.
|
||||
3. **LocalFeedCache**: This connection string is for a local SQLite Database (using EF Core) that caches the geofeed data from Netbox. The syntax should follow the standard SQLite EF Core connection string format.
|
||||
|
||||
### For AS1024.GeoFeed.MinimalAPI - MinimalAPI Version
|
||||
1. **APIKey**: This is the API key used for authenticating with the NetBox API. Ensure this key has the necessary permissions to access the required resources.
|
||||
2. **NetBoxHost**: The hostname of the NetBox instance from which the application retrieves data. For example, `netbox.example.com`.
|
||||
3. **TempCache** (optional): This configuration is specific to the Minimal API version. It is optional, but if users wish to specify a different location for storing and serving the cached geofeed data, this value can be adjusted to point to the desired save location.
|
||||
|
||||
These variables can be set in your application's configuration file or through environment variables, depending on your deployment strategy.
|
||||
|
||||
|
||||
## NetBox Custom Fields
|
||||
|
||||
Ensure that your NetBox instance is configured with the following custom fields:
|
||||
@@ -46,6 +67,37 @@ To build and run the application, follow these steps:
|
||||
5. After a successful build, you can start the application by running `dotnet run`.
|
||||
6. The application will start, and you can access the endpoints as specified.
|
||||
|
||||
## Building a Docker Image
|
||||
|
||||
### Building a Docker Image for the Minimal API Version
|
||||
|
||||
To containerize the `AS1024.GeoFeed` version using Docker, you can follow these steps to build a Docker image:
|
||||
|
||||
1. Open your terminal or command line interface.
|
||||
2. Navigate to the root directory of this repository.
|
||||
3. Execute the following Docker build command: ``docker buildx build --platform=linux/amd64,linux/arm64 -f .\AS1024.GeoFeed\Dockerfile .``
|
||||
|
||||
### Building a Docker Image for the Minimal API Version
|
||||
|
||||
To containerize the `AS1024.GeoFeed.MinimalAPI` version using Docker, you can follow these steps to build a Docker image:
|
||||
|
||||
1. Open your terminal or command line interface.
|
||||
2. Navigate to the root directory of this repository.
|
||||
3. Execute the following Docker build command: ``docker buildx build --platform=linux/amd64 -f .\AS1024.GeoFeed.MinimalAPI\Dockerfile.alpine-selfcontained .``
|
||||
|
||||
**Currently the minimal API version does not support being cross compiled for different CPU architectures. It is best built with the same CPU architecture where the build machine is targeting to.**
|
||||
|
||||
Ensure you have Docker installed and configured on your machine before executing this command. This Docker image can then be used to deploy the application in containerized environments such as Kubernetes or Docker Compose setups.
|
||||
|
||||
## Docker Deployment
|
||||
|
||||
To deploy the Docker container of this GeoFeed application, simply pull the image for the following variants:
|
||||
|
||||
- MVC Variant ``docker pull git.startmywifi.com/as1024/geofeed:latest``
|
||||
- Minimal API Variant ``docker pull git.startmywifi.com/as1024/geofeed:aot-minimal``
|
||||
|
||||
To configure the container, please refer to the Configuration section above. You should be able to configure this with either an environment variable or map an ``appSettings.json`` file to the container.
|
||||
|
||||
## Endpoints
|
||||
|
||||
The application provides the following key endpoints:
|
||||
@@ -55,8 +107,10 @@ The application provides the following key endpoints:
|
||||
|
||||
## Security and Compliance
|
||||
|
||||
This application is designed to always communicate over HTTPS with NetBox, ensuring that the data transfer is encrypted and secure.
|
||||
This application is designed to always communicate over HTTPS with NetBox, ensuring that the data transfer is encrypted and secure.
|
||||
|
||||
---
|
||||
## Extending Beyond NetBox
|
||||
|
||||
For more information about configuring and using this application, please refer to the official .NET documentation and the NetBox API guide.
|
||||
If your current IPAM solution is not netbox and wish to extend this web application to use the desired IPAM solution of choice, the interface `IGeoFeedProvider` is available for extensibility. To use your custom IPAM backend ensure that `NetboxAoTGeoFeedProvider` and `NetboxGeoFeedProvider` are not registered in the dependency injection container in the Web Apps. Once unregistered, register your custom IPAM communication backend provider to your needs and the web app should work in both AOT and MVC mode.
|
||||
|
||||
Currently the Minimal API implementation of this web application only supports code that does not require reflection. This is a known limitation of native AOT deployments. If your code utilizes reflection or is not properly adapted for source generation, the minimal API version will **not work**.
|
||||
14
docker/Caddyfile
Normal file
14
docker/Caddyfile
Normal file
@@ -0,0 +1,14 @@
|
||||
{$GEOFEEDDOMAIN}:443 {
|
||||
log {
|
||||
level INFO
|
||||
output file {$LOG_FILE} {
|
||||
roll_size 10MB
|
||||
roll_keep 10
|
||||
}
|
||||
}
|
||||
|
||||
# Use the ACME HTTP-01 challenge to get a cert for the configured domain.
|
||||
tls {$EMAIL}
|
||||
|
||||
reverse_proxy geofeed:8080
|
||||
}
|
||||
28
docker/docker-compose.yml
Normal file
28
docker/docker-compose.yml
Normal file
@@ -0,0 +1,28 @@
|
||||
version: '3.7'
|
||||
services:
|
||||
geofeed:
|
||||
# use the image tag aot-minimal for the AOT version for fastest startup performance
|
||||
image: git.startmywifi.com/as1024/geofeed:latest
|
||||
restart: always
|
||||
volumes:
|
||||
- './data:/data'
|
||||
environment:
|
||||
- ASPNETCORE_URLS=http://+:8080
|
||||
- ConnectionString__LocalFeedCache=Data Source=/data/geofeed-cache.db
|
||||
- APIKey=APIKeyHere
|
||||
- NetBoxHost=netboxhosthere
|
||||
caddy:
|
||||
image: caddy:2
|
||||
restart: always
|
||||
ports:
|
||||
- 80:80
|
||||
- 443:443
|
||||
- 443:443/udp
|
||||
volumes:
|
||||
- ./Caddyfile:/etc/caddy/Caddyfile:ro
|
||||
- ./caddy-config:/config
|
||||
- ./caddy-data:/data
|
||||
environment:
|
||||
GEOFEEDDOMAIN: "https://geofeed.exampleas.net"
|
||||
EMAIL: "noc@example.com" # The email address to use for ACME registration.
|
||||
LOG_FILE: "/data/access.log"
|
||||
Reference in New Issue
Block a user