Skip to content

Commit 12ee2c6

Browse files
committed
log to file, secure admin endpoints
1 parent 97a7bf7 commit 12ee2c6

File tree

5 files changed

+34
-14
lines changed

5 files changed

+34
-14
lines changed

.github/workflows/dotnet-cd.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ jobs:
3737

3838
deploy:
3939
environment:
40-
name: AZ-TEST
40+
name: AZ-Test
4141
url: https://test.rubberduckvba.com
4242
permissions:
4343
contents: none

rubberduckvba.Server/Api/Admin/AdminController.cs

+5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using Hangfire;
2+
using Microsoft.AspNetCore.Authorization;
23
using Microsoft.AspNetCore.Mvc;
34
using Microsoft.Extensions.Options;
45
using rubberduckvba.com.Server.ContentSynchronization;
@@ -7,13 +8,15 @@
78
namespace rubberduckvba.com.Server.Api.Admin;
89

910

11+
[Authorize("github")]
1012
[ApiController]
1113
public class AdminController(ConfigurationOptions options, IBackgroundJobClient backgroundJob, ILogger<AdminController> logger) : ControllerBase
1214
{
1315
/// <summary>
1416
/// Enqueues a job that updates xmldoc content from the latest release/pre-release tags.
1517
/// </summary>
1618
/// <returns>The unique identifier of the enqueued job.</returns>
19+
[Authorize("github")]
1720
[HttpPost("admin/update/xmldoc")]
1821
public async ValueTask<IActionResult> UpdateXmldocContent()
1922
{
@@ -28,6 +31,7 @@ public async ValueTask<IActionResult> UpdateXmldocContent()
2831
/// Enqueues a job that gets the latest release/pre-release tags and their respective assets, and updates the installer download stats.
2932
/// </summary>
3033
/// <returns>The unique identifier of the enqueued job.</returns>
34+
[Authorize("github")]
3135
[HttpPost("admin/update/tags")]
3236
public async ValueTask<IActionResult> UpdateTagMetadata()
3337
{
@@ -38,6 +42,7 @@ public async ValueTask<IActionResult> UpdateTagMetadata()
3842
return await ValueTask.FromResult(Ok(jobId));
3943
}
4044

45+
[Authorize("github")]
4146
[HttpGet("admin/config/current")]
4247
public async ValueTask<IActionResult> Config()
4348
{

rubberduckvba.Server/ContentSynchronization/Pipeline/Abstract/PipelineSection.cs

+17-12
Original file line numberDiff line numberDiff line change
@@ -45,27 +45,28 @@ public void TraceBlockCompletion(IDataflowBlock block, string name)
4545
break;
4646
}
4747
Logger.LogTrace(Context.Parameters, $"{GetType().Name} | ✅ Dataflow block completion task completed | {name} ({block.GetType().Name}) | {status}");
48-
})
49-
.ContinueWith(t =>
50-
{
51-
var details = Blocks.Select(
52-
block => $"{(block.Value.Completion.IsCompletedSuccessfully ? "✔️" :
53-
block.Value.Completion.IsFaulted ? "✖️" :
54-
block.Value.Completion.IsCanceled ? "⛔" : "🕑")} {block.Key} : {block.Value.Completion.Status}");
55-
Logger.LogTrace(Context.Parameters, "Pipeline block completion status details" + Environment.NewLine + string.Join(Environment.NewLine, details));
56-
}));
48+
}).ContinueWith(t =>
49+
{
50+
var details = Blocks.Select(
51+
block => $"{(
52+
block.Value.Completion.IsCompletedSuccessfully ? "✔️"
53+
: block.Value.Completion.IsFaulted ? "✖️"
54+
: block.Value.Completion.IsCanceled ? "⛔"
55+
: "🕑")} {block.Key} : {block.Value.Completion.Status}");
56+
Logger.LogTrace(Context.Parameters, "Pipeline block completion status details" + Environment.NewLine + string.Join(Environment.NewLine, details));
57+
}));
5758
}
5859

5960
public void FaultPipelineBlock(IDataflowBlock block, Exception exception)
6061
{
62+
block.Fault(exception);
63+
Logger.LogWarning(Context.Parameters, $"{GetType().Name} | ⚠️ Block ({block.GetType().Name}) was faulted");
64+
6165
if (Exception is null)
6266
{
6367
Exception = exception;
6468
Result.AddException(exception);
6569

66-
block.Fault(exception);
67-
Logger.LogWarning(Context.Parameters, $"{GetType().Name} | ⚠️ Block ({block.GetType().Name}) was faulted");
68-
6970
try
7071
{
7172
Logger.LogWarning(Context.Parameters, $"{GetType().Name} | ⚠️ Cancelling token source");
@@ -77,6 +78,10 @@ public void FaultPipelineBlock(IDataflowBlock block, Exception exception)
7778
Logger.LogWarning(Context.Parameters, $"{GetType().Name} | ⚠️ Token source disposed: cancellation already happened");
7879
}
7980
}
81+
else
82+
{
83+
Exception = new AggregateException([Exception, exception]);
84+
}
8085
}
8186

8287
protected void ThrowIfCancellationRequested() => Token.ThrowIfCancellationRequested();

rubberduckvba.Server/Program.cs

+10
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,16 @@ private static void ConfigureLogging(IServiceCollection services)
169169

170170
(NLog.LogLevel MinLevel, string, Target Target)[] targets = [
171171
(NLog.LogLevel.Trace, "*", new DebuggerTarget("DebuggerLog")),
172+
(NLog.LogLevel.Info, "rubberduckvba.*", new FileTarget("FileLog")
173+
{
174+
FileName = "rubberduckvba.Server.log",
175+
DeleteOldFileOnStartup = true,
176+
CreateDirs = true,
177+
ArchiveEvery = FileArchivePeriod.Day,
178+
ArchiveOldFileOnStartup = true,
179+
EnableFileDelete = true,
180+
MaxArchiveDays = 10,
181+
}),
172182
(NLog.LogLevel.Error, "*", new EventLogTarget("EventLog")
173183
{
174184
Source = "rubberduckvba.Server",

rubberduckvba.Server/appsettings.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"AutoRetryAttempts": 2,
1919
"AutoRetryDelaySeconds": [ 2, 5, 10, 30, 60 ],
2020
"HeartbeatIntervalMinutes": 1,
21-
"CancellationCheckIntervalSeconds": 5,
21+
"CancellationCheckIntervalSeconds": 300,
2222
"ConfigureHangfireServerOnStartup": true,
2323
"CreateUpdateInstallerDownloadsJob": true,
2424
"CreateUpdateXmldocContentJob": true,

0 commit comments

Comments
 (0)