From 795034cd9dd85fed00ffde9c8262a9470fc23241 Mon Sep 17 00:00:00 2001 From: Oscar Hinton Date: Tue, 15 Aug 2023 15:10:56 +0200 Subject: [PATCH] [PM-3430] Refactor organization public key response (#3195) --- .../Controllers/OrganizationsController.cs | 13 ++++++++++--- .../OrganizationPublicKeyResponseModel.cs | 19 +++++++++++++++++++ 2 files changed, 29 insertions(+), 3 deletions(-) create mode 100644 src/Api/Models/Response/Organizations/OrganizationPublicKeyResponseModel.cs diff --git a/src/Api/Controllers/OrganizationsController.cs b/src/Api/Controllers/OrganizationsController.cs index 1d0e9d1487..e1301e3f25 100644 --- a/src/Api/Controllers/OrganizationsController.cs +++ b/src/Api/Controllers/OrganizationsController.cs @@ -682,8 +682,8 @@ public class OrganizationsController : Controller await _paymentService.SaveTaxInfoAsync(organization, taxInfo); } - [HttpGet("{id}/keys")] - public async Task GetKeys(string id) + [HttpGet("{id}/public-key")] + public async Task GetPublicKey(string id) { var org = await _organizationRepository.GetByIdAsync(new Guid(id)); if (org == null) @@ -691,7 +691,14 @@ public class OrganizationsController : Controller throw new NotFoundException(); } - return new OrganizationKeysResponseModel(org); + return new OrganizationPublicKeyResponseModel(org); + } + + [Obsolete("TDL-136 Renamed to public-key (2023.8), left for backwards compatability with older clients.")] + [HttpGet("{id}/keys")] + public async Task GetKeys(string id) + { + return await GetPublicKey(id); } [HttpPost("{id}/keys")] diff --git a/src/Api/Models/Response/Organizations/OrganizationPublicKeyResponseModel.cs b/src/Api/Models/Response/Organizations/OrganizationPublicKeyResponseModel.cs new file mode 100644 index 0000000000..0451433e1b --- /dev/null +++ b/src/Api/Models/Response/Organizations/OrganizationPublicKeyResponseModel.cs @@ -0,0 +1,19 @@ +using Bit.Core.Entities; +using Bit.Core.Models.Api; + +namespace Bit.Api.Models.Response.Organizations; + +public class OrganizationPublicKeyResponseModel : ResponseModel +{ + public OrganizationPublicKeyResponseModel(Organization org) : base("organizationPublicKey") + { + if (org == null) + { + throw new ArgumentNullException(nameof(org)); + } + + PublicKey = org.PublicKey; + } + + public string PublicKey { get; set; } +}