Skip to content

Commit

Permalink
Lift badge configuration for LogAnalytics to options
Browse files Browse the repository at this point in the history
  • Loading branch information
kzu committed Aug 13, 2024
1 parent 70cdc34 commit 5cf5ed5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
8 changes: 8 additions & 0 deletions src/Core/SponsorLinkOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,12 @@ public class SponsorLinkOptions
/// Timespan for the expiration of the badge cache, in a format compatible with <see cref="TimeSpan.Parse(string)"/>.
/// </summary>
public string? BadgeExpiration { get; init; }

/// <summary>
/// Optional Azure Log Analytics workspace ID to produce usage badges from the /badge endpoint.
/// </summary>
/// <remarks>
/// Example badge usage: https://img.shields.io/endpoint?color=blue&url=https://sponsorlink.devlooped.com/badge?user
/// </remarks>
public string? LogAnalytics { get; init; }
}
4 changes: 2 additions & 2 deletions src/Web/Badge.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

namespace Devlooped.Sponsors;

public class Badge(IConfiguration config, IHttpClientFactory httpFactory, IMemoryCache cache, IOptions<SponsorLinkOptions> options, ILogger<Badge> logger)
public class Badge(IHttpClientFactory httpFactory, IMemoryCache cache, IOptions<SponsorLinkOptions> options, ILogger<Badge> logger)
{
SponsorLinkOptions options = options.Value;
TimeSpan expiration = TimeSpan.TryParse(options.Value.BadgeExpiration, out var expiration) ? expiration : TimeSpan.FromMinutes(5);
Expand All @@ -23,7 +23,7 @@ public class Badge(IConfiguration config, IHttpClientFactory httpFactory, IMemor
[Function("badge")]
public async Task<HttpResponseData> RunAsync([HttpTrigger(AuthorizationLevel.Anonymous, "get")] HttpRequestData req)
{
var workspace = config["SponsorLink:LogsAnalytics"];
var workspace = options.LogAnalytics;
if (string.IsNullOrEmpty(workspace))
{
logger.LogError("Missing SponsorLink:LogsAnalytics configuration");
Expand Down

0 comments on commit 5cf5ed5

Please sign in to comment.