Skip to content

Commit

Permalink
Added more comments
Browse files Browse the repository at this point in the history
  • Loading branch information
davidfowl committed Nov 12, 2022
1 parent a84369d commit cb98a17
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 3 deletions.
4 changes: 2 additions & 2 deletions TodoApi.Tests/TodoApplication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ protected override IHost CreateHost(IHostBuilder builder)
services.AddDbContextFactory<TodoDbContext>(options => options.UseInMemoryDatabase("Testing", root));
});

// We need to configure signing keys for CI scenarios where
// there's no user-jwts tool
var keyBytes = new byte[32];
RandomNumberGenerator.Fill(keyBytes);
var base64Key = Convert.ToBase64String(keyBytes);

// We need to configure signing keys for CI scenarios where
// there's no user-jwts tool
builder.ConfigureAppConfiguration(config =>
{
config.AddInMemoryCollection(new Dictionary<string, string?>
Expand Down
1 change: 1 addition & 0 deletions TodoApi/OpenApiExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ namespace TodoApi;

public static class OpenApiExtensions
{
// Adds the JWT security scheme to the Open API description
public static IEndpointConventionBuilder AddOpenApiSecurityRequirement(this IEndpointConventionBuilder builder)
{
var scheme = new OpenApiSecurityScheme()
Expand Down
2 changes: 2 additions & 0 deletions TodoApi/OpenTelemetryExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ namespace TodoApi;

public static class OpenTelemetryExtensions
{
// Configures logging, distributed tracing, and metrics (with a prometheus endpoint)
// Other exporters can be configured to send telemetry to.
public static WebApplicationBuilder AddOpenTelemetry(this WebApplicationBuilder builder)
{
var resourceBuilder = ResourceBuilder.CreateDefault().AddService(builder.Environment.ApplicationName);
Expand Down
2 changes: 2 additions & 0 deletions TodoApi/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,7 @@

// Configure the prometheus endpoint for scraping metrics
app.MapPrometheusScrapingEndpoint();
// NOTE: This should only be exposed on an internal port!
// .RequireHost("*:9100");

app.Run();
4 changes: 3 additions & 1 deletion TodoApi/UserId.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

namespace TodoApi;

// This is a struct that we're using to bind the relevant user
// claims in a more friendly way.
public record struct UserId(string Id, bool IsAdmin)
{
public static ValueTask<UserId> BindAsync(HttpContext context)
{
// Grab the id claim
// Grab the id claim and check if the user is an admin
var id = context.User.FindFirstValue("id")!;
var isAdmin = context.User.IsInRole("admin");

Expand Down

0 comments on commit cb98a17

Please sign in to comment.