-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
133 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# Referrers | ||
|
||
Sub-commands: | ||
|
||
* [`list`](#query-referrers) - Lists the referrers to a manifest | ||
|
||
## Query Referrers | ||
|
||
Returns the referrers to the specified manifest. | ||
|
||
```console | ||
> dredge referrer list mcr.microsoft.com/dotnet/core/sdk:latest | ||
{ | ||
"manifests": [ | ||
{ | ||
"mediaType": "application/vnd.oci.image.manifest.v1+json", | ||
"digest": "sha256:551e9aa2046071e51b1611a7e85f85af3d2cc6841935cc176a931de4194ecdc1", | ||
"size": 788, | ||
"urls": [], | ||
"annotations": { | ||
"org.opencontainers.image.created": "2024-08-13T14:20:19Z", | ||
"vnd.microsoft.artifact.lifecycle.end-of-life.date": "2022-12-13" | ||
}, | ||
"artifactType": "application/vnd.microsoft.artifact.lifecycle" | ||
} | ||
], | ||
"annotations": {}, | ||
"schemaVersion": 2, | ||
"mediaType": "application/vnd.oci.image.index.v1+json" | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
using Newtonsoft.Json; | ||
using Valleysoft.DockerRegistryClient; | ||
using Valleysoft.DockerRegistryClient.Models.Manifests; | ||
using Valleysoft.DockerRegistryClient.Models.Manifests.Oci; | ||
|
||
namespace Valleysoft.Dredge.Commands.Referrer; | ||
|
||
public class ListCommand : RegistryCommandBase<ListOptions> | ||
{ | ||
public ListCommand(IDockerRegistryClientFactory dockerRegistryClientFactory) | ||
: base("list", "Lists the referrers to a manifest", dockerRegistryClientFactory) | ||
{ | ||
} | ||
|
||
protected override Task ExecuteAsync() | ||
{ | ||
ImageName imageName = ImageName.Parse(Options.Image); | ||
return CommandHelper.ExecuteCommandAsync(imageName.Registry, async () => | ||
{ | ||
using IDockerRegistryClient client = await DockerRegistryClientFactory.GetClientAsync(imageName.Registry); | ||
|
||
OciImageIndex initialIndex; | ||
|
||
string digest; | ||
if (!string.IsNullOrEmpty(imageName.Digest)) | ||
{ | ||
digest = imageName.Digest; | ||
} | ||
else | ||
{ | ||
ManifestInfo manifestInfo = await client.Manifests.GetAsync(imageName.Repo, imageName.Tag!); | ||
digest = manifestInfo.DockerContentDigest; | ||
} | ||
|
||
Page<OciImageIndex> indexPage = await client.Referrers.GetAsync(imageName.Repo, digest, Options.ArtifactType); | ||
initialIndex = indexPage.Value; | ||
while (indexPage.NextPageLink is not null) | ||
{ | ||
Page<OciImageIndex> nextPage = await client.Referrers.GetAsync(imageName.Repo, digest, Options.ArtifactType); | ||
initialIndex.Manifests = initialIndex.Manifests | ||
.Concat(nextPage.Value.Manifests) | ||
.ToArray(); | ||
} | ||
|
||
string output = JsonConvert.SerializeObject(initialIndex, JsonHelper.Settings); | ||
|
||
Console.Out.WriteLine(output); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using System.CommandLine; | ||
|
||
namespace Valleysoft.Dredge.Commands.Referrer; | ||
|
||
public class ListOptions : OptionsBase | ||
{ | ||
private readonly Argument<string> imageArg; | ||
private readonly Option<string> artifactTypeArg; | ||
|
||
public string Image { get; set; } = string.Empty; | ||
public string? ArtifactType { get; set; } | ||
|
||
public ListOptions() | ||
{ | ||
imageArg = Add(new Argument<string>("name", "Name of the manifest (<name>, <name>:<tag>, or <name>@<digest>)")); | ||
artifactTypeArg = Add(new Option<string>("--artifact-type", "Artifact media type to filter by")); | ||
} | ||
|
||
protected override void GetValues() | ||
{ | ||
Image = GetValue(imageArg); | ||
ArtifactType = GetValue(artifactTypeArg); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/Valleysoft.Dredge/Commands/Referrer/ReferrerCommand.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using System.CommandLine; | ||
|
||
namespace Valleysoft.Dredge.Commands.Referrer; | ||
|
||
public class ReferrerCommand : Command | ||
{ | ||
public ReferrerCommand(IDockerRegistryClientFactory dockerRegistryClientFactory) | ||
: base("referrer", "Commands related to referrers") | ||
{ | ||
AddCommand(new ListCommand(dockerRegistryClientFactory)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters