From d98186e1ebecdd1b60749e57568fc92deee32bfe Mon Sep 17 00:00:00 2001 From: Kenneth Skovhede Date: Mon, 4 Nov 2024 13:20:23 +0100 Subject: [PATCH] Implemented secret provider on the remoteoperation and webmodules calls --- .../WebserverCore/Endpoints/V1/RemoteOperation.cs | 15 +++++++++++---- .../WebserverCore/Endpoints/V1/WebModules.cs | 13 +++++++++++-- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/Duplicati/WebserverCore/Endpoints/V1/RemoteOperation.cs b/Duplicati/WebserverCore/Endpoints/V1/RemoteOperation.cs index 1bb91439d..c422f6ec4 100644 --- a/Duplicati/WebserverCore/Endpoints/V1/RemoteOperation.cs +++ b/Duplicati/WebserverCore/Endpoints/V1/RemoteOperation.cs @@ -1,4 +1,6 @@ using Duplicati.Library.Interface; +using Duplicati.Library.Main; +using Duplicati.Library.RestAPI; using Duplicati.Server; using Duplicati.WebserverCore.Abstractions; using Duplicati.WebserverCore.Exceptions; @@ -31,7 +33,7 @@ namespace Duplicati.WebserverCore.Endpoints.V1 return new Dto.GetDbPathDto(!string.IsNullOrWhiteSpace(path), path); } - private static Dictionary ParseUrlOptions(Library.Utility.Uri uri) + private static Dictionary ParseUrlOptions(Library.Utility.Uri uri) { var qp = uri.QueryParameters; @@ -42,7 +44,7 @@ namespace Duplicati.WebserverCore.Endpoints.V1 return opts; } - private static IEnumerable ConfigureModules(IDictionary opts) + private static IEnumerable ConfigureModules(IDictionary opts) { // TODO: This works because the generic modules are implemented // with pre .NetCore logic, using static methods @@ -65,10 +67,15 @@ namespace Duplicati.WebserverCore.Endpoints.V1 } } - private static TupleDisposeWrapper GetBackend(string url) + private static async Task GetBackend(string url, CancellationToken cancelToken) { var uri = new Library.Utility.Uri(url); var opts = ParseUrlOptions(uri); + + var tmp = new[] { url }; + await SecretProviderHelper.ApplySecretProviderAsync(tmp, opts, Library.Utility.TempFolder.SystemTempPath, FIXMEGlobal.SecretProvider, cancelToken); + url = tmp[0]; + var modules = ConfigureModules(opts); var backend = Library.DynamicLoader.BackendLoader.GetBackend(url, new Dictionary()); return new TupleDisposeWrapper(backend, modules); @@ -80,7 +87,7 @@ namespace Duplicati.WebserverCore.Endpoints.V1 try { - wrapper = GetBackend(url); + wrapper = await GetBackend(url, cancelToken); using (var b = wrapper.Backend) { diff --git a/Duplicati/WebserverCore/Endpoints/V1/WebModules.cs b/Duplicati/WebserverCore/Endpoints/V1/WebModules.cs index e91788289..d306163c4 100644 --- a/Duplicati/WebserverCore/Endpoints/V1/WebModules.cs +++ b/Duplicati/WebserverCore/Endpoints/V1/WebModules.cs @@ -1,4 +1,7 @@ using Duplicati.Library.Interface; +using Duplicati.Library.Main; +using Duplicati.Library.RestAPI; +using Duplicati.Server; using Duplicati.WebserverCore.Abstractions; using Duplicati.WebserverCore.Exceptions; using Microsoft.AspNetCore.Mvc; @@ -10,17 +13,23 @@ public record WebModules : IEndpointV1 public static void Map(RouteGroupBuilder group) { group.MapGet("/webmodules", ExecuteGet).RequireAuthorization(); - group.MapPost("/webmodule/{modulekey}", ([FromRoute] string modulekey, [FromBody] Dictionary options) => ExecutePost(modulekey, options)).RequireAuthorization(); + group.MapPost("/webmodule/{modulekey}", ([FromRoute] string modulekey, [FromBody] Dictionary options, CancellationToken cancellationToken) => ExecutePost(modulekey, options, cancellationToken)).RequireAuthorization(); } private static IEnumerable ExecuteGet() => Library.DynamicLoader.WebLoader.Modules; - private static Dto.WebModuleOutputDto ExecutePost(string modulekey, Dictionary options) + private static async Task ExecutePost(string modulekey, Dictionary inputOptions, CancellationToken cancellationToken) { var m = Library.DynamicLoader.WebLoader.Modules.FirstOrDefault(x => x.Key.Equals(modulekey, StringComparison.OrdinalIgnoreCase)) ?? throw new NotFoundException("No such module found"); + var options = Runner.GetCommonOptions(); + foreach (var k in inputOptions.Keys) + options[k] = inputOptions[k]; + + await SecretProviderHelper.ApplySecretProviderAsync([], options, Library.Utility.TempFolder.SystemTempPath, FIXMEGlobal.SecretProvider, cancellationToken); + return new Dto.WebModuleOutputDto( Status: "OK", Result: m.Execute(options)