diff --git a/Directory.Build.props b/Directory.Build.props
index 3a158daa0..d37501b6d 100644
--- a/Directory.Build.props
+++ b/Directory.Build.props
@@ -7,6 +7,7 @@
Bit.$(MSBuildProjectName)
true
enable
+ false
+
+
+
+
+
+
+
+
+ <_Parameter1>GitHash
+ <_Parameter2>$(SourceRevisionId)
+
+
+
+
\ No newline at end of file
diff --git a/bitwarden_license/src/Scim/Controllers/InfoController.cs b/bitwarden_license/src/Scim/Controllers/InfoController.cs
index aa08ce9bf..9959bfb0a 100644
--- a/bitwarden_license/src/Scim/Controllers/InfoController.cs
+++ b/bitwarden_license/src/Scim/Controllers/InfoController.cs
@@ -17,6 +17,6 @@ public class InfoController : Controller
[HttpGet("~/version")]
public JsonResult GetVersion()
{
- return Json(CoreHelpers.GetVersion());
+ return Json(AssemblyHelpers.GetVersion());
}
}
diff --git a/bitwarden_license/src/Sso/Controllers/InfoController.cs b/bitwarden_license/src/Sso/Controllers/InfoController.cs
index c3641c466..67794de75 100644
--- a/bitwarden_license/src/Sso/Controllers/InfoController.cs
+++ b/bitwarden_license/src/Sso/Controllers/InfoController.cs
@@ -15,6 +15,6 @@ public class InfoController : Controller
[HttpGet("~/version")]
public JsonResult GetVersion()
{
- return Json(CoreHelpers.GetVersion());
+ return Json(AssemblyHelpers.GetVersion());
}
}
diff --git a/bitwarden_license/src/Sso/Views/Shared/_Layout.cshtml b/bitwarden_license/src/Sso/Views/Shared/_Layout.cshtml
index 4467f08f2..ae7511942 100644
--- a/bitwarden_license/src/Sso/Views/Shared/_Layout.cshtml
+++ b/bitwarden_license/src/Sso/Views/Shared/_Layout.cshtml
@@ -1,4 +1,4 @@
-@using static Bit.Core.Utilities.CoreHelpers;
+@using static Bit.Core.Utilities.AssemblyHelpers;
diff --git a/src/Admin/Controllers/HomeController.cs b/src/Admin/Controllers/HomeController.cs
index 5e3b76ebb..20c1be70d 100644
--- a/src/Admin/Controllers/HomeController.cs
+++ b/src/Admin/Controllers/HomeController.cs
@@ -26,7 +26,7 @@ public class HomeController : Controller
return View(new HomeModel
{
GlobalSettings = _globalSettings,
- CurrentVersion = Core.Utilities.CoreHelpers.GetVersion()
+ CurrentVersion = Core.Utilities.AssemblyHelpers.GetVersion()
});
}
diff --git a/src/Admin/Controllers/InfoController.cs b/src/Admin/Controllers/InfoController.cs
index 0c097fde7..dc41721de 100644
--- a/src/Admin/Controllers/InfoController.cs
+++ b/src/Admin/Controllers/InfoController.cs
@@ -15,6 +15,6 @@ public class InfoController : Controller
[HttpGet("~/version")]
public JsonResult GetVersion()
{
- return Json(CoreHelpers.GetVersion());
+ return Json(AssemblyHelpers.GetVersion());
}
}
diff --git a/src/Api/Api.csproj b/src/Api/Api.csproj
index 30ef64658..901036fcc 100644
--- a/src/Api/Api.csproj
+++ b/src/Api/Api.csproj
@@ -32,5 +32,5 @@
-
+
diff --git a/src/Api/Controllers/ConfigController.cs b/src/Api/Controllers/ConfigController.cs
new file mode 100644
index 000000000..51d224bc6
--- /dev/null
+++ b/src/Api/Controllers/ConfigController.cs
@@ -0,0 +1,23 @@
+using Bit.Api.Models.Response;
+using Bit.Core.Settings;
+
+using Microsoft.AspNetCore.Mvc;
+
+namespace Bit.Api.Controllers;
+
+[Route("config")]
+public class ConfigController : Controller
+{
+ private readonly IGlobalSettings _globalSettings;
+
+ public ConfigController(IGlobalSettings globalSettings)
+ {
+ _globalSettings = globalSettings;
+ }
+
+ [HttpGet("")]
+ public ConfigResponseModel GetConfigs()
+ {
+ return new ConfigResponseModel(_globalSettings);
+ }
+}
diff --git a/src/Api/Controllers/InfoController.cs b/src/Api/Controllers/InfoController.cs
index 739f9f425..9c6b7b886 100644
--- a/src/Api/Controllers/InfoController.cs
+++ b/src/Api/Controllers/InfoController.cs
@@ -15,7 +15,7 @@ public class InfoController : Controller
[HttpGet("~/version")]
public JsonResult GetVersion()
{
- return Json(CoreHelpers.GetVersion());
+ return Json(AssemblyHelpers.GetVersion());
}
[HttpGet("~/ip")]
diff --git a/src/Api/Models/Response/ConfigResponseModel.cs b/src/Api/Models/Response/ConfigResponseModel.cs
new file mode 100644
index 000000000..ad2d79a83
--- /dev/null
+++ b/src/Api/Models/Response/ConfigResponseModel.cs
@@ -0,0 +1,51 @@
+using Bit.Core.Models.Api;
+using Bit.Core.Settings;
+using Bit.Core.Utilities;
+
+namespace Bit.Api.Models.Response;
+
+public class ConfigResponseModel : ResponseModel
+{
+ public string Version { get; set; }
+ public string GitHash { get; set; }
+ public ServerConfigResponseModel Server { get; set; }
+ public EnvironmentConfigResponseModel Environment { get; set; }
+
+ public ConfigResponseModel(string obj = "config") : base(obj)
+ {
+ Version = AssemblyHelpers.GetVersion();
+ GitHash = AssemblyHelpers.GetGitHash();
+ Environment = new EnvironmentConfigResponseModel();
+ }
+
+ public ConfigResponseModel(IGlobalSettings globalSettings, string obj = "config") : base(obj)
+ {
+ Version = AssemblyHelpers.GetVersion();
+ GitHash = AssemblyHelpers.GetGitHash();
+ Environment = new EnvironmentConfigResponseModel
+ {
+ Vault = globalSettings.BaseServiceUri.Vault,
+ Api = globalSettings.BaseServiceUri.Api,
+ Identity = globalSettings.BaseServiceUri.Identity,
+ Admin = globalSettings.BaseServiceUri.Admin,
+ Notifications = globalSettings.BaseServiceUri.Notifications,
+ Sso = globalSettings.BaseServiceUri.Sso
+ };
+ }
+}
+
+public class ServerConfigResponseModel
+{
+ public string Name { get; set; }
+ public string Url { get; set; }
+}
+
+public class EnvironmentConfigResponseModel
+{
+ public string Vault { get; set; }
+ public string Api { get; set; }
+ public string Identity { get; set; }
+ public string Admin { get; set; }
+ public string Notifications { get; set; }
+ public string Sso { get; set; }
+}
diff --git a/src/Billing/Controllers/InfoController.cs b/src/Billing/Controllers/InfoController.cs
index 58b29f4c4..16c015844 100644
--- a/src/Billing/Controllers/InfoController.cs
+++ b/src/Billing/Controllers/InfoController.cs
@@ -15,6 +15,6 @@ public class InfoController : Controller
[HttpGet("~/version")]
public JsonResult GetVersion()
{
- return Json(CoreHelpers.GetVersion());
+ return Json(AssemblyHelpers.GetVersion());
}
}
diff --git a/src/Core/Utilities/AssemblyHelpers.cs b/src/Core/Utilities/AssemblyHelpers.cs
new file mode 100644
index 000000000..a00e10851
--- /dev/null
+++ b/src/Core/Utilities/AssemblyHelpers.cs
@@ -0,0 +1,43 @@
+using System.Reflection;
+
+namespace Bit.Core.Utilities;
+
+public static class AssemblyHelpers
+{
+ private static readonly IEnumerable _assemblyMetadataAttributes;
+ private static readonly AssemblyInformationalVersionAttribute _assemblyInformationalVersionAttributes;
+ private const string GIT_HASH_ASSEMBLY_KEY = "GitHash";
+ private static string _version;
+ private static string _gitHash;
+
+ static AssemblyHelpers()
+ {
+ _assemblyMetadataAttributes = Assembly.GetEntryAssembly().GetCustomAttributes();
+ _assemblyInformationalVersionAttributes = Assembly.GetEntryAssembly().GetCustomAttribute();
+ }
+
+ public static string GetVersion()
+ {
+ if (string.IsNullOrWhiteSpace(_version))
+ {
+ _version = _assemblyInformationalVersionAttributes.InformationalVersion;
+ }
+
+ return _version;
+ }
+
+ public static string GetGitHash()
+ {
+ if (string.IsNullOrWhiteSpace(_gitHash))
+ {
+ try
+ {
+ _gitHash = _assemblyMetadataAttributes.Where(i => i.Key == GIT_HASH_ASSEMBLY_KEY).First().Value;
+ }
+ catch (Exception)
+ { }
+ }
+
+ return _gitHash;
+ }
+}
diff --git a/src/Core/Utilities/CoreHelpers.cs b/src/Core/Utilities/CoreHelpers.cs
index ef6848cf1..0185281b8 100644
--- a/src/Core/Utilities/CoreHelpers.cs
+++ b/src/Core/Utilities/CoreHelpers.cs
@@ -459,18 +459,6 @@ public static class CoreHelpers
return val.ToString();
}
- public static string GetVersion()
- {
- if (string.IsNullOrWhiteSpace(_version))
- {
- _version = Assembly.GetEntryAssembly()
- .GetCustomAttribute()
- .InformationalVersion;
- }
-
- return _version;
- }
-
public static string SanitizeForEmail(string value, bool htmlEncode = true)
{
var cleanedValue = value.Replace("@", "[at]");
diff --git a/src/Events/Controllers/InfoController.cs b/src/Events/Controllers/InfoController.cs
index 6d42f6757..46f21a0f0 100644
--- a/src/Events/Controllers/InfoController.cs
+++ b/src/Events/Controllers/InfoController.cs
@@ -15,6 +15,6 @@ public class InfoController : Controller
[HttpGet("~/version")]
public JsonResult GetVersion()
{
- return Json(CoreHelpers.GetVersion());
+ return Json(AssemblyHelpers.GetVersion());
}
}
diff --git a/src/EventsProcessor/Startup.cs b/src/EventsProcessor/Startup.cs
index d0a624f73..2f64c0f92 100644
--- a/src/EventsProcessor/Startup.cs
+++ b/src/EventsProcessor/Startup.cs
@@ -48,7 +48,7 @@ public class Startup
endpoints.MapGet("/now",
async context => await context.Response.WriteAsJsonAsync(System.DateTime.UtcNow));
endpoints.MapGet("/version",
- async context => await context.Response.WriteAsJsonAsync(CoreHelpers.GetVersion()));
+ async context => await context.Response.WriteAsJsonAsync(AssemblyHelpers.GetVersion()));
});
}
diff --git a/src/Icons/Controllers/InfoController.cs b/src/Icons/Controllers/InfoController.cs
index 1ebbd473a..253ee7cc7 100644
--- a/src/Icons/Controllers/InfoController.cs
+++ b/src/Icons/Controllers/InfoController.cs
@@ -15,6 +15,6 @@ public class InfoController : Controller
[HttpGet("~/version")]
public JsonResult GetVersion()
{
- return Json(CoreHelpers.GetVersion());
+ return Json(AssemblyHelpers.GetVersion());
}
}
diff --git a/src/Identity/Controllers/InfoController.cs b/src/Identity/Controllers/InfoController.cs
index c06812cdf..05cf3f236 100644
--- a/src/Identity/Controllers/InfoController.cs
+++ b/src/Identity/Controllers/InfoController.cs
@@ -15,6 +15,6 @@ public class InfoController : Controller
[HttpGet("~/version")]
public JsonResult GetVersion()
{
- return Json(CoreHelpers.GetVersion());
+ return Json(AssemblyHelpers.GetVersion());
}
}
diff --git a/src/Notifications/Controllers/InfoController.cs b/src/Notifications/Controllers/InfoController.cs
index 6a8eaf282..afd6911a8 100644
--- a/src/Notifications/Controllers/InfoController.cs
+++ b/src/Notifications/Controllers/InfoController.cs
@@ -15,6 +15,6 @@ public class InfoController : Controller
[HttpGet("~/version")]
public JsonResult GetVersion()
{
- return Json(CoreHelpers.GetVersion());
+ return Json(AssemblyHelpers.GetVersion());
}
}
diff --git a/src/SharedWeb/Utilities/ServiceCollectionExtensions.cs b/src/SharedWeb/Utilities/ServiceCollectionExtensions.cs
index 7fab4b2ee..a9a88b4fe 100644
--- a/src/SharedWeb/Utilities/ServiceCollectionExtensions.cs
+++ b/src/SharedWeb/Utilities/ServiceCollectionExtensions.cs
@@ -511,7 +511,7 @@ public static class ServiceCollectionExtensions
{
httpContext.Response.OnStarting((state) =>
{
- httpContext.Response.Headers.Append("Server-Version", CoreHelpers.GetVersion());
+ httpContext.Response.Headers.Append("Server-Version", AssemblyHelpers.GetVersion());
return Task.FromResult(0);
}, null);
await next.Invoke();