-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add healthcheck controller with loopback-only authorization filter. A…
…dd curl install to Dockerfile.
- Loading branch information
Showing
6 changed files
with
70 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Remotely.Server.Auth; | ||
using Remotely.Server.Services; | ||
using System.Threading.Tasks; | ||
|
||
namespace Remotely.Server.API | ||
{ | ||
/// <summary> | ||
/// Can only be accessed from the local machine. The sole purpose | ||
/// is to provide a healthcheck endpoint for Docker that exercises | ||
/// the database connection. | ||
/// </summary> | ||
[Route("api/[controller]")] | ||
[ApiController] | ||
[ServiceFilter(typeof(LocalOnlyFilter))] | ||
public class HealthCheckController : ControllerBase | ||
{ | ||
private readonly IDataService _dataService; | ||
|
||
public HealthCheckController(IDataService dataService) | ||
{ | ||
_dataService = dataService; | ||
} | ||
|
||
[HttpGet] | ||
public async Task<IActionResult> Get() | ||
{ | ||
var orgCount = await _dataService.GetOrganizationCountAsync(); | ||
return Ok($"Organization Count: {orgCount}"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.AspNetCore.Mvc.Filters; | ||
using System.Net; | ||
|
||
namespace Remotely.Server.Auth | ||
{ | ||
public class LocalOnlyFilter : IAuthorizationFilter | ||
{ | ||
public void OnAuthorization(AuthorizationFilterContext context) | ||
{ | ||
var remoteIp = context.HttpContext.Connection.RemoteIpAddress; | ||
if (!IPAddress.IsLoopback(remoteIp)) | ||
{ | ||
context.Result = new UnauthorizedResult(); | ||
return; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters