mirror of
https://github.com/logos-storage/logos-storage-nim-cs-dist-tests.git
synced 2026-05-07 09:59:28 +00:00
* ci(docker): build dist-tests images * Update to .net 10, kubernetes client 18.0.13 Kubernetes client 18.0.13 is compatible with Kubernetes 1.34.x. The Kubernetes version is selected automatically by kubeadm in docker desktop (v1.34.1). See https://github.com/kubernetes-client/csharp#version-compatibility for a compatibility table. * Updates to support Kubernetes upgrade * bump openapi.yaml to match openapi.yaml in the logos-storage-nim docker image * bump doc to .net 10 * bump docker to .net 10 * Build image with latest tag always Always build an image with a latest tag (as well as a sha commit hash) when there's a push to master * docker image tag as "latest" only when pushing to master * Update docker image to install doctl * Remove doctl install kubeconfig is now created and uses a plain bearer token instead of using doctl as a credential mgr * Rename and remove all instances of Codex * Further remove CodexNetDeployer as it is no longer needed --------- Co-authored-by: Adam Uhlíř <adam@uhlir.dev>
166 lines
4.5 KiB
C#
166 lines
4.5 KiB
C#
using Newtonsoft.Json.Linq;
|
|
using System.Numerics;
|
|
using Utils;
|
|
|
|
namespace LogosStorageClient
|
|
{
|
|
public class Mapper
|
|
{
|
|
public DebugInfo Map(StorageOpenApi.DebugInfo debugInfo)
|
|
{
|
|
return new DebugInfo
|
|
{
|
|
Id = debugInfo.Id,
|
|
Spr = debugInfo.Spr,
|
|
Addrs = debugInfo.Addrs.ToArray(),
|
|
AnnounceAddresses = debugInfo.AnnounceAddresses.ToArray(),
|
|
Version = Map(debugInfo.Storage),
|
|
Table = Map(debugInfo.Table)
|
|
};
|
|
}
|
|
|
|
public LocalDatasetList Map(StorageOpenApi.DataList dataList)
|
|
{
|
|
return new LocalDatasetList
|
|
{
|
|
Content = dataList.Content.Select(Map).ToArray()
|
|
};
|
|
}
|
|
|
|
public LocalDataset Map(StorageOpenApi.DataItem dataItem)
|
|
{
|
|
return new LocalDataset
|
|
{
|
|
Cid = new ContentId(dataItem.Cid),
|
|
Manifest = MapManifest(dataItem.Manifest)
|
|
};
|
|
}
|
|
public LogosStorageSpace Map(StorageOpenApi.Space space)
|
|
{
|
|
return new LogosStorageSpace
|
|
{
|
|
QuotaMaxBytes = space.QuotaMaxBytes,
|
|
QuotaReservedBytes = space.QuotaReservedBytes,
|
|
QuotaUsedBytes = space.QuotaUsedBytes,
|
|
TotalBlocks = space.TotalBlocks
|
|
};
|
|
}
|
|
|
|
private DebugInfoVersion Map(StorageOpenApi.StorageVersion obj)
|
|
{
|
|
return new DebugInfoVersion
|
|
{
|
|
Version = obj.Version,
|
|
Revision = obj.Revision
|
|
};
|
|
}
|
|
|
|
private DebugInfoTable Map(StorageOpenApi.PeersTable obj)
|
|
{
|
|
return new DebugInfoTable
|
|
{
|
|
LocalNode = Map(obj.LocalNode),
|
|
Nodes = Map(obj.Nodes)
|
|
};
|
|
}
|
|
|
|
private DebugInfoTableNode Map(StorageOpenApi.Node? token)
|
|
{
|
|
if (token == null) return new DebugInfoTableNode();
|
|
return new DebugInfoTableNode
|
|
{
|
|
Address = token.Address,
|
|
NodeId = token.NodeId,
|
|
PeerId = token.PeerId,
|
|
Record = token.Record,
|
|
Seen = token.Seen
|
|
};
|
|
}
|
|
|
|
private DebugInfoTableNode[] Map(ICollection<StorageOpenApi.Node> nodes)
|
|
{
|
|
if (nodes == null || nodes.Count == 0)
|
|
{
|
|
return new DebugInfoTableNode[0];
|
|
}
|
|
|
|
return nodes.Select(Map).ToArray();
|
|
}
|
|
|
|
private Manifest MapManifest(StorageOpenApi.ManifestItem manifest)
|
|
{
|
|
return new Manifest
|
|
{
|
|
BlockSize = new ByteSize(Convert.ToInt64(manifest.BlockSize)),
|
|
DatasetSize = new ByteSize(Convert.ToInt64(manifest.DatasetSize)),
|
|
RootHash = manifest.TreeCid
|
|
};
|
|
}
|
|
|
|
private JArray JArray(IDictionary<string, object> map, string name)
|
|
{
|
|
return (JArray)map[name];
|
|
}
|
|
|
|
private JObject JObject(IDictionary<string, object> map, string name)
|
|
{
|
|
return (JObject)map[name];
|
|
}
|
|
|
|
private string StringOrEmpty(JObject obj, string name)
|
|
{
|
|
if (obj.TryGetValue(name, out var token))
|
|
{
|
|
var str = (string?)token;
|
|
if (!string.IsNullOrEmpty(str)) return str;
|
|
}
|
|
return string.Empty;
|
|
}
|
|
|
|
private bool Bool(JObject obj, string name)
|
|
{
|
|
if (obj.TryGetValue(name, out var token))
|
|
{
|
|
return (bool)token;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
private string ToDecInt(double d)
|
|
{
|
|
var i = new BigInteger(d);
|
|
return i.ToString("D");
|
|
}
|
|
|
|
private string ToDecInt(TestToken t)
|
|
{
|
|
return t.TstWei.ToString("D");
|
|
}
|
|
|
|
private TestToken ToTestToken(string s)
|
|
{
|
|
return new TestToken(ToBigInt(s));
|
|
}
|
|
|
|
private long ToLong(double value)
|
|
{
|
|
return Convert.ToInt64(value);
|
|
}
|
|
|
|
private BigInteger ToBigInt(string tokens)
|
|
{
|
|
return BigInteger.Parse(tokens);
|
|
}
|
|
|
|
private TimeSpan ToTimespan(long duration)
|
|
{
|
|
return TimeSpan.FromSeconds(duration);
|
|
}
|
|
|
|
private ByteSize ToByteSize(long size)
|
|
{
|
|
return new ByteSize(size);
|
|
}
|
|
}
|
|
}
|