1
0
mirror of https://github.com/bitwarden/server synced 2026-01-05 18:13:31 +00:00

Add Additional Logging to Self-hosted installs for F4E (#1999)

* Add logging to SH logs

* Fix tests
This commit is contained in:
Justin Baur
2022-05-16 09:57:00 -04:00
committed by GitHub
parent 6b484e29a7
commit 53241f16e0
5 changed files with 56 additions and 7 deletions

View File

@@ -14,6 +14,7 @@ using Bit.Core.Settings;
using Bit.Core.Utilities;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
namespace Bit.Admin.Controllers
{
@@ -34,6 +35,7 @@ namespace Bit.Admin.Controllers
private readonly GlobalSettings _globalSettings;
private readonly IReferenceEventService _referenceEventService;
private readonly IUserService _userService;
private readonly ILogger<OrganizationsController> _logger;
public OrganizationsController(
IOrganizationRepository organizationRepository,
@@ -49,7 +51,8 @@ namespace Bit.Admin.Controllers
IApplicationCacheService applicationCacheService,
GlobalSettings globalSettings,
IReferenceEventService referenceEventService,
IUserService userService)
IUserService userService,
ILogger<OrganizationsController> logger)
{
_organizationRepository = organizationRepository;
_organizationUserRepository = organizationUserRepository;
@@ -65,6 +68,7 @@ namespace Bit.Admin.Controllers
_globalSettings = globalSettings;
_referenceEventService = referenceEventService;
_userService = userService;
_logger = logger;
}
public async Task<IActionResult> Index(string name = null, string userEmail = null, bool? paid = null,
@@ -199,6 +203,7 @@ namespace Bit.Admin.Controllers
catch (Exception ex)
{
TempData["ConnectionError"] = ex.Message;
_logger.LogWarning(ex, "Error while attempting to do billing sync for organization with id '{OrganizationId}'", id);
}
if (_globalSettings.SelfHosted)

View File

@@ -74,6 +74,10 @@ namespace Bit.Api.Controllers
case OrganizationConnectionType.CloudBillingSync:
var typedModel = new OrganizationConnectionRequestModel<BillingSyncConfig>(model);
var license = await _licensingService.ReadOrganizationLicenseAsync(model.OrganizationId);
if (!_licensingService.VerifyLicense(license))
{
throw new BadRequestException("Cannot verify license file.");
}
typedModel.ParsedConfig.CloudOrganizationId = license.Id;
var connection = await _createOrganizationConnectionCommand.CreateAsync(typedModel.ToData());
return new OrganizationConnectionResponseModel(connection, typeof(BillingSyncConfig));

View File

@@ -87,6 +87,7 @@ namespace Bit.Core.OrganizationFeatures.OrganizationSponsorships.FamiliesForEnte
if (response == null)
{
_logger.LogDebug("Organization sync failed for '{OrgId}'", organizationId);
throw new BadRequestException("Organization sync failed");
}

View File

@@ -124,11 +124,19 @@ namespace Bit.Core.Services
if (!response.IsSuccessStatusCode)
{
_logger.LogInformation("Unsuccessful token response with status code {StatusCode}", response.StatusCode);
if (response.StatusCode == HttpStatusCode.BadRequest)
{
_nextAuthAttempt = DateTime.UtcNow.AddDays(1);
}
if (_logger.IsEnabled(LogLevel.Debug))
{
var responseBody = await response.Content.ReadAsStringAsync();
_logger.LogDebug("Error response body:\n{ResponseBody}", responseBody);
}
return false;
}