Skip to content

Commit

Permalink
Add logging in a few places to troubleshoot
Browse files Browse the repository at this point in the history
  • Loading branch information
stephen-vakil committed Jul 19, 2024
1 parent f23510c commit 34d18be
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
6 changes: 6 additions & 0 deletions src/Opserver.Web/Controllers/AdminController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,11 @@ public ActionResult Dashboard()
/// </summary>
[Route("admin/errors/{resource?}/{subResource?}"), AlsoAllow(Roles.LocalRequest)]
public Task InvokeErrorHandler() => ExceptionalMiddleware.HandleRequestAsync(HttpContext);

[Route("admin/throw"), AlsoAllow(Roles.LocalRequest)]
public ActionResult Throw()
{
throw new System.Exception("This is a test exception");
}
}
}
3 changes: 1 addition & 2 deletions src/Opserver.Web/Controllers/AuthController.OIDC.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ private string GetRedirectUri()
Request.Host.Value,
null
);
Console.WriteLine($"Redirect Uri = {redirectUri}");
return redirectUri;
}

Expand Down Expand Up @@ -111,7 +110,7 @@ public async Task<IActionResult> OAuthCallback(string code, string state, string
if (!response.Success)
{
return Error(
$"failed to exchange authorization code for access token. {response.StatusCode} - {response.Data} - uri {redirectUri}"
$"failed to exchange authorization code for access token. {response.StatusCode} - {response.Data}"
);
}

Expand Down
7 changes: 5 additions & 2 deletions src/Opserver.Web/Controllers/HomeController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,18 @@ HAProxyModule haproxy
[DefaultRoute("")]
public ActionResult Home()
{
Console.WriteLine("Home Page loaded");
// TODO: Order
foreach (var m in Modules)
{
//if (m.Enabled && m.SecuritySettings)
// return RedirectToAction()...
Console.WriteLine(m)

Check failure on line 62 in src/Opserver.Web/Controllers/HomeController.cs

View workflow job for this annotation

GitHub Actions / build

; expected
}

static bool AllowMeMaybe(StatusModule m) => m.Enabled && Current.User.HasAccess(m);
static bool AllowMeMaybe(StatusModule m) {
Console.WriteLine($"Module: {m.Name}, Enabled: {m.Enabled}, HasAccess: {Current.User.HasAccess(m)");

Check failure on line 66 in src/Opserver.Web/Controllers/HomeController.cs

View workflow job for this annotation

GitHub Actions / build

Unexpected token '");'

Check failure on line 66 in src/Opserver.Web/Controllers/HomeController.cs

View workflow job for this annotation

GitHub Actions / build

Newline in constant
return m.Enabled && Current.User.HasAccess(m);
}

Check failure on line 68 in src/Opserver.Web/Controllers/HomeController.cs

View workflow job for this annotation

GitHub Actions / build

Unterminated string literal

Check failure on line 68 in src/Opserver.Web/Controllers/HomeController.cs

View workflow job for this annotation

GitHub Actions / build

) expected

Check failure on line 68 in src/Opserver.Web/Controllers/HomeController.cs

View workflow job for this annotation

GitHub Actions / build

; expected

if (AllowMeMaybe(Dashboard))
return RedirectToAction(nameof(DashboardController.Dashboard), "Dashboard");
Expand Down
2 changes: 2 additions & 0 deletions src/Opserver.Web/Security/OIDCProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,13 @@ protected override bool TryValidateToken(OIDCToken token, out ClaimsPrincipal cl

protected override bool InGroupsCore(User user, string[] groupNames)
{
Console.WriteLine("Checking if user is in groups {0}", string.Join(", ", groupNames));
var groupClaims = user.Principal.FindAll(x => x.Type == GroupsClaimType);
foreach (var groupClaim in groupClaims)
{
if (groupNames.Any(x => string.Equals(groupClaim.Value, x, StringComparison.OrdinalIgnoreCase)))
{
Console.WriteLine("User is in group {0}", groupClaim.Value);
return true;
}
}
Expand Down

0 comments on commit 34d18be

Please sign in to comment.