2024-07-26 06:39:27 +00:00
|
|
|
|
using CodexPlugin.Hooks;
|
|
|
|
|
using Core;
|
2023-09-19 09:51:59 +00:00
|
|
|
|
using GethPlugin;
|
2023-09-20 10:55:09 +00:00
|
|
|
|
using KubernetesWorkflow;
|
2023-11-12 09:07:23 +00:00
|
|
|
|
using KubernetesWorkflow.Types;
|
2023-09-12 09:43:46 +00:00
|
|
|
|
|
2023-09-11 09:59:33 +00:00
|
|
|
|
namespace CodexPlugin
|
|
|
|
|
{
|
|
|
|
|
public interface ICodexNodeFactory
|
|
|
|
|
{
|
2023-09-19 09:51:59 +00:00
|
|
|
|
CodexNode CreateOnlineCodexNode(CodexAccess access, CodexNodeGroup group);
|
2023-09-20 10:55:09 +00:00
|
|
|
|
CrashWatcher CreateCrashWatcher(RunningContainer c);
|
2023-09-11 09:59:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class CodexNodeFactory : ICodexNodeFactory
|
|
|
|
|
{
|
2023-09-12 09:43:46 +00:00
|
|
|
|
private readonly IPluginTools tools;
|
2024-07-26 06:39:27 +00:00
|
|
|
|
private readonly CodexHooksFactory codexHooksFactory;
|
2023-09-12 09:43:46 +00:00
|
|
|
|
|
2024-07-26 06:39:27 +00:00
|
|
|
|
public CodexNodeFactory(IPluginTools tools, CodexHooksFactory codexHooksFactory)
|
2023-09-12 09:43:46 +00:00
|
|
|
|
{
|
|
|
|
|
this.tools = tools;
|
2024-07-26 06:39:27 +00:00
|
|
|
|
this.codexHooksFactory = codexHooksFactory;
|
2023-09-12 09:43:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-09-19 09:51:59 +00:00
|
|
|
|
public CodexNode CreateOnlineCodexNode(CodexAccess access, CodexNodeGroup group)
|
2023-09-11 14:57:57 +00:00
|
|
|
|
{
|
2024-05-24 13:34:42 +00:00
|
|
|
|
var ethAccount = GetEthAccount(access);
|
2024-07-26 06:39:27 +00:00
|
|
|
|
var hooks = codexHooksFactory.CreateHooks(access.Container.Name);
|
2024-08-20 10:13:42 +00:00
|
|
|
|
|
|
|
|
|
var marketplaceAccess = GetMarketplaceAccess(access, ethAccount, hooks);
|
2024-07-26 06:39:27 +00:00
|
|
|
|
return new CodexNode(tools, access, group, marketplaceAccess, hooks, ethAccount);
|
2023-09-20 06:45:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-08-20 10:13:42 +00:00
|
|
|
|
private IMarketplaceAccess GetMarketplaceAccess(CodexAccess codexAccess, EthAccount? ethAccount, ICodexNodeHooks hooks)
|
2023-09-20 06:45:55 +00:00
|
|
|
|
{
|
2024-05-24 13:34:42 +00:00
|
|
|
|
if (ethAccount == null) return new MarketplaceUnavailable();
|
2024-08-20 10:13:42 +00:00
|
|
|
|
return new MarketplaceAccess(tools.GetLog(), codexAccess, hooks);
|
2023-09-19 09:51:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-05-24 13:34:42 +00:00
|
|
|
|
private EthAccount? GetEthAccount(CodexAccess access)
|
2023-09-19 09:51:59 +00:00
|
|
|
|
{
|
2024-04-13 14:09:17 +00:00
|
|
|
|
var ethAccount = access.Container.Containers.Single().Recipe.Additionals.Get<EthAccount>();
|
2024-03-26 14:35:26 +00:00
|
|
|
|
if (ethAccount == null) return null;
|
2024-05-24 13:34:42 +00:00
|
|
|
|
return ethAccount;
|
2023-09-11 14:57:57 +00:00
|
|
|
|
}
|
2023-09-20 10:55:09 +00:00
|
|
|
|
|
|
|
|
|
public CrashWatcher CreateCrashWatcher(RunningContainer c)
|
|
|
|
|
{
|
|
|
|
|
return tools.CreateWorkflow().CreateCrashWatcher(c);
|
|
|
|
|
}
|
2023-09-11 09:59:33 +00:00
|
|
|
|
}
|
|
|
|
|
}
|