Skip to content

Commit 2ad254f

Browse files
Fix delete managed item per instance
1 parent 3efe940 commit 2ad254f

File tree

5 files changed

+16
-18
lines changed

5 files changed

+16
-18
lines changed

src/Certify.Core/Management/CertifyManager/CertifyManager.ManagedCertificates.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using Certify.Models.Providers;
1010
using Certify.Models.Reporting;
1111
using Certify.Models.Shared;
12+
using Certify.Models.Config;
1213

1314
namespace Certify.Management
1415
{
@@ -337,16 +338,19 @@ private async Task SendQueuedStatusReports()
337338
/// </summary>
338339
/// <param name="id"></param>
339340
/// <returns></returns>
340-
public async Task DeleteManagedCertificate(string id)
341+
public async Task<ActionResult> DeleteManagedCertificate(string id)
341342
{
342343
if (!string.IsNullOrEmpty(id))
343344
{
344345
var item = await _itemManager.GetById(id);
345346
if (item != null)
346347
{
347348
await _itemManager.Delete(item);
349+
return new ActionResult { IsSuccess = true, Message = "Deleted" };
348350
}
349351
}
352+
353+
return new ActionResult { IsSuccess = false, Message = "Delete failed." };
350354
}
351355

352356
/// <summary>

src/Certify.Core/Management/CertifyManager/ICertifyManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public interface ICertifyManager
3333

3434
Task<ManagedCertificate> UpdateManagedCertificate(ManagedCertificate site);
3535

36-
Task DeleteManagedCertificate(string id);
36+
Task<ActionResult> DeleteManagedCertificate(string id);
3737

3838
Task<ImportExportPackage> PerformExport(ExportRequest exportRequest);
3939
Task<List<ActionStep>> PerformImport(ImportRequest importRequest);

src/Certify.Server/Certify.Server.Api.Public.Client/Certify.API.Public.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2064,7 +2064,7 @@ public virtual async System.Threading.Tasks.Task<ManagedCertificate> PerformRene
20642064
/// </summary>
20652065
/// <returns>OK</returns>
20662066
/// <exception cref="ApiException">A server side error occurred.</exception>
2067-
public virtual System.Threading.Tasks.Task<bool> RemoveManagedCertificateAsync(string instanceId, string managedCertId)
2067+
public virtual System.Threading.Tasks.Task<ActionResult> RemoveManagedCertificateAsync(string instanceId, string managedCertId)
20682068
{
20692069
return RemoveManagedCertificateAsync(instanceId, managedCertId, System.Threading.CancellationToken.None);
20702070
}
@@ -2075,7 +2075,7 @@ public virtual System.Threading.Tasks.Task<bool> RemoveManagedCertificateAsync(s
20752075
/// </summary>
20762076
/// <returns>OK</returns>
20772077
/// <exception cref="ApiException">A server side error occurred.</exception>
2078-
public virtual async System.Threading.Tasks.Task<bool> RemoveManagedCertificateAsync(string instanceId, string managedCertId, System.Threading.CancellationToken cancellationToken)
2078+
public virtual async System.Threading.Tasks.Task<ActionResult> RemoveManagedCertificateAsync(string instanceId, string managedCertId, System.Threading.CancellationToken cancellationToken)
20792079
{
20802080
if (instanceId == null)
20812081
throw new System.ArgumentNullException("instanceId");
@@ -2125,7 +2125,7 @@ public virtual async System.Threading.Tasks.Task<bool> RemoveManagedCertificateA
21252125
var status_ = (int)response_.StatusCode;
21262126
if (status_ == 200)
21272127
{
2128-
var objectResponse_ = await ReadObjectResponseAsync<bool>(response_, headers_, cancellationToken).ConfigureAwait(false);
2128+
var objectResponse_ = await ReadObjectResponseAsync<ActionResult>(response_, headers_, cancellationToken).ConfigureAwait(false);
21292129
if (objectResponse_.Object == null)
21302130
{
21312131
throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null);

src/Certify.Server/Certify.Server.Api.Public/Services/ManagementAPI.cs

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ private async Task SendCommandWithNoResult(string instanceId, InstanceCommandReq
130130
/// <param name="managedCertId"></param>
131131
/// <param name="authContext"></param>
132132
/// <returns></returns>
133-
public async Task<bool> RemoveManagedCertificate(string instanceId, string managedCertId, AuthContext authContext)
133+
public async Task<ActionResult> RemoveManagedCertificate(string instanceId, string managedCertId, AuthContext authContext)
134134
{
135135
// delete managed cert via management hub
136136

@@ -139,20 +139,14 @@ public async Task<bool> RemoveManagedCertificate(string instanceId, string manag
139139
new("managedCertId",managedCertId)
140140
};
141141

142-
var deletedOK = await PerformInstanceCommandTaskWithResult<bool>(instanceId, args, ManagementHubCommands.RemoveDeleteManagedItem);
142+
var result = await PerformInstanceCommandTaskWithResult<ActionResult>(instanceId, args, ManagementHubCommands.RemoveManagedItem);
143143

144-
if (deletedOK)
144+
if (result.IsSuccess)
145145
{
146-
try
147-
{
148-
_mgmtStateProvider.DeleteCachedManagedInstanceItem(instanceId, managedCertId);
149-
}
150-
catch
151-
{
152-
}
146+
_mgmtStateProvider.DeleteCachedManagedInstanceItem(instanceId, managedCertId);
153147
}
154148

155-
return deletedOK;
149+
return result;
156150
}
157151

158152
public async Task<StatusSummary> GetManagedCertificateSummary(AuthContext? currentAuthContext)

src/Certify.SourceGenerators/ApiMethods.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ public static List<GeneratedAPI> GetApiDefinitions()
176176
Comment = "Delete a managed challenge (DNS challenge delegation etc)",
177177
PublicAPIController = "ManagedChallenge",
178178
PublicAPIRoute = "remove",
179-
ServiceAPIRoute = "managedchallenge",
179+
ServiceAPIRoute = "managedchallenge/{id}",
180180
ReturnType = "Models.Config.ActionResult",
181181
Params = new Dictionary<string, string>{
182182
{ "id", "string" }
@@ -356,7 +356,7 @@ public static List<GeneratedAPI> GetApiDefinitions()
356356
UseManagementAPI = true,
357357
PublicAPIController = "Certificate",
358358
PublicAPIRoute = "{instanceId}/settings/{managedCertId}",
359-
ReturnType = "bool",
359+
ReturnType = "Models.Config.ActionResult",
360360
Params =new Dictionary<string, string>{ { "instanceId", "string" },{ "managedCertId", "string" } }
361361
},
362362
// TODO

0 commit comments

Comments
 (0)