feat(archival): enable readonly Hangfire Dashboard

This commit is contained in:
Collin M. Barrett 2020-09-22 16:47:33 -05:00
parent a4309e4ffd
commit 8eb6f52f09
6 changed files with 57 additions and 1 deletions

View file

@ -1,6 +1,18 @@
server {
listen 80 default_server;
location ^~ /api/archival/ {
rewrite ^/api/archival/(.*)$ /$1 break;
proxy_pass http://archival-api:80;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection keep-alive;
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
location ^~ /api/ {
rewrite ^/api/(.*)$ /$1 break;
proxy_pass http://directory-api:80;

View file

@ -8,6 +8,18 @@ server {
ssl_certificate_key /etc/nginx/cert/filterlists_key.pem;
add_header Content-Security-Policy "default-src 'none'; connect-src 'self'; img-src 'self' data:; manifest-src 'self'; script-src 'self' 'unsafe-inline'; style-src 'self' 'unsafe-inline'; base-uri 'none'; form-action 'none'; frame-ancestors 'none';" always;
location ^~ /api/archival/ {
rewrite ^/api/archival/(.*)$ /$1 break;
proxy_pass http://archival-api:80;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection keep-alive;
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
location ^~ /api/ {
rewrite ^/api/(.*)$ /$1 break;

View file

@ -2,6 +2,7 @@
FROM mcr.microsoft.com/dotnet/core/runtime-deps:3.1.7-alpine AS base
LABEL org.opencontainers.image.description="filterlists.com | github.com/collinbarrett/filterlists | A .NET Core app archiving copies of FilterLists for mirrors and future analysis."
WORKDIR /app
EXPOSE 80
# init build
FROM mcr.microsoft.com/dotnet/core/sdk:3.1.401-alpine AS build

View file

@ -1,4 +1,6 @@
using FilterLists.Archival.Application;
using FilterLists.Archival.Application;
using FilterLists.Archival.Infrastructure.Scheduling;
using Hangfire;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
@ -18,6 +20,9 @@ public Startup(IConfiguration configuration)
public void ConfigureServices(IServiceCollection services)
{
services.AddRouting(o => o.LowercaseUrls = true);
services.AddControllers()
.AddJsonOptions(o => o.JsonSerializerOptions.IgnoreNullValues = true);
services.AddApplicationServices(Configuration);
}
@ -28,6 +33,19 @@ public static void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
app.UseDeveloperExceptionPage();
}
app.UseStaticFiles();
app.UseRouting();
app.UseEndpoints(e =>
{
e.MapControllers();
e.MapHangfireDashboard(new DashboardOptions
{
PrefixPath = "/api/archival/",
Authorization = new[] {new DashboardAuthorizationFilter()},
IsReadOnlyFunc = _ => true
});
});
}
}
}

View file

@ -1,6 +1,7 @@
# init base for Visual Studio debugging
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1.7-alpine AS base
WORKDIR /app
EXPOSE 80
# init build
FROM mcr.microsoft.com/dotnet/core/sdk:3.1.401-alpine AS build

View file

@ -0,0 +1,12 @@
using Hangfire.Dashboard;
namespace FilterLists.Archival.Infrastructure.Scheduling
{
public class DashboardAuthorizationFilter : IDashboardAuthorizationFilter
{
public bool Authorize(DashboardContext context)
{
return true;
}
}
}