mirror of
https://github.com/codex-storage/cs-codex-dist-tests.git
synced 2025-02-02 23:33:45 +00:00
Automatic updating of CodexPlugin openapi.yaml.
This commit is contained in:
parent
9ca4bf8afc
commit
960b0c3788
41
Framework/Utils/PluginPathUtils.cs
Normal file
41
Framework/Utils/PluginPathUtils.cs
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
namespace Utils
|
||||||
|
{
|
||||||
|
public static class PluginPathUtils
|
||||||
|
{
|
||||||
|
private const string ProjectPluginsFolderName = "ProjectPlugins";
|
||||||
|
private static string projectPluginsDir = string.Empty;
|
||||||
|
|
||||||
|
public static string ProjectPluginsDir
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(projectPluginsDir)) projectPluginsDir = FindProjectPluginsDir();
|
||||||
|
return projectPluginsDir;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static string FindProjectPluginsDir()
|
||||||
|
{
|
||||||
|
var current = Directory.GetCurrentDirectory();
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
var localFolders = Directory.GetDirectories(current);
|
||||||
|
var projectPluginsFolders = localFolders.Where(l => l.EndsWith(ProjectPluginsFolderName)).ToArray();
|
||||||
|
if (projectPluginsFolders.Length == 1)
|
||||||
|
{
|
||||||
|
return projectPluginsFolders.Single();
|
||||||
|
}
|
||||||
|
|
||||||
|
var parent = Directory.GetParent(current);
|
||||||
|
if (parent == null)
|
||||||
|
{
|
||||||
|
var msg = $"Unable to locate '{ProjectPluginsFolderName}' folder. Travelled up from: '{Directory.GetCurrentDirectory()}'";
|
||||||
|
Console.WriteLine(msg);
|
||||||
|
throw new Exception(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
current = parent.FullName;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,4 +1,6 @@
|
|||||||
namespace CodexContractsPlugin
|
using Utils;
|
||||||
|
|
||||||
|
namespace CodexContractsPlugin
|
||||||
{
|
{
|
||||||
public class SelfUpdater
|
public class SelfUpdater
|
||||||
{
|
{
|
||||||
@ -41,24 +43,10 @@
|
|||||||
|
|
||||||
private string GetMarketplaceFilePath()
|
private string GetMarketplaceFilePath()
|
||||||
{
|
{
|
||||||
var here = Directory.GetCurrentDirectory();
|
var projectPluginDir = PluginPathUtils.ProjectPluginsDir;
|
||||||
while (true)
|
var path = Path.Combine(projectPluginDir, "CodexContractsPlugin", "Marketplace", "Marketplace.cs");
|
||||||
{
|
if (!File.Exists(path)) throw new Exception("Marketplace file not found. Expected: " + path);
|
||||||
var path = GetMarketplaceFile(here);
|
return path;
|
||||||
if (path != null) return path;
|
|
||||||
|
|
||||||
var parent = Directory.GetParent(here);
|
|
||||||
var up = parent?.FullName;
|
|
||||||
if (up == null || up == here) throw new Exception("Unable to locate ProjectPlugins folder. Unable to update contracts.");
|
|
||||||
here = up;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private string? GetMarketplaceFile(string root)
|
|
||||||
{
|
|
||||||
var path = Path.Combine(root, "ProjectPlugins", "CodexContractsPlugin", "Marketplace", "Marketplace.cs");
|
|
||||||
if (File.Exists(path)) return path;
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private string GenerateContent(string abi, string bytecode)
|
private string GenerateContent(string abi, string bytecode)
|
||||||
|
@ -3,13 +3,14 @@ using KubernetesWorkflow.Types;
|
|||||||
using Logging;
|
using Logging;
|
||||||
using System.Security.Cryptography;
|
using System.Security.Cryptography;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using Utils;
|
||||||
|
|
||||||
namespace CodexPlugin
|
namespace CodexPlugin
|
||||||
{
|
{
|
||||||
public class ApiChecker
|
public class ApiChecker
|
||||||
{
|
{
|
||||||
// <INSERT-OPENAPI-YAML-HASH>
|
// <INSERT-OPENAPI-YAML-HASH>
|
||||||
private const string OpenApiYamlHash = "6B-94-24-A4-D5-01-6F-12-E9-34-74-36-80-57-7A-3A-79-8C-E8-02-68-B7-05-DA-50-A0-5C-B1-02-B9-AE-C6";
|
private const string OpenApiYamlHash = "8B-C5-3F-BF-E6-6C-6A-4F-1C-70-29-19-46-AA-E6-71-DC-56-0A-A0-BC-73-A5-11-9E-66-CE-09-1E-86-20-FC";
|
||||||
private const string OpenApiFilePath = "/codex/openapi.yaml";
|
private const string OpenApiFilePath = "/codex/openapi.yaml";
|
||||||
private const string DisableEnvironmentVariable = "CODEXPLUGIN_DISABLE_APICHECK";
|
private const string DisableEnvironmentVariable = "CODEXPLUGIN_DISABLE_APICHECK";
|
||||||
|
|
||||||
@ -21,8 +22,9 @@ namespace CodexPlugin
|
|||||||
|
|
||||||
private const string Failure =
|
private const string Failure =
|
||||||
"Codex API compatibility check failed! " +
|
"Codex API compatibility check failed! " +
|
||||||
"openapi.yaml used by CodexPlugin does not match openapi.yaml in Codex container. Please update the openapi.yaml in " +
|
"openapi.yaml used by CodexPlugin does not match openapi.yaml in Codex container. The openapi.yaml in " +
|
||||||
"'ProjectPlugins/CodexPlugin' and rebuild this project. If you wish to disable API compatibility checking, please set " +
|
"'ProjectPlugins/CodexPlugin' has been overwritten with the container one. " +
|
||||||
|
"Please and rebuild this project. If you wish to disable API compatibility checking, please set " +
|
||||||
$"the environment variable '{DisableEnvironmentVariable}' or set the disable bool in 'ProjectPlugins/CodexPlugin/ApiChecker.cs'.";
|
$"the environment variable '{DisableEnvironmentVariable}' or set the disable bool in 'ProjectPlugins/CodexPlugin/ApiChecker.cs'.";
|
||||||
|
|
||||||
private static bool checkPassed = false;
|
private static bool checkPassed = false;
|
||||||
@ -71,10 +73,23 @@ namespace CodexPlugin
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
OverwriteOpenApiYaml(containerApi);
|
||||||
|
|
||||||
log.Error(Failure);
|
log.Error(Failure);
|
||||||
throw new Exception(Failure);
|
throw new Exception(Failure);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void OverwriteOpenApiYaml(string containerApi)
|
||||||
|
{
|
||||||
|
Log("API compatibility check failed. Updating CodexPlugin...");
|
||||||
|
var openApiFilePath = Path.Combine(PluginPathUtils.ProjectPluginsDir, "CodexPlugin", "openapi.yaml");
|
||||||
|
if (!File.Exists(openApiFilePath)) throw new Exception("Unable to locate CodexPlugin/openapi.yaml. Expected: " + openApiFilePath);
|
||||||
|
|
||||||
|
File.Delete(openApiFilePath);
|
||||||
|
File.WriteAllText(openApiFilePath, containerApi);
|
||||||
|
Log("CodexPlugin/openapi.yaml has been updated.");
|
||||||
|
}
|
||||||
|
|
||||||
private string Hash(string file)
|
private string Hash(string file)
|
||||||
{
|
{
|
||||||
var fileBytes = Encoding.ASCII.GetBytes(file
|
var fileBytes = Encoding.ASCII.GetBytes(file
|
||||||
|
@ -7,7 +7,7 @@ namespace CodexPlugin
|
|||||||
{
|
{
|
||||||
public class CodexContainerRecipe : ContainerRecipeFactory
|
public class CodexContainerRecipe : ContainerRecipeFactory
|
||||||
{
|
{
|
||||||
private const string DefaultDockerImage = "codexstorage/nim-codex:0.1.4";
|
private const string DefaultDockerImage = "codexstorage/nim-codex:0.1.5-dist-tests";
|
||||||
public const string ApiPortTag = "codex_api_port";
|
public const string ApiPortTag = "codex_api_port";
|
||||||
public const string ListenPortTag = "codex_listen_port";
|
public const string ListenPortTag = "codex_listen_port";
|
||||||
public const string MetricsPortTag = "codex_metrics_port";
|
public const string MetricsPortTag = "codex_metrics_port";
|
||||||
|
@ -83,33 +83,12 @@ components:
|
|||||||
id:
|
id:
|
||||||
$ref: "#/components/schemas/PeerId"
|
$ref: "#/components/schemas/PeerId"
|
||||||
|
|
||||||
ErasureParameters:
|
|
||||||
type: object
|
|
||||||
properties:
|
|
||||||
totalChunks:
|
|
||||||
type: integer
|
|
||||||
|
|
||||||
PoRParameters:
|
|
||||||
description: Parameters for Proof of Retrievability
|
|
||||||
type: object
|
|
||||||
properties:
|
|
||||||
u:
|
|
||||||
type: string
|
|
||||||
publicKey:
|
|
||||||
type: string
|
|
||||||
name:
|
|
||||||
type: string
|
|
||||||
|
|
||||||
Content:
|
Content:
|
||||||
type: object
|
type: object
|
||||||
description: Parameters specifying the content
|
description: Parameters specifying the content
|
||||||
properties:
|
properties:
|
||||||
cid:
|
cid:
|
||||||
$ref: "#/components/schemas/Cid"
|
$ref: "#/components/schemas/Cid"
|
||||||
erasure:
|
|
||||||
$ref: "#/components/schemas/ErasureParameters"
|
|
||||||
por:
|
|
||||||
$ref: "#/components/schemas/PoRParameters"
|
|
||||||
|
|
||||||
DebugInfo:
|
DebugInfo:
|
||||||
type: object
|
type: object
|
||||||
|
@ -7,4 +7,8 @@
|
|||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\..\Framework\Utils\Utils.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
using System.Security.Cryptography;
|
using System.Security.Cryptography;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using Utils;
|
||||||
|
|
||||||
public static class Program
|
public static class Program
|
||||||
{
|
{
|
||||||
@ -40,32 +41,9 @@ public static class Program
|
|||||||
|
|
||||||
private static string FindCodexPluginFolder()
|
private static string FindCodexPluginFolder()
|
||||||
{
|
{
|
||||||
var current = Directory.GetCurrentDirectory();
|
var folder = Path.Combine(PluginPathUtils.ProjectPluginsDir, "CodexPlugin");
|
||||||
|
if (!Directory.Exists(folder)) throw new Exception("CodexPlugin folder not found. Expected: " + folder);
|
||||||
while (true)
|
return folder;
|
||||||
{
|
|
||||||
var localFolders = Directory.GetDirectories(current);
|
|
||||||
var projectPluginsFolders = localFolders.Where(l => l.EndsWith(ProjectPluginsFolderName)).ToArray();
|
|
||||||
if (projectPluginsFolders.Length == 1)
|
|
||||||
{
|
|
||||||
return Path.Combine(projectPluginsFolders.Single(), CodexPluginFolderName);
|
|
||||||
}
|
|
||||||
var codexPluginFolders = localFolders.Where(l => l.EndsWith(CodexPluginFolderName)).ToArray();
|
|
||||||
if (codexPluginFolders.Length == 1)
|
|
||||||
{
|
|
||||||
return codexPluginFolders.Single();
|
|
||||||
}
|
|
||||||
|
|
||||||
var parent = Directory.GetParent(current);
|
|
||||||
if (parent == null)
|
|
||||||
{
|
|
||||||
var msg = $"Unable to locate '{CodexPluginFolderName}' folder. Travelled up from: '{Directory.GetCurrentDirectory()}'";
|
|
||||||
Console.WriteLine(msg);
|
|
||||||
throw new Exception(msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
current = parent.FullName;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static string CreateHash(string openApiFile)
|
private static string CreateHash(string openApiFile)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user