2023-09-13 08:03:11 +00:00
|
|
|
|
using FileUtils;
|
|
|
|
|
using KubernetesWorkflow;
|
|
|
|
|
using Logging;
|
|
|
|
|
|
|
|
|
|
namespace Core
|
|
|
|
|
{
|
2023-09-13 08:23:05 +00:00
|
|
|
|
public interface IPluginTools : IWorkflowTool, ILogTool, IHttpFactoryTool, IFileTool
|
|
|
|
|
{
|
2023-09-21 08:33:09 +00:00
|
|
|
|
void Decommission(bool deleteKubernetesResources, bool deleteTrackedFiles);
|
2023-09-13 08:23:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public interface IWorkflowTool
|
|
|
|
|
{
|
|
|
|
|
IStartupWorkflow CreateWorkflow(string? namespaceOverride = null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public interface ILogTool
|
|
|
|
|
{
|
|
|
|
|
ILog GetLog();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public interface IHttpFactoryTool
|
|
|
|
|
{
|
2024-03-26 09:03:52 +00:00
|
|
|
|
IHttp CreateHttp(Action<HttpClient> onClientCreated);
|
|
|
|
|
IHttp CreateHttp(Action<HttpClient> onClientCreated, ITimeSet timeSet);
|
|
|
|
|
IHttp CreateHttp();
|
2023-09-13 08:23:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public interface IFileTool
|
|
|
|
|
{
|
|
|
|
|
IFileManager GetFileManager();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal class PluginTools : IPluginTools
|
2023-09-13 08:03:11 +00:00
|
|
|
|
{
|
|
|
|
|
private readonly ITimeSet timeSet;
|
|
|
|
|
private readonly WorkflowCreator workflowCreator;
|
|
|
|
|
private readonly IFileManager fileManager;
|
2024-03-27 07:41:18 +00:00
|
|
|
|
private readonly LogPrefixer log;
|
2023-09-13 08:03:11 +00:00
|
|
|
|
|
2023-09-14 13:40:15 +00:00
|
|
|
|
internal PluginTools(ILog log, WorkflowCreator workflowCreator, string fileManagerRootFolder, ITimeSet timeSet)
|
2023-09-13 08:03:11 +00:00
|
|
|
|
{
|
2024-03-27 07:41:18 +00:00
|
|
|
|
this.log = new LogPrefixer(log);
|
2023-09-13 09:59:21 +00:00
|
|
|
|
this.workflowCreator = workflowCreator;
|
2023-09-13 08:03:11 +00:00
|
|
|
|
this.timeSet = timeSet;
|
|
|
|
|
fileManager = new FileManager(log, fileManagerRootFolder);
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-13 08:23:05 +00:00
|
|
|
|
public void ApplyLogPrefix(string prefix)
|
|
|
|
|
{
|
2024-03-27 07:41:18 +00:00
|
|
|
|
log.Prefix = prefix;
|
2023-09-13 08:23:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-03-26 09:03:52 +00:00
|
|
|
|
public IHttp CreateHttp(Action<HttpClient> onClientCreated)
|
2023-09-13 08:03:11 +00:00
|
|
|
|
{
|
2024-03-26 09:03:52 +00:00
|
|
|
|
return CreateHttp(onClientCreated, timeSet);
|
2023-10-10 16:08:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-03-26 09:03:52 +00:00
|
|
|
|
public IHttp CreateHttp(Action<HttpClient> onClientCreated, ITimeSet ts)
|
2023-10-10 16:08:21 +00:00
|
|
|
|
{
|
2024-03-26 09:03:52 +00:00
|
|
|
|
return new Http(log, ts, onClientCreated);
|
2023-09-13 08:03:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-03-26 09:03:52 +00:00
|
|
|
|
public IHttp CreateHttp()
|
2023-09-13 08:03:11 +00:00
|
|
|
|
{
|
2024-03-26 09:03:52 +00:00
|
|
|
|
return new Http(log, timeSet);
|
2023-09-13 08:03:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IStartupWorkflow CreateWorkflow(string? namespaceOverride = null)
|
|
|
|
|
{
|
2023-09-13 12:37:53 +00:00
|
|
|
|
return workflowCreator.CreateWorkflow(namespaceOverride);
|
2023-09-13 08:03:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-09-21 08:33:09 +00:00
|
|
|
|
public void Decommission(bool deleteKubernetesResources, bool deleteTrackedFiles)
|
|
|
|
|
{
|
|
|
|
|
if (deleteKubernetesResources) CreateWorkflow().DeleteNamespace();
|
|
|
|
|
if (deleteTrackedFiles) fileManager.DeleteAllFiles();
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-13 08:03:11 +00:00
|
|
|
|
public IFileManager GetFileManager()
|
|
|
|
|
{
|
|
|
|
|
return fileManager;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ILog GetLog()
|
|
|
|
|
{
|
|
|
|
|
return log;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|