Implemented secret provider on the remoteoperation and webmodules calls
This commit is contained in:
@@ -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<string, string> ParseUrlOptions(Library.Utility.Uri uri)
|
||||
private static Dictionary<string, string?> ParseUrlOptions(Library.Utility.Uri uri)
|
||||
{
|
||||
var qp = uri.QueryParameters;
|
||||
|
||||
@@ -42,7 +44,7 @@ namespace Duplicati.WebserverCore.Endpoints.V1
|
||||
return opts;
|
||||
}
|
||||
|
||||
private static IEnumerable<IGenericModule> ConfigureModules(IDictionary<string, string> opts)
|
||||
private static IEnumerable<IGenericModule> ConfigureModules(IDictionary<string, string?> 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<TupleDisposeWrapper> 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<string, string>());
|
||||
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)
|
||||
{
|
||||
|
||||
@@ -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<string, string> options) => ExecutePost(modulekey, options)).RequireAuthorization();
|
||||
group.MapPost("/webmodule/{modulekey}", ([FromRoute] string modulekey, [FromBody] Dictionary<string, string> options, CancellationToken cancellationToken) => ExecutePost(modulekey, options, cancellationToken)).RequireAuthorization();
|
||||
}
|
||||
|
||||
private static IEnumerable<IWebModule> ExecuteGet()
|
||||
=> Library.DynamicLoader.WebLoader.Modules;
|
||||
|
||||
private static Dto.WebModuleOutputDto ExecutePost(string modulekey, Dictionary<string, string> options)
|
||||
private static async Task<Dto.WebModuleOutputDto> ExecutePost(string modulekey, Dictionary<string, string> 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)
|
||||
|
||||
Reference in New Issue
Block a user