Skip to content

Commit

Permalink
Standardize '/version' endpoint on all services (bitwarden#1755)
Browse files Browse the repository at this point in the history
  • Loading branch information
vgrassia authored Dec 9, 2021
1 parent d3673cd commit 2ec10cf
Show file tree
Hide file tree
Showing 18 changed files with 201 additions and 130 deletions.
8 changes: 0 additions & 8 deletions bitwarden_license/src/Sso/Controllers/HomeController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,6 @@ public HomeController(IIdentityServerInteractionService interaction)
_interaction = interaction;
}

[HttpGet("~/alive")]
[HttpGet("~/now")]
[AllowAnonymous]
public DateTime GetAlive()
{
return DateTime.UtcNow;
}

[Route("~/Error")]
[Route("~/Home/Error")]
[AllowAnonymous]
Expand Down
22 changes: 22 additions & 0 deletions bitwarden_license/src/Sso/Controllers/InfoController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System;
using Microsoft.AspNetCore.Mvc;
using Bit.Core.Utilities;

namespace Bit.Sso.Controllers
{
public class InfoController : Controller
{
[HttpGet("~/alive")]
[HttpGet("~/now")]
public DateTime GetAlive()
{
return DateTime.UtcNow;
}

[HttpGet("~/version")]
public JsonResult GetVersion()
{
return Json(CoreHelpers.GetVersion());
}
}
}
10 changes: 1 addition & 9 deletions src/Admin/Controllers/HomeController.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Diagnostics;
using System.Diagnostics;
using Microsoft.AspNetCore.Mvc;
using Bit.Admin.Models;
using Microsoft.AspNetCore.Authorization;
Expand Down Expand Up @@ -29,13 +28,6 @@ public IActionResult Index()
CurrentVersion = Core.Utilities.CoreHelpers.GetVersion()
});
}

[HttpGet("~/alive")]
[HttpGet("~/now")]
public DateTime Get()
{
return DateTime.UtcNow;
}

public IActionResult Error()
{
Expand Down
22 changes: 22 additions & 0 deletions src/Admin/Controllers/InfoController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System;
using Microsoft.AspNetCore.Mvc;
using Bit.Core.Utilities;

namespace Bit.Admin.Controllers
{
public class InfoController : Controller
{
[HttpGet("~/alive")]
[HttpGet("~/now")]
public DateTime GetAlive()
{
return DateTime.UtcNow;
}

[HttpGet("~/version")]
public JsonResult GetVersion()
{
return Json(CoreHelpers.GetVersion());
}
}
}
38 changes: 38 additions & 0 deletions src/Api/Controllers/InfoController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.AspNetCore.Mvc;
using Bit.Core.Utilities;

namespace Bit.Api.Controllers
{
public class InfoController : Controller
{
[HttpGet("~/alive")]
[HttpGet("~/now")]
public DateTime GetAlive()
{
return DateTime.UtcNow;
}

[HttpGet("~/version")]
public JsonResult GetVersion()
{
return Json(CoreHelpers.GetVersion());
}

[HttpGet("~/ip")]
public JsonResult Ip()
{
var headerSet = new HashSet<string> { "x-forwarded-for", "cf-connecting-ip", "client-ip" };
var headers = HttpContext.Request?.Headers
.Where(h => headerSet.Contains(h.Key.ToLower()))
.ToDictionary(h => h.Key);
return new JsonResult(new
{
Ip = HttpContext.Connection?.RemoteIpAddress?.ToString(),
Headers = headers,
});
}
}
}
30 changes: 1 addition & 29 deletions src/Api/Controllers/MiscController.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc;
using Bit.Core.Models.Api;
using System.Threading.Tasks;
using Bit.Core.Utilities;
Expand All @@ -24,33 +23,6 @@ public MiscController(
_globalSettings = globalSettings;
}

[HttpGet("~/alive")]
[HttpGet("~/now")]
public DateTime Get()
{
return DateTime.UtcNow;
}

[HttpGet("~/version")]
public VersionResponseModel Version()
{
return new VersionResponseModel();
}

[HttpGet("~/ip")]
public JsonResult Ip()
{
var headerSet = new HashSet<string> { "x-forwarded-for", "cf-connecting-ip", "client-ip" };
var headers = HttpContext.Request?.Headers
.Where(h => headerSet.Contains(h.Key.ToLower()))
.ToDictionary(h => h.Key);
return new JsonResult(new
{
Ip = HttpContext.Connection?.RemoteIpAddress?.ToString(),
Headers = headers,
});
}

[Authorize("Application")]
[HttpPost("~/bitpay-invoice")]
[SelfHosted(NotSelfHostedOnly = true)]
Expand Down
25 changes: 0 additions & 25 deletions src/Billing/Controllers/HomeController.cs

This file was deleted.

22 changes: 22 additions & 0 deletions src/Billing/Controllers/InfoController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System;
using Microsoft.AspNetCore.Mvc;
using Bit.Core.Utilities;

namespace Bit.Billing.Controllers
{
public class InfoController : Controller
{
[HttpGet("~/alive")]
[HttpGet("~/now")]
public DateTime GetAlive()
{
return DateTime.UtcNow;
}

[HttpGet("~/version")]
public JsonResult GetVersion()
{
return Json(CoreHelpers.GetVersion());
}
}
}
16 changes: 0 additions & 16 deletions src/Core/Models/Api/Response/VersionResponseModel.cs

This file was deleted.

8 changes: 0 additions & 8 deletions src/Events/Controllers/CollectController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,6 @@ public CollectController(
_cipherRepository = cipherRepository;
}

[HttpGet("~/alive")]
[HttpGet("~/now")]
[AllowAnonymous]
public DateTime GetAlive()
{
return DateTime.UtcNow;
}

[HttpPost]
public async Task<IActionResult> Post([FromBody]IEnumerable<EventModel> model)
{
Expand Down
22 changes: 22 additions & 0 deletions src/Events/Controllers/InfoController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System;
using Microsoft.AspNetCore.Mvc;
using Bit.Core.Utilities;

namespace Bit.Events.Controllers
{
public class InfoController : Controller
{
[HttpGet("~/alive")]
[HttpGet("~/now")]
public DateTime GetAlive()
{
return DateTime.UtcNow;
}

[HttpGet("~/version")]
public JsonResult GetVersion()
{
return Json(CoreHelpers.GetVersion());
}
}
}
7 changes: 6 additions & 1 deletion src/EventsProcessor/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,12 @@ public void Configure(
app.UseEndpoints(endpoints =>
{
endpoints.MapGet("/alive",
async context => await context.Response.WriteAsync(System.DateTime.UtcNow.ToString()));
async context => await context.Response.WriteAsJsonAsync(System.DateTime.UtcNow));
endpoints.MapGet("/now",
async context => await context.Response.WriteAsJsonAsync(System.DateTime.UtcNow));
endpoints.MapGet("/version",
async context => await context.Response.WriteAsJsonAsync(CoreHelpers.GetVersion()));

});
}
}
Expand Down
7 changes: 0 additions & 7 deletions src/Icons/Controllers/IconsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,6 @@ public IconsController(
_iconsSettings = iconsSettings;
}

