Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/TickerQ.Dashboard/DashboardOptionsBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
public class DashboardOptionsBuilder
{
internal string BasePath { get; set; } = "/tickerq/dashboard";
internal Action<CorsPolicyBuilder> CorsPolicyBuilder { get; set; }

Check warning on line 13 in src/TickerQ.Dashboard/DashboardOptionsBuilder.cs

View workflow job for this annotation

GitHub Actions / PR Build and Test

Non-nullable property 'CorsPolicyBuilder' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.
internal string BackendDomain { get; set; }

Check warning on line 14 in src/TickerQ.Dashboard/DashboardOptionsBuilder.cs

View workflow job for this annotation

GitHub Actions / PR Build and Test

Non-nullable property 'BackendDomain' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.
internal string GroupName { get; set; }

Check warning on line 15 in src/TickerQ.Dashboard/DashboardOptionsBuilder.cs

View workflow job for this annotation

GitHub Actions / PR Build and Test

Non-nullable property 'GroupName' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

// Clean authentication system
internal AuthConfig Auth { get; set; } = new();
Expand All @@ -35,6 +36,10 @@

public void SetBackendDomain(string backendDomain)
=> BackendDomain = backendDomain;

/// <summary>Set OpenAPI group name for dashboard endpoints</summary>
public void SetGroupName(string groupName)
=> GroupName = groupName;

/// <summary>Configure no authentication (public dashboard)</summary>
public DashboardOptionsBuilder WithNoAuth()
Expand Down Expand Up @@ -101,4 +106,4 @@
{
Auth.Validate();
}
}
}
19 changes: 15 additions & 4 deletions src/TickerQ.Dashboard/Endpoints/DashboardEndpoints.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,22 @@ public static void MapDashboardEndpoints<TTimeTicker, TCronTicker>(this IEndpoin
where TCronTicker : CronTickerEntity, new()
{
// New authentication endpoints
endpoints.MapGet("/api/auth/info", GetAuthInfo)
WithGroupNameIfSet(endpoints.MapGet("/api/auth/info", GetAuthInfo)
.WithName("GetAuthInfo")
.WithSummary("Get authentication configuration")
.WithTags("TickerQ Dashboard")
.RequireCors("TickerQ_Dashboard_CORS")
.AllowAnonymous();
.AllowAnonymous(), config);

endpoints.MapPost("/api/auth/validate", ValidateAuth)
WithGroupNameIfSet(endpoints.MapPost("/api/auth/validate", ValidateAuth)
.WithName("ValidateAuth")
.WithSummary("Validate authentication credentials")
.WithTags("TickerQ Dashboard")
.RequireCors("TickerQ_Dashboard_CORS")
.AllowAnonymous();
.AllowAnonymous(), config);

var apiGroup = endpoints.MapGroup("/api").WithTags("TickerQ Dashboard").RequireCors("TickerQ_Dashboard_CORS");
WithGroupNameIfSet(apiGroup, config);

// Apply authentication if configured
if (config.Auth.Mode == AuthMode.Host)
Expand Down Expand Up @@ -202,6 +203,16 @@ public static void MapDashboardEndpoints<TTimeTicker, TCronTicker>(this IEndpoin

}
#region Endpoint Handlers

private static IEndpointConventionBuilder WithGroupNameIfSet(IEndpointConventionBuilder builder, DashboardOptionsBuilder config)
{
if (!string.IsNullOrWhiteSpace(config.GroupName))
{
builder.WithGroupName(config.GroupName);
}

return builder;
}

private static IResult GetAuthInfo(IAuthService authService, DashboardOptionsBuilder dashboardOptions)
{
Expand Down
12 changes: 12 additions & 0 deletions src/TickerQ.Dashboard/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,17 @@ services.AddTickerQ<MyTimeTicker, MyCronTicker>(config =>
});
```

### Dedicated OpenAPI Group
```csharp
services.AddTickerQ<MyTimeTicker, MyCronTicker>(config =>
{
config.AddDashboard(dashboard =>
{
dashboard.SetGroupName("tickerq");
});
});
```

## πŸ”§ Fluent API Methods

- `WithBasicAuth(username, password)` - Enable username/password authentication
Expand All @@ -67,6 +78,7 @@ services.AddTickerQ<MyTimeTicker, MyCronTicker>(config =>
- `SetBasePath(path)` - Set dashboard URL path
- `SetBackendDomain(domain)` - Set backend API domain
- `SetCorsPolicy(policy)` - Configure CORS
- `SetGroupName(name)` - Set OpenAPI group name for dashboard endpoints

## πŸ”’ How It Works

Expand Down
Loading