41 lines
1.4 KiB
C#
41 lines
1.4 KiB
C#
|
|
using System.Security.Cryptography.X509Certificates;
|
||
|
|
|
||
|
|
namespace Quorate.Oci;
|
||
|
|
|
||
|
|
public sealed class Registry : IDisposable
|
||
|
|
{
|
||
|
|
private readonly RegistryTransport transport;
|
||
|
|
|
||
|
|
public Registry(Uri endpoint, RegistryAuth auth, X509Certificate2 root)
|
||
|
|
{
|
||
|
|
transport = new RegistryTransport(endpoint, auth, root);
|
||
|
|
}
|
||
|
|
|
||
|
|
internal Registry(Uri endpoint, RegistryAuth auth, HttpMessageHandler handler)
|
||
|
|
{
|
||
|
|
transport = new RegistryTransport(endpoint, auth, handler);
|
||
|
|
}
|
||
|
|
|
||
|
|
public static X509Certificate2 LoadRoot(string path) =>
|
||
|
|
X509CertificateLoader.LoadCertificateFromFile(path);
|
||
|
|
|
||
|
|
public async Task<string> PushAsync(
|
||
|
|
string repository,
|
||
|
|
string layout,
|
||
|
|
string sourceTag,
|
||
|
|
string targetTag,
|
||
|
|
CancellationToken cancellationToken = default)
|
||
|
|
{
|
||
|
|
RepositoryName destination = RepositoryName.Parse(repository);
|
||
|
|
OciTag source = OciTag.Parse(sourceTag);
|
||
|
|
OciTag target = OciTag.Parse(targetTag);
|
||
|
|
OciPublicationPlan plan = await OciLayout.LoadAsync(layout, source, cancellationToken)
|
||
|
|
.ConfigureAwait(false);
|
||
|
|
var publisher = new OciPublisher(transport, destination);
|
||
|
|
OciDigest published = await publisher.PushAsync(plan, target, cancellationToken)
|
||
|
|
.ConfigureAwait(false);
|
||
|
|
return published.ToString();
|
||
|
|
}
|
||
|
|
|
||
|
|
public void Dispose() => transport.Dispose();
|
||
|
|
}
|