Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Implement Pack Manifests #149

Merged
merged 15 commits into from
Nov 12, 2024
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Copyright The ORAS Authors.
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

using System;

namespace OrasProject.Oras.Exceptions;

/// <summary>
/// InvalidDateTimeFormatException is thrown when a time format is invalid.
/// </summary>
public class InvalidDateTimeFormatException : FormatException
{
public InvalidDateTimeFormatException()
{
}

public InvalidDateTimeFormatException(string? message)
: base(message)
{
}

public InvalidDateTimeFormatException(string? message, Exception? inner)
: base(message, inner)
{
}
}
36 changes: 36 additions & 0 deletions src/OrasProject.Oras/Exceptions/InvalidMediaTypeException.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Copyright The ORAS Authors.
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

using System;

namespace OrasProject.Oras.Exceptions;

/// <summary>
/// InvalidMediaTypeException is thrown when media type is invalid.
/// </summary>
public class InvalidMediaTypeException : FormatException
{
public InvalidMediaTypeException()
{
}

public InvalidMediaTypeException(string? message)
: base(message)
{
}

public InvalidMediaTypeException(string? message, Exception? inner)
: base(message, inner)
{
}
}
36 changes: 36 additions & 0 deletions src/OrasProject.Oras/Exceptions/InvalidPackException.cs
nhu1997 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Copyright The ORAS Authors.
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

using System;

namespace OrasProject.Oras.Exceptions;

/// <summary>
/// InvalidPackException is thrown when an exception is thrown when pack manifest.
/// </summary>
public class InvalidPackException : FormatException
{
public InvalidPackException()
{
}

public InvalidPackException(string? message)
: base(message)
{
}

public InvalidPackException(string? message, Exception? inner)
: base(message, inner)
{
}
}
36 changes: 36 additions & 0 deletions src/OrasProject.Oras/Exceptions/MissingArtifactTypeException.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Copyright The ORAS Authors.
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

using System;

namespace OrasProject.Oras.Exceptions;

/// <summary>
/// MissingArtifactTypeException is thrown when artifactType is not found in manifest.
/// </summary>
public class MissingArtifactTypeException : FormatException
{
public MissingArtifactTypeException()
{
}

public MissingArtifactTypeException(string? message)
: base(message)
{
}

public MissingArtifactTypeException(string? message, Exception? inner)
: base(message, inner)
{
}
}
109 changes: 59 additions & 50 deletions src/OrasProject.Oras/Oci/Descriptor.cs
nhu1997 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,51 +1,60 @@
// Copyright The ORAS Authors.
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

using System.Collections.Generic;
using System.Text.Json.Serialization;

namespace OrasProject.Oras.Oci;

public class Descriptor
{
[JsonPropertyName("mediaType")]
public required string MediaType { get; set; }

[JsonPropertyName("digest")]
public required string Digest { get; set; }

[JsonPropertyName("size")]
public long Size { get; set; }

[JsonPropertyName("urls")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
public IList<string>? URLs { get; set; }

[JsonPropertyName("annotations")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
public IDictionary<string, string>? Annotations { get; set; }

[JsonPropertyName("data")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
public byte[]? Data { get; set; }

[JsonPropertyName("platform")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
public Platform? Platform { get; set; }

[JsonPropertyName("artifactType")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
// Copyright The ORAS Authors.
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

using System.Collections.Generic;
using System.Text;
using System.Text.Json.Serialization;

namespace OrasProject.Oras.Oci;

public class Descriptor
{
[JsonPropertyName("mediaType")]
public required string MediaType { get; set; }

[JsonPropertyName("digest")]
public required string Digest { get; set; }

[JsonPropertyName("size")]
public long Size { get; set; }

[JsonPropertyName("urls")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
public IList<string>? URLs { get; set; }

[JsonPropertyName("annotations")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
public IDictionary<string, string>? Annotations { get; set; }

[JsonPropertyName("data")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
public byte[]? Data { get; set; }

[JsonPropertyName("platform")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
public Platform? Platform { get; set; }

[JsonPropertyName("artifactType")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
public string? ArtifactType { get; set; }

internal BasicDescriptor BasicDescriptor => new BasicDescriptor(MediaType, Digest, Size);
}

internal static Descriptor Empty => new Descriptor
{
nhu1997 marked this conversation as resolved.
Show resolved Hide resolved
MediaType = OrasProject.Oras.Oci.MediaType.EmptyJson,
Digest = OrasProject.Oras.Content.Digest.ComputeSHA256(Encoding.UTF8.GetBytes("{}")),
Size = Encoding.UTF8.GetBytes("{}").Length,
Data = Encoding.UTF8.GetBytes("{}")
};
nhu1997 marked this conversation as resolved.
Show resolved Hide resolved

internal BasicDescriptor BasicDescriptor => new BasicDescriptor(MediaType, Digest, Size);
}
Loading
Loading