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

98 lines
2.7 KiB
C#
Raw Normal View History

2023-09-13 08:03:11 +00:00
using FileUtils;
using KubernetesWorkflow;
using Logging;
namespace Core
{
public interface IPluginTools : IWorkflowTool, ILogTool, IHttpFactoryTool, IFileTool
{
ITimeSet TimeSet { get; }
/// <summary>
/// Deletes kubernetes and tracked file resources.
/// when `waitTillDone` is true, this function will block until resources are deleted.
/// </summary>
void Decommission(bool deleteKubernetesResources, bool deleteTrackedFiles, bool waitTillDone);
}
public interface IWorkflowTool
{
IStartupWorkflow CreateWorkflow(string? namespaceOverride = null);
}
public interface ILogTool
{
ILog GetLog();
}
public interface IHttpFactoryTool
{
2024-07-25 08:10:11 +00:00
IHttp CreateHttp(string id, Action<HttpClient> onClientCreated);
IHttp CreateHttp(string id, Action<HttpClient> onClientCreated, ITimeSet timeSet);
IHttp CreateHttp(string id);
}
public interface IFileTool
{
IFileManager GetFileManager();
}
internal class PluginTools : IPluginTools
2023-09-13 08:03:11 +00:00
{
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;
TimeSet = timeSet;
2023-09-13 08:03:11 +00:00
fileManager = new FileManager(log, fileManagerRootFolder);
}
public ITimeSet TimeSet { get; }
public void ApplyLogPrefix(string prefix)
{
2024-03-27 07:41:18 +00:00
log.Prefix = prefix;
}
2024-07-25 08:10:11 +00:00
public IHttp CreateHttp(string id, Action<HttpClient> onClientCreated)
2023-09-13 08:03:11 +00:00
{
2024-07-25 08:10:11 +00:00
return CreateHttp(id, onClientCreated, TimeSet);
}
2024-07-25 08:10:11 +00:00
public IHttp CreateHttp(string id, Action<HttpClient> onClientCreated, ITimeSet ts)
{
2024-07-25 08:10:11 +00:00
return new Http(id, log, ts, onClientCreated);
2023-09-13 08:03:11 +00:00
}
2024-07-25 08:10:11 +00:00
public IHttp CreateHttp(string id)
2023-09-13 08:03:11 +00:00
{
2024-07-25 08:10:11 +00:00
return new Http(id, log, TimeSet);
2023-09-13 08:03:11 +00:00
}
public IStartupWorkflow CreateWorkflow(string? namespaceOverride = null)
{
return workflowCreator.CreateWorkflow(namespaceOverride);
2023-09-13 08:03:11 +00:00
}
public void Decommission(bool deleteKubernetesResources, bool deleteTrackedFiles, bool waitTillDone)
2023-09-21 08:33:09 +00:00
{
if (deleteKubernetesResources) CreateWorkflow().DeleteNamespace(waitTillDone);
2023-09-21 08:33:09 +00:00
if (deleteTrackedFiles) fileManager.DeleteAllFiles();
}
2023-09-13 08:03:11 +00:00
public IFileManager GetFileManager()
{
return fileManager;
}
public ILog GetLog()
{
return log;
}
}
}