1
0
mirror of https://github.com/bitwarden/server.git synced 2024-12-22 16:57:36 +01:00

Standardize '/version' endpoint on all services (#1755)

This commit is contained in:
Vince Grassia 2021-12-09 15:45:45 -05:00 committed by GitHub
parent d3673cdc85
commit 2ec10cfd2a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
18 changed files with 201 additions and 130 deletions

View File

@ -18,14 +18,6 @@ namespace Bit.Sso.Controllers
_interaction = interaction;
}
[HttpGet("~/alive")]
[HttpGet("~/now")]
[AllowAnonymous]
public DateTime GetAlive()
{
return DateTime.UtcNow;
}
[Route("~/Error")]
[Route("~/Home/Error")]
[AllowAnonymous]

View File

@ -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());
}
}
}

View File

@ -1,5 +1,4 @@
using System;
using System.Diagnostics;
using System.Diagnostics;
using Microsoft.AspNetCore.Mvc;
using Bit.Admin.Models;
using Microsoft.AspNetCore.Authorization;
@ -29,13 +28,6 @@ namespace Bit.Admin.Controllers
CurrentVersion = Core.Utilities.CoreHelpers.GetVersion()
});
}
[HttpGet("~/alive")]
[HttpGet("~/now")]
public DateTime Get()
{
return DateTime.UtcNow;
}
public IActionResult Error()
{

View File

@ -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());
}
}
}

View File

@ -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,
});
}
}
}

View File

@ -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;
@ -24,33 +23,6 @@ namespace Bit.Api.Controllers
_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)]

View File

@ -1,25 +0,0 @@
using System;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
namespace Billing.Controllers
{
public class HomeController : Controller
{
[HttpGet("~/alive")]
[HttpGet("~/now")]
[AllowAnonymous]
public DateTime GetAlive()
{
return DateTime.UtcNow;
}
/*
[Authorize]
public IActionResult Index()
{
return View();
}
*/
}
}

View File

@ -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());
}
}
}

View File

@ -1,16 +0,0 @@
using System;
using Bit.Core.Utilities;
namespace Bit.Core.Models.Api
{
public class VersionResponseModel : ResponseModel
{
public VersionResponseModel()
: base("version")
{
Version = CoreHelpers.GetVersion();
}
public string Version { get; set; }
}
}

View File

@ -32,14 +32,6 @@ namespace Bit.Events.Controllers
_cipherRepository = cipherRepository;
}
[HttpGet("~/alive")]
[HttpGet("~/now")]
[AllowAnonymous]
public DateTime GetAlive()
{
return DateTime.UtcNow;
}
[HttpPost]
public async Task<IActionResult> Post([FromBody]IEnumerable<EventModel> model)
{

View File

@ -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());
}
}
}

View File

@ -49,7 +49,12 @@ namespace Bit.EventsProcessor
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()));
});
}
}

View File

@ -39,13 +39,6 @@ namespace Bit.Icons.Controllers
_iconsSettings = iconsSettings;
}
[HttpGet("~/alive")]
[HttpGet("~/now")]
public DateTime GetAlive()
{
return DateTime.UtcNow;
}
[HttpGet("~/config")]
public IActionResult GetConfig()
{

View File

@ -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());
}
}
}

View File

@ -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());
}
}
}

View File

@ -1,17 +0,0 @@
using System;
using Microsoft.AspNetCore.Mvc;
namespace Bit.Identity.Controllers
{
public class MiscController : Controller
{
public MiscController() { }
[HttpGet("~/alive")]
[HttpGet("~/now")]
public DateTime Get()
{
return DateTime.UtcNow;
}
}
}

View File

@ -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());
}
}
}

View File

@ -1,5 +1,4 @@
using System;
using System.IO;
using System.IO;
using System.Text;
using System.Threading.Tasks;
using Bit.Core.Utilities;
@ -19,14 +18,6 @@ namespace Bit.Notifications
_hubContext = hubContext;
}
[HttpGet("~/alive")]
[HttpGet("~/now")]
[AllowAnonymous]
public DateTime GetAlive()
{
return DateTime.UtcNow;
}
[HttpPost("~/send")]
[SelfHosted(SelfHostedOnly = true)]
public async Task PostSend()