[HttpGet("~/alive")]
[HttpGet("~/now")]
public DateTime GetAlive()
{
return DateTime.UtcNow;
}

[HttpGet("~/config")]
public IActionResult GetConfig()
{
Expand Down
22 changes: 22 additions & 0 deletions src/Icons/Controllers/InfoController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System;
using Microsoft.AspNetCore.Mvc;
using Bit.Core.Utilities;

namespace Bit.Icons.Controllers
{
public class InfoController : Controller
{
[HttpGet("~/alive")]
[HttpGet("~/now")]
public DateTime GetAlive()
{
return DateTime.UtcNow;
}

[HttpGet("~/version")]
public JsonResult GetVersion()
{
return Json(CoreHelpers.GetVersion());
}
}
}
22 changes: 22 additions & 0 deletions src/Identity/Controllers/InfoController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System;
using Microsoft.AspNetCore.Mvc;
using Bit.Core.Utilities;

namespace Bit.Identity.Controllers
{
public class InfoController : Controller
{
[HttpGet("~/alive")]
[HttpGet("~/now")]
public DateTime GetAlive()
{
return DateTime.UtcNow;
}

[HttpGet("~/version")]
public JsonResult GetVersion()
{
return Json(CoreHelpers.GetVersion());
}
}
}
17 changes: 0 additions & 17 deletions src/Identity/Controllers/MiscController.cs

This file was deleted.

22 changes: 22 additions & 0 deletions src/Notifications/Controllers/InfoController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System;
using Microsoft.AspNetCore.Mvc;
using Bit.Core.Utilities;

namespace Bit.Notifications.Controllers
{
public class InfoController : Controller
{
[HttpGet("~/alive")]
[HttpGet("~/now")]
public DateTime GetAlive()
{
return DateTime.UtcNow;
}

[HttpGet("~/version")]
public JsonResult GetVersion()
{
return Json(CoreHelpers.GetVersion());
}
}
}
Loading

0 comments on commit 2ec10cf

Please sign in to comment.