cs-codex-dist-tests/Framework/Core/PluginTools.cs

92 lines
2.8 KiB
C#
Raw Normal View History

2023-09-13 08:03:11 +00:00
using FileUtils;
using KubernetesWorkflow;
using Logging;
using Utils;
namespace Core
{
public interface IPluginTools : IWorkflowTool, ILogTool, IHttpFactoryTool, IFileTool
{
2023-09-21 08:33:09 +00:00
void Decommission(bool deleteKubernetesResources, bool deleteTrackedFiles);
}
public interface IWorkflowTool
{
IStartupWorkflow CreateWorkflow(string? namespaceOverride = null);
}
public interface ILogTool
{
ILog GetLog();
}
public interface IHttpFactoryTool
{
2023-09-14 13:40:15 +00:00
IHttp CreateHttp(Address address, string baseUrl, Action<HttpClient> onClientCreated, string? logAlias = null);
IHttp CreateHttp(Address address, string baseUrl, Action<HttpClient> onClientCreated, ITimeSet timeSet, string? logAlias = null);
2023-09-14 13:40:15 +00:00
IHttp CreateHttp(Address address, string baseUrl, string? logAlias = null);
}
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;
private ILog 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
{
this.log = 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);
}
public void ApplyLogPrefix(string prefix)
{
log = new LogPrefixer(log, prefix);
}
2023-09-14 13:40:15 +00:00
public IHttp CreateHttp(Address address, string baseUrl, Action<HttpClient> onClientCreated, string? logAlias = null)
2023-09-13 08:03:11 +00:00
{
return CreateHttp(address, baseUrl, onClientCreated, timeSet, logAlias);
}
public IHttp CreateHttp(Address address, string baseUrl, Action<HttpClient> onClientCreated, ITimeSet ts, string? logAlias = null)
{
return new Http(log, ts, address, baseUrl, onClientCreated, logAlias);
2023-09-13 08:03:11 +00:00
}
2023-09-14 13:40:15 +00:00
public IHttp CreateHttp(Address address, string baseUrl, string? logAlias = null)
2023-09-13 08:03:11 +00:00
{
return new Http(log, timeSet, address, baseUrl, logAlias);
}
public IStartupWorkflow CreateWorkflow(string? namespaceOverride = null)
{
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;
}
}
}