Skip to content

Commit

Permalink
add Index constructor
Browse files Browse the repository at this point in the history
Signed-off-by: Patrick Pan <[email protected]>
  • Loading branch information
Patrick Pan committed Nov 25, 2024
1 parent ddbf048 commit feaf46d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/OrasProject.Oras/Content/Digest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ internal static string Validate(string? digest)

return digest;
}

/// <summary>
/// Generates a SHA-256 digest from a byte array.
/// </summary>
Expand Down
18 changes: 12 additions & 6 deletions src/OrasProject.Oras/Oci/Index.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
// limitations under the License.

using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Text;
using System.Text.Json;
using System.Text.Json.Serialization;
Expand Down Expand Up @@ -43,14 +44,19 @@ public class Index : Versioned
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
public IDictionary<string, string>? Annotations { get; set; }

public Index() {}

[SetsRequiredMembers]
public Index(IList<Descriptor> manifests)
{
Manifests = manifests;
MediaType = Oci.MediaType.ImageIndex;
SchemaVersion = 2;
}

internal static (Descriptor, byte[]) GenerateIndex(IList<Descriptor> manifests)
{
var index = new Index()
{
Manifests = manifests,
MediaType = Oci.MediaType.ImageIndex,
SchemaVersion = 2
};
var index = new Index(manifests);
var indexContent = JsonSerializer.SerializeToUtf8Bytes(index);
return (Descriptor.Create(indexContent, Oci.MediaType.ImageIndex), indexContent);
}
Expand Down

0 comments on commit feaf46d

Please sign in to comment.