Skip to content

Commit

Permalink
Log decisions on debug
Browse files Browse the repository at this point in the history
  • Loading branch information
oanatmaria committed Jan 26, 2024
1 parent 37216bc commit bc60f85
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
7 changes: 3 additions & 4 deletions src/Aserto.AspNetCore.Middleware/AsertoMiddleware.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,30 +66,29 @@ public async Task Invoke(HttpContext context)
var endpoint = context.GetEndpoint();
if (endpoint == null)
{
this.logger.LogInformation($"Endpoint information for: {context.Request.Path} is null - allowing request");
this.logger.LogDebug($"Endpoint information for: {context.Request.Path} is null - allowing request");
await this.next.Invoke(context);
return;
}

var asertoAttribute = endpoint.Metadata.GetMetadata<Extensions.AsertoAttribute>();
if (asertoAttribute == null)
{
this.logger.LogInformation($"Endpoint information for: {context.Request.Path} does not have aserto attribute - allowing request");
this.logger.LogDebug($"Endpoint information for: {context.Request.Path} does not have aserto attribute - allowing request");
await this.next.Invoke(context);
return;
}

var allowed = await this.client.IsAsync(this.client.BuildIsRequest(context, Utils.DefaultClaimTypes, this.options));
if (!allowed && this.options.Enabled)
{
this.logger.LogInformation($"Decision to allow: {context.Request.Path} was: {allowed}");
context.Response.StatusCode = (int)HttpStatusCode.Forbidden;
var errorMessage = Encoding.UTF8.GetBytes(HttpStatusCode.Forbidden.ToString());
await context.Response.Body.WriteAsync(errorMessage, 0, errorMessage.Length);
}
else
{
this.logger.LogInformation($"Decision to allow: {context.Request.Path} was: {allowed}");
this.logger.LogDebug($"Decision to allow: {context.Request.Path} was: {allowed}");
await this.next.Invoke(context);
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/Aserto.AspNetCore.Middleware/CheckMiddleware.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,15 @@ public async Task Invoke(HttpContext context)
var endpoint = context.GetEndpoint();
if (endpoint == null)
{
this.logger.LogInformation($"Endpoint information for: {context.Request.Path} is null - allowing request");
this.logger.LogDebug($"Endpoint information for: {context.Request.Path} is null - allowing request");
await this.next.Invoke(context);
return;
}

var checkAttribute = endpoint.Metadata.GetMetadata<Extensions.CheckAttribute>();
if (checkAttribute == null)
{
this.logger.LogInformation($"Endpoint information for: {context.Request.Path} does not have check attribute - allowing request");
this.logger.LogDebug($"Endpoint information for: {context.Request.Path} does not have check attribute - allowing request");
await this.next.Invoke(context);
return;
}
Expand All @@ -103,7 +103,7 @@ public async Task Invoke(HttpContext context)
}
else
{
this.logger.LogInformation($"Decision to allow: {context.Request.Path} was: {allowed}");
this.logger.LogDebug($"Decision to allow: {context.Request.Path} was: {allowed}");
await this.next.Invoke(context);
}
}
Expand Down

0 comments on commit bc60f85

Please sign in to comment.