diff --git a/src/Api/Controllers/InstallationsController.cs b/src/Api/Controllers/InstallationsController.cs index c4ee72f095..d9669b67df 100644 --- a/src/Api/Controllers/InstallationsController.cs +++ b/src/Api/Controllers/InstallationsController.cs @@ -5,6 +5,7 @@ using Bit.Core.Repositories; using Bit.Core.Models.Api; using Bit.Api.Utilities; using Microsoft.AspNetCore.Authorization; +using Bit.Core.Exceptions; namespace Bit.Api.Controllers { @@ -20,13 +21,26 @@ namespace Bit.Api.Controllers _installationRepository = installationRepository; } + [HttpPost("{id}")] + [AllowAnonymous] + public async Task Get(Guid id) + { + var installation = await _installationRepository.GetByIdAsync(id); + if(installation == null) + { + throw new NotFoundException(); + } + + return new InstallationResponseModel(installation, false); + } + [HttpPost("")] [AllowAnonymous] public async Task Post([FromBody] InstallationRequestModel model) { var installation = model.ToInstallation(); await _installationRepository.CreateAsync(installation); - return new InstallationResponseModel(installation); + return new InstallationResponseModel(installation, true); } } } diff --git a/src/Core/Models/Api/Response/InstallationResponseModel.cs b/src/Core/Models/Api/Response/InstallationResponseModel.cs index 9db1567c72..efddcd7fae 100644 --- a/src/Core/Models/Api/Response/InstallationResponseModel.cs +++ b/src/Core/Models/Api/Response/InstallationResponseModel.cs @@ -5,14 +5,16 @@ namespace Bit.Core.Models.Api { public class InstallationResponseModel : ResponseModel { - public InstallationResponseModel(Installation installation) + public InstallationResponseModel(Installation installation, bool withKey) : base("installation") { Id = installation.Id.ToString(); - Key = installation.Key; + Key = withKey ? installation.Key : null; + Enabled = installation.Enabled; } public string Id { get; set; } public string Key { get; set; } + public bool Enabled { get; set; } } }