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

Update [Resource]Data to inherit the exact matching base class #1095

Merged
merged 16 commits into from
Mar 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions NuGet.Config
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<packageSources>
<clear />
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
<add key="azure-sdk-for-net" value="https://pkgs.dev.azure.com/azure-sdk/public/_packaging/azure-sdk-for-net/nuget/v3/index.json" />
</packageSources>
<disabledPackageSources>
<clear />
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -21,33 +21,15 @@ void IUtf8JsonSerializable.Write(Utf8JsonWriter writer)
internal static AzureEntityResource DeserializeAzureEntityResource(JsonElement element)
{
Optional<string> etag = default;
Optional<string> id = default;
Optional<string> name = default;
Optional<string> type = default;
foreach (var property in element.EnumerateObject())
{
if (property.NameEquals("etag"))
{
etag = property.Value.GetString();
continue;
}
if (property.NameEquals("id"))
{
id = property.Value.GetString();
continue;
}
if (property.NameEquals("name"))
{
name = property.Value.GetString();
continue;
}
if (property.NameEquals("type"))
{
type = property.Value.GetString();
continue;
}
}
return new AzureEntityResource(id.Value, name.Value, type.Value, etag.Value);
return new AzureEntityResource(etag.Value);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,21 @@

#nullable disable

using Azure.ResourceManager.Core;

namespace Azure.Management.Storage.Models
{
/// <summary> The resource model definition for a Azure Resource Manager resource with an etag. </summary>
public partial class AzureEntityResource : Resource
public partial class AzureEntityResource : ResourceManager.Core.Resource
{
/// <summary> Initializes a new instance of AzureEntityResource. </summary>
public AzureEntityResource()
{
}

/// <summary> Initializes a new instance of AzureEntityResource. </summary>
/// <param name="id"> Fully qualified resource Id for the resource. Ex - /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName}. </param>
/// <param name="name"> The name of the resource. </param>
/// <param name="type"> The type of the resource. Ex- Microsoft.Compute/virtualMachines or Microsoft.Storage/storageAccounts. </param>
/// <param name="etag"> Resource Etag. </param>
internal AzureEntityResource(string id, string name, string type, string etag) : base(id, name, type)
internal AzureEntityResource(string etag)
{
Etag = etag;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,206 @@

#nullable disable

using System;
using System.Collections.Generic;
using System.Text.Json;
using Azure.Core;

namespace Azure.Management.Storage.Models
{
/// <summary> A class representing the BlobContainer data model. </summary>
public partial class BlobContainerData
public partial class BlobContainerData : IUtf8JsonSerializable
{
void IUtf8JsonSerializable.Write(Utf8JsonWriter writer)
{
writer.WriteStartObject();
writer.WritePropertyName("properties");
writer.WriteStartObject();
if (Optional.IsDefined(DefaultEncryptionScope))
{
writer.WritePropertyName("defaultEncryptionScope");
writer.WriteStringValue(DefaultEncryptionScope);
}
if (Optional.IsDefined(DenyEncryptionScopeOverride))
{
writer.WritePropertyName("denyEncryptionScopeOverride");
writer.WriteBooleanValue(DenyEncryptionScopeOverride.Value);
}
if (Optional.IsDefined(PublicAccess))
{
writer.WritePropertyName("publicAccess");
writer.WriteStringValue(PublicAccess.Value.ToSerialString());
}
if (Optional.IsCollectionDefined(Metadata))
{
writer.WritePropertyName("metadata");
writer.WriteStartObject();
foreach (var item in Metadata)
{
writer.WritePropertyName(item.Key);
writer.WriteStringValue(item.Value);
}
writer.WriteEndObject();
}
writer.WriteEndObject();
writer.WriteEndObject();
}

internal static BlobContainerData DeserializeBlobContainerData(JsonElement element)
{
return new BlobContainerData();
Optional<string> etag = default;
Optional<string> defaultEncryptionScope = default;
Optional<bool> denyEncryptionScopeOverride = default;
Optional<PublicAccess> publicAccess = default;
Optional<DateTimeOffset> lastModifiedTime = default;
Optional<LeaseStatus> leaseStatus = default;
Optional<LeaseState> leaseState = default;
Optional<LeaseDuration> leaseDuration = default;
Optional<IDictionary<string, string>> metadata = default;
Optional<ImmutabilityPolicyProperties> immutabilityPolicy = default;
Optional<LegalHoldProperties> legalHold = default;
Optional<bool> hasLegalHold = default;
Optional<bool> hasImmutabilityPolicy = default;
foreach (var property in element.EnumerateObject())
{
if (property.NameEquals("etag"))
{
etag = property.Value.GetString();
continue;
}
if (property.NameEquals("properties"))
{
if (property.Value.ValueKind == JsonValueKind.Null)
{
property.ThrowNonNullablePropertyIsNull();
continue;
}
foreach (var property0 in property.Value.EnumerateObject())
{
if (property0.NameEquals("defaultEncryptionScope"))
{
defaultEncryptionScope = property0.Value.GetString();
continue;
}
if (property0.NameEquals("denyEncryptionScopeOverride"))
{
if (property0.Value.ValueKind == JsonValueKind.Null)
{
property0.ThrowNonNullablePropertyIsNull();
continue;
}
denyEncryptionScopeOverride = property0.Value.GetBoolean();
continue;
}
if (property0.NameEquals("publicAccess"))
{
if (property0.Value.ValueKind == JsonValueKind.Null)
{
property0.ThrowNonNullablePropertyIsNull();
continue;
}
publicAccess = property0.Value.GetString().ToPublicAccess();
continue;
}
if (property0.NameEquals("lastModifiedTime"))
{
if (property0.Value.ValueKind == JsonValueKind.Null)
{
property0.ThrowNonNullablePropertyIsNull();
continue;
}
lastModifiedTime = property0.Value.GetDateTimeOffset("O");
continue;
}
if (property0.NameEquals("leaseStatus"))
{
if (property0.Value.ValueKind == JsonValueKind.Null)
{
property0.ThrowNonNullablePropertyIsNull();
continue;
}
leaseStatus = new LeaseStatus(property0.Value.GetString());
continue;
}
if (property0.NameEquals("leaseState"))
{
if (property0.Value.ValueKind == JsonValueKind.Null)
{
property0.ThrowNonNullablePropertyIsNull();
continue;
}
leaseState = new LeaseState(property0.Value.GetString());
continue;
}
if (property0.NameEquals("leaseDuration"))
{
if (property0.Value.ValueKind == JsonValueKind.Null)
{
property0.ThrowNonNullablePropertyIsNull();
continue;
}
leaseDuration = new LeaseDuration(property0.Value.GetString());
continue;
}
if (property0.NameEquals("metadata"))
{
if (property0.Value.ValueKind == JsonValueKind.Null)
{
property0.ThrowNonNullablePropertyIsNull();
continue;
}
Dictionary<string, string> dictionary = new Dictionary<string, string>();
foreach (var property1 in property0.Value.EnumerateObject())
{
dictionary.Add(property1.Name, property1.Value.GetString());
}
metadata = dictionary;
continue;
}
if (property0.NameEquals("immutabilityPolicy"))
{
if (property0.Value.ValueKind == JsonValueKind.Null)
{
property0.ThrowNonNullablePropertyIsNull();
continue;
}
immutabilityPolicy = ImmutabilityPolicyProperties.DeserializeImmutabilityPolicyProperties(property0.Value);
continue;
}
if (property0.NameEquals("legalHold"))
{
if (property0.Value.ValueKind == JsonValueKind.Null)
{
property0.ThrowNonNullablePropertyIsNull();
continue;
}
legalHold = LegalHoldProperties.DeserializeLegalHoldProperties(property0.Value);
continue;
}
if (property0.NameEquals("hasLegalHold"))
{
if (property0.Value.ValueKind == JsonValueKind.Null)
{
property0.ThrowNonNullablePropertyIsNull();
continue;
}
hasLegalHold = property0.Value.GetBoolean();
continue;
}
if (property0.NameEquals("hasImmutabilityPolicy"))
{
if (property0.Value.ValueKind == JsonValueKind.Null)
{
property0.ThrowNonNullablePropertyIsNull();
continue;
}
hasImmutabilityPolicy = property0.Value.GetBoolean();
continue;
}
}
continue;
}
}
return new BlobContainerData(etag.Value, defaultEncryptionScope.Value, Optional.ToNullable(denyEncryptionScopeOverride), Optional.ToNullable(publicAccess), Optional.ToNullable(lastModifiedTime), Optional.ToNullable(leaseStatus), Optional.ToNullable(leaseState), Optional.ToNullable(leaseDuration), Optional.ToDictionary(metadata), immutabilityPolicy.Value, legalHold.Value, Optional.ToNullable(hasLegalHold), Optional.ToNullable(hasImmutabilityPolicy));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,49 @@

using System;
using System.Collections.Generic;
using Azure.Core;

namespace Azure.Management.Storage.Models
{
/// <summary> A class representing the BlobContainer data model. </summary>
public partial class BlobContainerData
public partial class BlobContainerData : AzureEntityResource
{
/// <summary> Initializes a new instance of BlobContainerData. </summary>
public BlobContainerData()
{
Metadata = new ChangeTrackingDictionary<string, string>();
}

/// <summary> Initializes a new instance of BlobContainerData. </summary>
/// <param name="etag"> Resource Etag. </param>
/// <param name="defaultEncryptionScope"> Default the container to use specified encryption scope for all writes. </param>
/// <param name="denyEncryptionScopeOverride"> Block override of encryption scope from the container default. </param>
/// <param name="publicAccess"> Specifies whether data in the container may be accessed publicly and the level of access. </param>
/// <param name="lastModifiedTime"> Returns the date and time the container was last modified. </param>
/// <param name="leaseStatus"> The lease status of the container. </param>
/// <param name="leaseState"> Lease state of the container. </param>
/// <param name="leaseDuration"> Specifies whether the lease on a container is of infinite or fixed duration, only when the container is leased. </param>
/// <param name="metadata"> A name-value pair to associate with the container as metadata. </param>
/// <param name="immutabilityPolicy"> The ImmutabilityPolicy property of the container. </param>
/// <param name="legalHold"> The LegalHold property of the container. </param>
/// <param name="hasLegalHold"> The hasLegalHold public property is set to true by SRP if there are at least one existing tag. The hasLegalHold public property is set to false by SRP if all existing legal hold tags are cleared out. There can be a maximum of 1000 blob containers with hasLegalHold=true for a given account. </param>
/// <param name="hasImmutabilityPolicy"> The hasImmutabilityPolicy public property is set to true by SRP if ImmutabilityPolicy has been created for this container. The hasImmutabilityPolicy public property is set to false by SRP if ImmutabilityPolicy has not been created for this container. </param>
internal BlobContainerData(string etag, string defaultEncryptionScope, bool? denyEncryptionScopeOverride, PublicAccess? publicAccess, DateTimeOffset? lastModifiedTime, LeaseStatus? leaseStatus, LeaseState? leaseState, LeaseDuration? leaseDuration, IDictionary<string, string> metadata, ImmutabilityPolicyProperties immutabilityPolicy, LegalHoldProperties legalHold, bool? hasLegalHold, bool? hasImmutabilityPolicy) : base(etag)
{
DefaultEncryptionScope = defaultEncryptionScope;
DenyEncryptionScopeOverride = denyEncryptionScopeOverride;
PublicAccess = publicAccess;
LastModifiedTime = lastModifiedTime;
LeaseStatus = leaseStatus;
LeaseState = leaseState;
LeaseDuration = leaseDuration;
Metadata = metadata;
ImmutabilityPolicy = immutabilityPolicy;
LegalHold = legalHold;
HasLegalHold = hasLegalHold;
HasImmutabilityPolicy = hasImmutabilityPolicy;
}

/// <summary> Default the container to use specified encryption scope for all writes. </summary>
public string DefaultEncryptionScope { get; set; }
/// <summary> Block override of encryption scope from the container default. </summary>
Expand Down
Loading