diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 78e01e3db792..4d32d38e7ebc 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -39,6 +39,8 @@ /sdk/storage/ @amishra-dev @seanmcc-msft @amnguye @kasobol-msft @tg-msft @JoshLove-msft +/sdk/tables/ @christothes + /sdk/textanalytics/ @annelo-msft @maririos # Management Plane diff --git a/sdk/tables/Azure.Data.Tables/Azure.Data.Tables.sln b/sdk/tables/Azure.Data.Tables/Azure.Data.Tables.sln new file mode 100644 index 000000000000..c3f4e8459c50 --- /dev/null +++ b/sdk/tables/Azure.Data.Tables/Azure.Data.Tables.sln @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.30011.22 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Azure.Data.Tables", "src\Azure.Data.Tables.csproj", "{0E27F1A7-BBBD-4BE9-B331-C4B18D8DD27C}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Azure.Data.Tables.Tests", "tests\Azure.Data.Tables.Tests.csproj", "{DE6D1CE8-3B67-4651-B401-A868A72398D1}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {0E27F1A7-BBBD-4BE9-B331-C4B18D8DD27C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {0E27F1A7-BBBD-4BE9-B331-C4B18D8DD27C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {0E27F1A7-BBBD-4BE9-B331-C4B18D8DD27C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {0E27F1A7-BBBD-4BE9-B331-C4B18D8DD27C}.Release|Any CPU.Build.0 = Release|Any CPU + {DE6D1CE8-3B67-4651-B401-A868A72398D1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {DE6D1CE8-3B67-4651-B401-A868A72398D1}.Debug|Any CPU.Build.0 = Debug|Any CPU + {DE6D1CE8-3B67-4651-B401-A868A72398D1}.Release|Any CPU.ActiveCfg = Release|Any CPU + {DE6D1CE8-3B67-4651-B401-A868A72398D1}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {A97F4B90-2591-4689-B1F8-5F21FE6D6CAE} + EndGlobalSection +EndGlobal diff --git a/sdk/tables/Azure.Data.Tables/CHANGELOG.md b/sdk/tables/Azure.Data.Tables/CHANGELOG.md new file mode 100644 index 000000000000..320d347eb4f6 --- /dev/null +++ b/sdk/tables/Azure.Data.Tables/CHANGELOG.md @@ -0,0 +1,3 @@ +# Release History + +## 1.0.0-preview.1 (Unreleased) diff --git a/sdk/tables/Azure.Data.Tables/api/Azure.Data.Tables.netstandard2.0.cs b/sdk/tables/Azure.Data.Tables/api/Azure.Data.Tables.netstandard2.0.cs new file mode 100644 index 000000000000..683f7a24d888 --- /dev/null +++ b/sdk/tables/Azure.Data.Tables/api/Azure.Data.Tables.netstandard2.0.cs @@ -0,0 +1,184 @@ +namespace Azure.Data.Tables +{ + public partial class TableClient + { + protected TableClient() { } + public virtual Azure.Response> Insert(System.Collections.Generic.IDictionary entity, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task>> InsertAsync(System.Collections.Generic.IDictionary entity, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.Pageable> Query(string select = null, string filter = null, int? top = default(int?), System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.AsyncPageable> QueryAsync(string select = null, string filter = null, int? top = default(int?), System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.Response Update(string partitionKey, string rowKey, System.Collections.Generic.IDictionary entity, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task UpdateAsync(string partitionKey, string rowKey, System.Collections.Generic.IDictionary entity, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + } + public partial class TableClientOptions : Azure.Core.ClientOptions + { + public TableClientOptions(Azure.Data.Tables.TableClientOptions.ServiceVersion serviceVersion = Azure.Data.Tables.TableClientOptions.ServiceVersion.V2018_10_10) { } + public enum ServiceVersion + { + V2018_10_10 = 1, + } + } + public partial class TableServiceClient + { + protected TableServiceClient() { } + public TableServiceClient(System.Uri endpoint, Azure.Data.Tables.TablesSharedKeyCredential credential, Azure.Data.Tables.TableClientOptions options = null) { } + public Azure.Data.Tables.TableClient GetTableClient(string tableName) { throw null; } + public virtual Azure.Pageable GetTables(string select = null, string filter = null, int? top = default(int?), System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.AsyncPageable GetTablesAsync(string select = null, string filter = null, int? top = default(int?), System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + } + public partial class TablesSharedKeyCredential + { + public TablesSharedKeyCredential(string accountName, string accountKey) { } + public string AccountName { get { throw null; } } + protected static string ComputeSasSignature(Azure.Data.Tables.TablesSharedKeyCredential credential, string message) { throw null; } + public void SetAccountKey(string accountKey) { } + } +} +namespace Azure.Data.Tables.Models +{ + public partial class AccessPolicy + { + public AccessPolicy(System.DateTimeOffset start, System.DateTimeOffset expiry, string permission) { } + public System.DateTimeOffset Expiry { get { throw null; } } + public string Permission { get { throw null; } } + public System.DateTimeOffset Start { get { throw null; } } + } + public partial class CorsRule + { + public CorsRule(string allowedOrigins, string allowedMethods, string allowedHeaders, string exposedHeaders, int maxAgeInSeconds) { } + public string AllowedHeaders { get { throw null; } } + public string AllowedMethods { get { throw null; } } + public string AllowedOrigins { get { throw null; } } + public string ExposedHeaders { get { throw null; } } + public int MaxAgeInSeconds { get { throw null; } } + } + public partial class GeoReplication + { + internal GeoReplication() { } + public System.DateTimeOffset LastSyncTime { get { throw null; } } + public Azure.Data.Tables.Models.GeoReplicationStatusType Status { get { throw null; } } + } + [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)] + public readonly partial struct GeoReplicationStatusType : System.IEquatable + { + private readonly object _dummy; + private readonly int _dummyPrimitive; + public GeoReplicationStatusType(string value) { throw null; } + public static Azure.Data.Tables.Models.GeoReplicationStatusType Bootstrap { get { throw null; } } + public static Azure.Data.Tables.Models.GeoReplicationStatusType Live { get { throw null; } } + public static Azure.Data.Tables.Models.GeoReplicationStatusType Unavailable { get { throw null; } } + public bool Equals(Azure.Data.Tables.Models.GeoReplicationStatusType other) { throw null; } + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] + public override bool Equals(object obj) { throw null; } + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] + public override int GetHashCode() { throw null; } + public static bool operator ==(Azure.Data.Tables.Models.GeoReplicationStatusType left, Azure.Data.Tables.Models.GeoReplicationStatusType right) { throw null; } + public static implicit operator Azure.Data.Tables.Models.GeoReplicationStatusType (string value) { throw null; } + public static bool operator !=(Azure.Data.Tables.Models.GeoReplicationStatusType left, Azure.Data.Tables.Models.GeoReplicationStatusType right) { throw null; } + public override string ToString() { throw null; } + } + public partial class LoggingSettings + { + public LoggingSettings(string version, bool delete, bool read, bool write, Azure.Data.Tables.Models.RetentionPolicy retentionPolicy) { } + public bool Delete { get { throw null; } } + public bool Read { get { throw null; } } + public Azure.Data.Tables.Models.RetentionPolicy RetentionPolicy { get { throw null; } } + public string Version { get { throw null; } } + public bool Write { get { throw null; } } + } + [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)] + public readonly partial struct OdataMetadataFormat : System.IEquatable + { + private readonly object _dummy; + private readonly int _dummyPrimitive; + public OdataMetadataFormat(string value) { throw null; } + public static Azure.Data.Tables.Models.OdataMetadataFormat ApplicationJsonOdataFullmetadata { get { throw null; } } + public static Azure.Data.Tables.Models.OdataMetadataFormat ApplicationJsonOdataMinimalmetadata { get { throw null; } } + public static Azure.Data.Tables.Models.OdataMetadataFormat ApplicationJsonOdataNometadata { get { throw null; } } + public bool Equals(Azure.Data.Tables.Models.OdataMetadataFormat other) { throw null; } + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] + public override bool Equals(object obj) { throw null; } + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] + public override int GetHashCode() { throw null; } + public static bool operator ==(Azure.Data.Tables.Models.OdataMetadataFormat left, Azure.Data.Tables.Models.OdataMetadataFormat right) { throw null; } + public static implicit operator Azure.Data.Tables.Models.OdataMetadataFormat (string value) { throw null; } + public static bool operator !=(Azure.Data.Tables.Models.OdataMetadataFormat left, Azure.Data.Tables.Models.OdataMetadataFormat right) { throw null; } + public override string ToString() { throw null; } + } + public partial class QueryOptions + { + public QueryOptions() { } + public string Filter { get { throw null; } set { } } + public Azure.Data.Tables.Models.OdataMetadataFormat? Format { get { throw null; } set { } } + public string Select { get { throw null; } set { } } + public int? Top { get { throw null; } set { } } + } + public partial class RequestMetrics + { + public RequestMetrics(bool enabled) { } + public bool Enabled { get { throw null; } } + public bool? IncludeAPIs { get { throw null; } set { } } + public Azure.Data.Tables.Models.RetentionPolicy RetentionPolicy { get { throw null; } set { } } + public string Version { get { throw null; } set { } } + } + public partial class RetentionPolicy + { + public RetentionPolicy(bool enabled) { } + public int? Days { get { throw null; } set { } } + public bool Enabled { get { throw null; } } + } + public partial class SignedIdentifier + { + public SignedIdentifier(string id, Azure.Data.Tables.Models.AccessPolicy accessPolicy) { } + public Azure.Data.Tables.Models.AccessPolicy AccessPolicy { get { throw null; } } + public string Id { get { throw null; } } + } + public partial class StorageError + { + internal StorageError() { } + public string Message { get { throw null; } } + } + public partial class StorageServiceProperties + { + public StorageServiceProperties() { } + public System.Collections.Generic.IList Cors { get { throw null; } set { } } + public Azure.Data.Tables.Models.RequestMetrics HourMetrics { get { throw null; } set { } } + public Azure.Data.Tables.Models.LoggingSettings Logging { get { throw null; } set { } } + public Azure.Data.Tables.Models.RequestMetrics MinuteMetrics { get { throw null; } set { } } + } + public partial class StorageServiceStats + { + internal StorageServiceStats() { } + public Azure.Data.Tables.Models.GeoReplication GeoReplication { get { throw null; } } + } + public partial class TableEntityQueryResponse + { + internal TableEntityQueryResponse() { } + public string OdataMetadata { get { throw null; } } + public System.Collections.Generic.IReadOnlyList> Value { get { throw null; } } + } + public partial class TableProperties + { + public TableProperties() { } + public string TableName { get { throw null; } set { } } + } + public partial class TableQueryResponse + { + internal TableQueryResponse() { } + public string OdataMetadata { get { throw null; } } + public System.Collections.Generic.IReadOnlyList Value { get { throw null; } } + } + public partial class TableResponse : Azure.Data.Tables.Models.TableResponseProperties + { + internal TableResponse() { } + public string OdataMetadata { get { throw null; } } + } + public partial class TableResponseProperties + { + internal TableResponseProperties() { } + public string OdataEditLink { get { throw null; } } + public string OdataId { get { throw null; } } + public string OdataType { get { throw null; } } + public string TableName { get { throw null; } } + } +} diff --git a/sdk/tables/Azure.Data.Tables/readme.md b/sdk/tables/Azure.Data.Tables/readme.md new file mode 100644 index 000000000000..dca888fb2d33 --- /dev/null +++ b/sdk/tables/Azure.Data.Tables/readme.md @@ -0,0 +1,47 @@ +# Azure Tables client library for .NET + +Content forthcoming + +## Getting started + +Content forthcoming + +### Install the package + +Content forthcoming + +### Authenticate the client + +Content forthcoming + +## Key concepts + +Content forthcoming + +## Examples + +Content forthcoming + +## Troubleshooting + +Content forthcoming + +## Next steps + +Content forthcoming + +## Contributing + +This project welcomes contributions and suggestions. Most contributions require +you to agree to a Contributor License Agreement (CLA) declaring that you have +the right to, and actually do, grant us the rights to use your contribution. For +details, visit [cla.microsoft.com][cla]. + +This project has adopted the [Microsoft Open Source Code of Conduct][coc]. +For more information see the [Code of Conduct FAQ][coc_faq] +or contact [opencode@microsoft.com][coc_contact] with any +additional questions or comments. + + + +![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-net%2Fsdk%2Ftables%2FAzure.Data.Tables%2FREADME.png) diff --git a/sdk/tables/Azure.Data.Tables/src/Azure.Data.Tables.csproj b/sdk/tables/Azure.Data.Tables/src/Azure.Data.Tables.csproj new file mode 100644 index 000000000000..235dd7375f38 --- /dev/null +++ b/sdk/tables/Azure.Data.Tables/src/Azure.Data.Tables.csproj @@ -0,0 +1,34 @@ + + + This client library enables working with the Microsoft Azure Table service + Microsoft Azure.Data.Tables client library + 1.0.0-preview.1 + TableSDK;$(DefineConstants) + Microsoft Azure Tables;Microsoft;Azure;Tables;Table;$(PackageCommonTags) + $(RequiredTargetFrameworks) + false + + $(NoWarn);CA1812;CS1591 + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sdk/tables/Azure.Data.Tables/src/Generated/Models/AccessPolicy.Serialization.cs b/sdk/tables/Azure.Data.Tables/src/Generated/Models/AccessPolicy.Serialization.cs new file mode 100644 index 000000000000..2ad84f88a1d3 --- /dev/null +++ b/sdk/tables/Azure.Data.Tables/src/Generated/Models/AccessPolicy.Serialization.cs @@ -0,0 +1,52 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Xml; +using System.Xml.Linq; +using Azure.Core; + +namespace Azure.Data.Tables.Models +{ + public partial class AccessPolicy : IXmlSerializable + { + void IXmlSerializable.Write(XmlWriter writer, string nameHint) + { + writer.WriteStartElement(nameHint ?? "AccessPolicy"); + writer.WriteStartElement("Start"); + writer.WriteValue(Start, "S"); + writer.WriteEndElement(); + writer.WriteStartElement("Expiry"); + writer.WriteValue(Expiry, "S"); + writer.WriteEndElement(); + writer.WriteStartElement("Permission"); + writer.WriteValue(Permission); + writer.WriteEndElement(); + writer.WriteEndElement(); + } + + internal static AccessPolicy DeserializeAccessPolicy(XElement element) + { + DateTimeOffset start = default; + DateTimeOffset expiry = default; + string permission = default; + if (element.Element("Start") is XElement startElement) + { + start = startElement.GetDateTimeOffsetValue("S"); + } + if (element.Element("Expiry") is XElement expiryElement) + { + expiry = expiryElement.GetDateTimeOffsetValue("S"); + } + if (element.Element("Permission") is XElement permissionElement) + { + permission = (string)permissionElement; + } + return new AccessPolicy(start, expiry, permission); + } + } +} diff --git a/sdk/tables/Azure.Data.Tables/src/Generated/Models/AccessPolicy.cs b/sdk/tables/Azure.Data.Tables/src/Generated/Models/AccessPolicy.cs new file mode 100644 index 000000000000..5347bec8c0c3 --- /dev/null +++ b/sdk/tables/Azure.Data.Tables/src/Generated/Models/AccessPolicy.cs @@ -0,0 +1,38 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; + +namespace Azure.Data.Tables.Models +{ + /// An Access policy. + public partial class AccessPolicy + { + /// Initializes a new instance of AccessPolicy. + /// the date-time the policy is active. + /// the date-time the policy expires. + /// the permissions for the acl policy. + public AccessPolicy(DateTimeOffset start, DateTimeOffset expiry, string permission) + { + if (permission == null) + { + throw new ArgumentNullException(nameof(permission)); + } + + Start = start; + Expiry = expiry; + Permission = permission; + } + + /// the date-time the policy is active. + public DateTimeOffset Start { get; } + /// the date-time the policy expires. + public DateTimeOffset Expiry { get; } + /// the permissions for the acl policy. + public string Permission { get; } + } +} diff --git a/sdk/tables/Azure.Data.Tables/src/Generated/Models/CorsRule.Serialization.cs b/sdk/tables/Azure.Data.Tables/src/Generated/Models/CorsRule.Serialization.cs new file mode 100644 index 000000000000..2a070fd8a1ed --- /dev/null +++ b/sdk/tables/Azure.Data.Tables/src/Generated/Models/CorsRule.Serialization.cs @@ -0,0 +1,67 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System.Xml; +using System.Xml.Linq; +using Azure.Core; + +namespace Azure.Data.Tables.Models +{ + public partial class CorsRule : IXmlSerializable + { + void IXmlSerializable.Write(XmlWriter writer, string nameHint) + { + writer.WriteStartElement(nameHint ?? "CorsRule"); + writer.WriteStartElement("AllowedOrigins"); + writer.WriteValue(AllowedOrigins); + writer.WriteEndElement(); + writer.WriteStartElement("AllowedMethods"); + writer.WriteValue(AllowedMethods); + writer.WriteEndElement(); + writer.WriteStartElement("AllowedHeaders"); + writer.WriteValue(AllowedHeaders); + writer.WriteEndElement(); + writer.WriteStartElement("ExposedHeaders"); + writer.WriteValue(ExposedHeaders); + writer.WriteEndElement(); + writer.WriteStartElement("MaxAgeInSeconds"); + writer.WriteValue(MaxAgeInSeconds); + writer.WriteEndElement(); + writer.WriteEndElement(); + } + + internal static CorsRule DeserializeCorsRule(XElement element) + { + string allowedOrigins = default; + string allowedMethods = default; + string allowedHeaders = default; + string exposedHeaders = default; + int maxAgeInSeconds = default; + if (element.Element("AllowedOrigins") is XElement allowedOriginsElement) + { + allowedOrigins = (string)allowedOriginsElement; + } + if (element.Element("AllowedMethods") is XElement allowedMethodsElement) + { + allowedMethods = (string)allowedMethodsElement; + } + if (element.Element("AllowedHeaders") is XElement allowedHeadersElement) + { + allowedHeaders = (string)allowedHeadersElement; + } + if (element.Element("ExposedHeaders") is XElement exposedHeadersElement) + { + exposedHeaders = (string)exposedHeadersElement; + } + if (element.Element("MaxAgeInSeconds") is XElement maxAgeInSecondsElement) + { + maxAgeInSeconds = (int)maxAgeInSecondsElement; + } + return new CorsRule(allowedOrigins, allowedMethods, allowedHeaders, exposedHeaders, maxAgeInSeconds); + } + } +} diff --git a/sdk/tables/Azure.Data.Tables/src/Generated/Models/CorsRule.cs b/sdk/tables/Azure.Data.Tables/src/Generated/Models/CorsRule.cs new file mode 100644 index 000000000000..30f8578dc9f0 --- /dev/null +++ b/sdk/tables/Azure.Data.Tables/src/Generated/Models/CorsRule.cs @@ -0,0 +1,58 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; + +namespace Azure.Data.Tables.Models +{ + /// CORS is an HTTP feature that enables a web application running under one domain to access resources in another domain. Web browsers implement a security restriction known as same-origin policy that prevents a web page from calling APIs in a different domain; CORS provides a secure way to allow one domain (the origin domain) to call APIs in another domain. + public partial class CorsRule + { + /// Initializes a new instance of CorsRule. + /// The origin domains that are permitted to make a request against the storage service via CORS. The origin domain is the domain from which the request originates. Note that the origin must be an exact case-sensitive match with the origin that the user age sends to the service. You can also use the wildcard character '*' to allow all origin domains to make requests via CORS. + /// The methods (HTTP request verbs) that the origin domain may use for a CORS request. (comma separated). + /// the request headers that the origin domain may specify on the CORS request. + /// The response headers that may be sent in the response to the CORS request and exposed by the browser to the request issuer. + /// The maximum amount time that a browser should cache the preflight OPTIONS request. + public CorsRule(string allowedOrigins, string allowedMethods, string allowedHeaders, string exposedHeaders, int maxAgeInSeconds) + { + if (allowedOrigins == null) + { + throw new ArgumentNullException(nameof(allowedOrigins)); + } + if (allowedMethods == null) + { + throw new ArgumentNullException(nameof(allowedMethods)); + } + if (allowedHeaders == null) + { + throw new ArgumentNullException(nameof(allowedHeaders)); + } + if (exposedHeaders == null) + { + throw new ArgumentNullException(nameof(exposedHeaders)); + } + + AllowedOrigins = allowedOrigins; + AllowedMethods = allowedMethods; + AllowedHeaders = allowedHeaders; + ExposedHeaders = exposedHeaders; + MaxAgeInSeconds = maxAgeInSeconds; + } + + /// The origin domains that are permitted to make a request against the storage service via CORS. The origin domain is the domain from which the request originates. Note that the origin must be an exact case-sensitive match with the origin that the user age sends to the service. You can also use the wildcard character '*' to allow all origin domains to make requests via CORS. + public string AllowedOrigins { get; } + /// The methods (HTTP request verbs) that the origin domain may use for a CORS request. (comma separated). + public string AllowedMethods { get; } + /// the request headers that the origin domain may specify on the CORS request. + public string AllowedHeaders { get; } + /// The response headers that may be sent in the response to the CORS request and exposed by the browser to the request issuer. + public string ExposedHeaders { get; } + /// The maximum amount time that a browser should cache the preflight OPTIONS request. + public int MaxAgeInSeconds { get; } + } +} diff --git a/sdk/tables/Azure.Data.Tables/src/Generated/Models/GeoReplication.Serialization.cs b/sdk/tables/Azure.Data.Tables/src/Generated/Models/GeoReplication.Serialization.cs new file mode 100644 index 000000000000..9f62b14a6b0f --- /dev/null +++ b/sdk/tables/Azure.Data.Tables/src/Generated/Models/GeoReplication.Serialization.cs @@ -0,0 +1,31 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Xml.Linq; +using Azure.Core; + +namespace Azure.Data.Tables.Models +{ + public partial class GeoReplication + { + internal static GeoReplication DeserializeGeoReplication(XElement element) + { + GeoReplicationStatusType status = default; + DateTimeOffset lastSyncTime = default; + if (element.Element("Status") is XElement statusElement) + { + status = new GeoReplicationStatusType(statusElement.Value); + } + if (element.Element("LastSyncTime") is XElement lastSyncTimeElement) + { + lastSyncTime = lastSyncTimeElement.GetDateTimeOffsetValue("R"); + } + return new GeoReplication(status, lastSyncTime); + } + } +} diff --git a/sdk/tables/Azure.Data.Tables/src/Generated/Models/GeoReplication.cs b/sdk/tables/Azure.Data.Tables/src/Generated/Models/GeoReplication.cs new file mode 100644 index 000000000000..edfe7a9ba2d1 --- /dev/null +++ b/sdk/tables/Azure.Data.Tables/src/Generated/Models/GeoReplication.cs @@ -0,0 +1,29 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; + +namespace Azure.Data.Tables.Models +{ + /// The GeoReplication. + public partial class GeoReplication + { + /// Initializes a new instance of GeoReplication. + /// The status of the secondary location. + /// A GMT date/time value, to the second. All primary writes preceding this value are guaranteed to be available for read operations at the secondary. Primary writes after this point in time may or may not be available for reads. + internal GeoReplication(GeoReplicationStatusType status, DateTimeOffset lastSyncTime) + { + Status = status; + LastSyncTime = lastSyncTime; + } + + /// The status of the secondary location. + public GeoReplicationStatusType Status { get; } + /// A GMT date/time value, to the second. All primary writes preceding this value are guaranteed to be available for read operations at the secondary. Primary writes after this point in time may or may not be available for reads. + public DateTimeOffset LastSyncTime { get; } + } +} diff --git a/sdk/tables/Azure.Data.Tables/src/Generated/Models/GeoReplicationStatusType.cs b/sdk/tables/Azure.Data.Tables/src/Generated/Models/GeoReplicationStatusType.cs new file mode 100644 index 000000000000..dc2869409cfd --- /dev/null +++ b/sdk/tables/Azure.Data.Tables/src/Generated/Models/GeoReplicationStatusType.cs @@ -0,0 +1,53 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ComponentModel; + +namespace Azure.Data.Tables.Models +{ + /// The status of the secondary location. + public readonly partial struct GeoReplicationStatusType : IEquatable + { + private readonly string _value; + + /// Determines if two values are the same. + public GeoReplicationStatusType(string value) + { + _value = value ?? throw new ArgumentNullException(nameof(value)); + } + + private const string LiveValue = "live"; + private const string BootstrapValue = "bootstrap"; + private const string UnavailableValue = "unavailable"; + + /// live. + public static GeoReplicationStatusType Live { get; } = new GeoReplicationStatusType(LiveValue); + /// bootstrap. + public static GeoReplicationStatusType Bootstrap { get; } = new GeoReplicationStatusType(BootstrapValue); + /// unavailable. + public static GeoReplicationStatusType Unavailable { get; } = new GeoReplicationStatusType(UnavailableValue); + /// Determines if two values are the same. + public static bool operator ==(GeoReplicationStatusType left, GeoReplicationStatusType right) => left.Equals(right); + /// Determines if two values are not the same. + public static bool operator !=(GeoReplicationStatusType left, GeoReplicationStatusType right) => !left.Equals(right); + /// Converts a string to a . + public static implicit operator GeoReplicationStatusType(string value) => new GeoReplicationStatusType(value); + + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public override bool Equals(object obj) => obj is GeoReplicationStatusType other && Equals(other); + /// + public bool Equals(GeoReplicationStatusType other) => string.Equals(_value, other._value, StringComparison.InvariantCultureIgnoreCase); + + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public override int GetHashCode() => _value?.GetHashCode() ?? 0; + /// + public override string ToString() => _value; + } +} diff --git a/sdk/tables/Azure.Data.Tables/src/Generated/Models/LoggingSettings.Serialization.cs b/sdk/tables/Azure.Data.Tables/src/Generated/Models/LoggingSettings.Serialization.cs new file mode 100644 index 000000000000..bbe6cf7a245c --- /dev/null +++ b/sdk/tables/Azure.Data.Tables/src/Generated/Models/LoggingSettings.Serialization.cs @@ -0,0 +1,65 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System.Xml; +using System.Xml.Linq; +using Azure.Core; + +namespace Azure.Data.Tables.Models +{ + public partial class LoggingSettings : IXmlSerializable + { + void IXmlSerializable.Write(XmlWriter writer, string nameHint) + { + writer.WriteStartElement(nameHint ?? "Logging"); + writer.WriteStartElement("Version"); + writer.WriteValue(Version); + writer.WriteEndElement(); + writer.WriteStartElement("Delete"); + writer.WriteValue(Delete); + writer.WriteEndElement(); + writer.WriteStartElement("Read"); + writer.WriteValue(Read); + writer.WriteEndElement(); + writer.WriteStartElement("Write"); + writer.WriteValue(Write); + writer.WriteEndElement(); + writer.WriteObjectValue(RetentionPolicy, "RetentionPolicy"); + writer.WriteEndElement(); + } + + internal static LoggingSettings DeserializeLoggingSettings(XElement element) + { + string version = default; + bool delete = default; + bool read = default; + bool write = default; + RetentionPolicy retentionPolicy = default; + if (element.Element("Version") is XElement versionElement) + { + version = (string)versionElement; + } + if (element.Element("Delete") is XElement deleteElement) + { + delete = (bool)deleteElement; + } + if (element.Element("Read") is XElement readElement) + { + read = (bool)readElement; + } + if (element.Element("Write") is XElement writeElement) + { + write = (bool)writeElement; + } + if (element.Element("RetentionPolicy") is XElement retentionPolicyElement) + { + retentionPolicy = RetentionPolicy.DeserializeRetentionPolicy(retentionPolicyElement); + } + return new LoggingSettings(version, delete, read, write, retentionPolicy); + } + } +} diff --git a/sdk/tables/Azure.Data.Tables/src/Generated/Models/LoggingSettings.cs b/sdk/tables/Azure.Data.Tables/src/Generated/Models/LoggingSettings.cs new file mode 100644 index 000000000000..cf128a52ebcc --- /dev/null +++ b/sdk/tables/Azure.Data.Tables/src/Generated/Models/LoggingSettings.cs @@ -0,0 +1,50 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; + +namespace Azure.Data.Tables.Models +{ + /// Azure Analytics Logging settings. + public partial class LoggingSettings + { + /// Initializes a new instance of LoggingSettings. + /// The version of Storage Analytics to configure. + /// Indicates whether all delete requests should be logged. + /// Indicates whether all read requests should be logged. + /// Indicates whether all write requests should be logged. + /// the retention policy. + public LoggingSettings(string version, bool delete, bool read, bool write, RetentionPolicy retentionPolicy) + { + if (version == null) + { + throw new ArgumentNullException(nameof(version)); + } + if (retentionPolicy == null) + { + throw new ArgumentNullException(nameof(retentionPolicy)); + } + + Version = version; + Delete = delete; + Read = read; + Write = write; + RetentionPolicy = retentionPolicy; + } + + /// The version of Storage Analytics to configure. + public string Version { get; } + /// Indicates whether all delete requests should be logged. + public bool Delete { get; } + /// Indicates whether all read requests should be logged. + public bool Read { get; } + /// Indicates whether all write requests should be logged. + public bool Write { get; } + /// the retention policy. + public RetentionPolicy RetentionPolicy { get; } + } +} diff --git a/sdk/tables/Azure.Data.Tables/src/Generated/Models/OdataMetadataFormat.cs b/sdk/tables/Azure.Data.Tables/src/Generated/Models/OdataMetadataFormat.cs new file mode 100644 index 000000000000..6244114e375f --- /dev/null +++ b/sdk/tables/Azure.Data.Tables/src/Generated/Models/OdataMetadataFormat.cs @@ -0,0 +1,53 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ComponentModel; + +namespace Azure.Data.Tables.Models +{ + /// The Enum0. + public readonly partial struct OdataMetadataFormat : IEquatable + { + private readonly string _value; + + /// Determines if two values are the same. + public OdataMetadataFormat(string value) + { + _value = value ?? throw new ArgumentNullException(nameof(value)); + } + + private const string ApplicationJsonOdataNometadataValue = "application/json;odata=nometadata"; + private const string ApplicationJsonOdataMinimalmetadataValue = "application/json;odata=minimalmetadata"; + private const string ApplicationJsonOdataFullmetadataValue = "application/json;odata=fullmetadata"; + + /// application/json;odata=nometadata. + public static OdataMetadataFormat ApplicationJsonOdataNometadata { get; } = new OdataMetadataFormat(ApplicationJsonOdataNometadataValue); + /// application/json;odata=minimalmetadata. + public static OdataMetadataFormat ApplicationJsonOdataMinimalmetadata { get; } = new OdataMetadataFormat(ApplicationJsonOdataMinimalmetadataValue); + /// application/json;odata=fullmetadata. + public static OdataMetadataFormat ApplicationJsonOdataFullmetadata { get; } = new OdataMetadataFormat(ApplicationJsonOdataFullmetadataValue); + /// Determines if two values are the same. + public static bool operator ==(OdataMetadataFormat left, OdataMetadataFormat right) => left.Equals(right); + /// Determines if two values are not the same. + public static bool operator !=(OdataMetadataFormat left, OdataMetadataFormat right) => !left.Equals(right); + /// Converts a string to a . + public static implicit operator OdataMetadataFormat(string value) => new OdataMetadataFormat(value); + + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public override bool Equals(object obj) => obj is OdataMetadataFormat other && Equals(other); + /// + public bool Equals(OdataMetadataFormat other) => string.Equals(_value, other._value, StringComparison.InvariantCultureIgnoreCase); + + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public override int GetHashCode() => _value?.GetHashCode() ?? 0; + /// + public override string ToString() => _value; + } +} diff --git a/sdk/tables/Azure.Data.Tables/src/Generated/Models/QueryOptions.cs b/sdk/tables/Azure.Data.Tables/src/Generated/Models/QueryOptions.cs new file mode 100644 index 000000000000..f4b7a50c5258 --- /dev/null +++ b/sdk/tables/Azure.Data.Tables/src/Generated/Models/QueryOptions.cs @@ -0,0 +1,40 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +namespace Azure.Data.Tables.Models +{ + /// Parameter group. + public partial class QueryOptions + { + /// Initializes a new instance of QueryOptions. + public QueryOptions() + { + } + + /// Initializes a new instance of QueryOptions. + /// Specifies the media type for the response. + /// Maximum number of records to return. + /// Select expression using OData notation. Limits the columns on each record to just those requested, e.g. "$select=PolicyAssignmentId, ResourceId". + /// OData filter expression. + internal QueryOptions(OdataMetadataFormat? format, int? top, string select, string filter) + { + Format = format; + Top = top; + Select = select; + Filter = filter; + } + + /// Specifies the media type for the response. + public OdataMetadataFormat? Format { get; set; } + /// Maximum number of records to return. + public int? Top { get; set; } + /// Select expression using OData notation. Limits the columns on each record to just those requested, e.g. "$select=PolicyAssignmentId, ResourceId". + public string Select { get; set; } + /// OData filter expression. + public string Filter { get; set; } + } +} diff --git a/sdk/tables/Azure.Data.Tables/src/Generated/Models/RequestMetrics.Serialization.cs b/sdk/tables/Azure.Data.Tables/src/Generated/Models/RequestMetrics.Serialization.cs new file mode 100644 index 000000000000..f0da8f675416 --- /dev/null +++ b/sdk/tables/Azure.Data.Tables/src/Generated/Models/RequestMetrics.Serialization.cs @@ -0,0 +1,66 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System.Xml; +using System.Xml.Linq; +using Azure.Core; + +namespace Azure.Data.Tables.Models +{ + public partial class RequestMetrics : IXmlSerializable + { + void IXmlSerializable.Write(XmlWriter writer, string nameHint) + { + writer.WriteStartElement(nameHint ?? "Metrics"); + if (Version != null) + { + writer.WriteStartElement("Version"); + writer.WriteValue(Version); + writer.WriteEndElement(); + } + writer.WriteStartElement("Enabled"); + writer.WriteValue(Enabled); + writer.WriteEndElement(); + if (IncludeAPIs != null) + { + writer.WriteStartElement("IncludeAPIs"); + writer.WriteValue(IncludeAPIs.Value); + writer.WriteEndElement(); + } + if (RetentionPolicy != null) + { + writer.WriteObjectValue(RetentionPolicy, "RetentionPolicy"); + } + writer.WriteEndElement(); + } + + internal static RequestMetrics DeserializeRequestMetrics(XElement element) + { + string version = default; + bool enabled = default; + bool? includeAPIs = default; + RetentionPolicy retentionPolicy = default; + if (element.Element("Version") is XElement versionElement) + { + version = (string)versionElement; + } + if (element.Element("Enabled") is XElement enabledElement) + { + enabled = (bool)enabledElement; + } + if (element.Element("IncludeAPIs") is XElement includeAPIsElement) + { + includeAPIs = (bool?)includeAPIsElement; + } + if (element.Element("RetentionPolicy") is XElement retentionPolicyElement) + { + retentionPolicy = RetentionPolicy.DeserializeRetentionPolicy(retentionPolicyElement); + } + return new RequestMetrics(version, enabled, includeAPIs, retentionPolicy); + } + } +} diff --git a/sdk/tables/Azure.Data.Tables/src/Generated/Models/RequestMetrics.cs b/sdk/tables/Azure.Data.Tables/src/Generated/Models/RequestMetrics.cs new file mode 100644 index 000000000000..201c45fa6789 --- /dev/null +++ b/sdk/tables/Azure.Data.Tables/src/Generated/Models/RequestMetrics.cs @@ -0,0 +1,42 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +namespace Azure.Data.Tables.Models +{ + /// The Metrics. + public partial class RequestMetrics + { + /// Initializes a new instance of RequestMetrics. + /// Indicates whether metrics are enabled for the Queue service. + public RequestMetrics(bool enabled) + { + Enabled = enabled; + } + + /// Initializes a new instance of RequestMetrics. + /// The version of Storage Analytics to configure. + /// Indicates whether metrics are enabled for the Queue service. + /// Indicates whether metrics should generate summary statistics for called API operations. + /// the retention policy. + internal RequestMetrics(string version, bool enabled, bool? includeAPIs, RetentionPolicy retentionPolicy) + { + Version = version; + Enabled = enabled; + IncludeAPIs = includeAPIs; + RetentionPolicy = retentionPolicy; + } + + /// The version of Storage Analytics to configure. + public string Version { get; set; } + /// Indicates whether metrics are enabled for the Queue service. + public bool Enabled { get; } + /// Indicates whether metrics should generate summary statistics for called API operations. + public bool? IncludeAPIs { get; set; } + /// the retention policy. + public RetentionPolicy RetentionPolicy { get; set; } + } +} diff --git a/sdk/tables/Azure.Data.Tables/src/Generated/Models/RetentionPolicy.Serialization.cs b/sdk/tables/Azure.Data.Tables/src/Generated/Models/RetentionPolicy.Serialization.cs new file mode 100644 index 000000000000..d68e7468982d --- /dev/null +++ b/sdk/tables/Azure.Data.Tables/src/Generated/Models/RetentionPolicy.Serialization.cs @@ -0,0 +1,46 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System.Xml; +using System.Xml.Linq; +using Azure.Core; + +namespace Azure.Data.Tables.Models +{ + public partial class RetentionPolicy : IXmlSerializable + { + void IXmlSerializable.Write(XmlWriter writer, string nameHint) + { + writer.WriteStartElement(nameHint ?? "RetentionPolicy"); + writer.WriteStartElement("Enabled"); + writer.WriteValue(Enabled); + writer.WriteEndElement(); + if (Days != null) + { + writer.WriteStartElement("Days"); + writer.WriteValue(Days.Value); + writer.WriteEndElement(); + } + writer.WriteEndElement(); + } + + internal static RetentionPolicy DeserializeRetentionPolicy(XElement element) + { + bool enabled = default; + int? days = default; + if (element.Element("Enabled") is XElement enabledElement) + { + enabled = (bool)enabledElement; + } + if (element.Element("Days") is XElement daysElement) + { + days = (int?)daysElement; + } + return new RetentionPolicy(enabled, days); + } + } +} diff --git a/sdk/tables/Azure.Data.Tables/src/Generated/Models/RetentionPolicy.cs b/sdk/tables/Azure.Data.Tables/src/Generated/Models/RetentionPolicy.cs new file mode 100644 index 000000000000..3b5ba27bd3c3 --- /dev/null +++ b/sdk/tables/Azure.Data.Tables/src/Generated/Models/RetentionPolicy.cs @@ -0,0 +1,34 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +namespace Azure.Data.Tables.Models +{ + /// the retention policy. + public partial class RetentionPolicy + { + /// Initializes a new instance of RetentionPolicy. + /// Indicates whether a retention policy is enabled for the storage service. + public RetentionPolicy(bool enabled) + { + Enabled = enabled; + } + + /// Initializes a new instance of RetentionPolicy. + /// Indicates whether a retention policy is enabled for the storage service. + /// Indicates the number of days that metrics or logging or soft-deleted data should be retained. All data older than this value will be deleted. + internal RetentionPolicy(bool enabled, int? days) + { + Enabled = enabled; + Days = days; + } + + /// Indicates whether a retention policy is enabled for the storage service. + public bool Enabled { get; } + /// Indicates the number of days that metrics or logging or soft-deleted data should be retained. All data older than this value will be deleted. + public int? Days { get; set; } + } +} diff --git a/sdk/tables/Azure.Data.Tables/src/Generated/Models/SignedIdentifier.Serialization.cs b/sdk/tables/Azure.Data.Tables/src/Generated/Models/SignedIdentifier.Serialization.cs new file mode 100644 index 000000000000..b35e1ee75ca6 --- /dev/null +++ b/sdk/tables/Azure.Data.Tables/src/Generated/Models/SignedIdentifier.Serialization.cs @@ -0,0 +1,41 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System.Xml; +using System.Xml.Linq; +using Azure.Core; + +namespace Azure.Data.Tables.Models +{ + public partial class SignedIdentifier : IXmlSerializable + { + void IXmlSerializable.Write(XmlWriter writer, string nameHint) + { + writer.WriteStartElement(nameHint ?? "SignedIdentifier"); + writer.WriteStartElement("Id"); + writer.WriteValue(Id); + writer.WriteEndElement(); + writer.WriteObjectValue(AccessPolicy, "AccessPolicy"); + writer.WriteEndElement(); + } + + internal static SignedIdentifier DeserializeSignedIdentifier(XElement element) + { + string id = default; + AccessPolicy accessPolicy = default; + if (element.Element("Id") is XElement idElement) + { + id = (string)idElement; + } + if (element.Element("AccessPolicy") is XElement accessPolicyElement) + { + accessPolicy = AccessPolicy.DeserializeAccessPolicy(accessPolicyElement); + } + return new SignedIdentifier(id, accessPolicy); + } + } +} diff --git a/sdk/tables/Azure.Data.Tables/src/Generated/Models/SignedIdentifier.cs b/sdk/tables/Azure.Data.Tables/src/Generated/Models/SignedIdentifier.cs new file mode 100644 index 000000000000..db148c60a473 --- /dev/null +++ b/sdk/tables/Azure.Data.Tables/src/Generated/Models/SignedIdentifier.cs @@ -0,0 +1,38 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; + +namespace Azure.Data.Tables.Models +{ + /// signed identifier. + public partial class SignedIdentifier + { + /// Initializes a new instance of SignedIdentifier. + /// a unique id. + /// The access policy. + public SignedIdentifier(string id, AccessPolicy accessPolicy) + { + if (id == null) + { + throw new ArgumentNullException(nameof(id)); + } + if (accessPolicy == null) + { + throw new ArgumentNullException(nameof(accessPolicy)); + } + + Id = id; + AccessPolicy = accessPolicy; + } + + /// a unique id. + public string Id { get; } + /// The access policy. + public AccessPolicy AccessPolicy { get; } + } +} diff --git a/sdk/tables/Azure.Data.Tables/src/Generated/Models/StorageError.Serialization.cs b/sdk/tables/Azure.Data.Tables/src/Generated/Models/StorageError.Serialization.cs new file mode 100644 index 000000000000..741a655cf7a0 --- /dev/null +++ b/sdk/tables/Azure.Data.Tables/src/Generated/Models/StorageError.Serialization.cs @@ -0,0 +1,44 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System.Text.Json; +using System.Xml.Linq; +using Azure.Core; + +namespace Azure.Data.Tables.Models +{ + public partial class StorageError + { + internal static StorageError DeserializeStorageError(JsonElement element) + { + string message = default; + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("Message")) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + message = property.Value.GetString(); + continue; + } + } + return new StorageError(message); + } + + internal static StorageError DeserializeStorageError(XElement element) + { + string message = default; + if (element.Element("Message") is XElement messageElement) + { + message = (string)messageElement; + } + return new StorageError(message); + } + } +} diff --git a/sdk/tables/Azure.Data.Tables/src/Generated/Models/StorageError.cs b/sdk/tables/Azure.Data.Tables/src/Generated/Models/StorageError.cs new file mode 100644 index 000000000000..9319d458f120 --- /dev/null +++ b/sdk/tables/Azure.Data.Tables/src/Generated/Models/StorageError.cs @@ -0,0 +1,27 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +namespace Azure.Data.Tables.Models +{ + /// The StorageError. + public partial class StorageError + { + /// Initializes a new instance of StorageError. + internal StorageError() + { + } + + /// Initializes a new instance of StorageError. + /// . + internal StorageError(string message) + { + Message = message; + } + + public string Message { get; } + } +} diff --git a/sdk/tables/Azure.Data.Tables/src/Generated/Models/StorageServiceProperties.Serialization.cs b/sdk/tables/Azure.Data.Tables/src/Generated/Models/StorageServiceProperties.Serialization.cs new file mode 100644 index 000000000000..5fe2ded64920 --- /dev/null +++ b/sdk/tables/Azure.Data.Tables/src/Generated/Models/StorageServiceProperties.Serialization.cs @@ -0,0 +1,74 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System.Collections.Generic; +using System.Xml; +using System.Xml.Linq; +using Azure.Core; + +namespace Azure.Data.Tables.Models +{ + public partial class StorageServiceProperties : IXmlSerializable + { + void IXmlSerializable.Write(XmlWriter writer, string nameHint) + { + writer.WriteStartElement(nameHint ?? "StorageServiceProperties"); + if (Logging != null) + { + writer.WriteObjectValue(Logging, "Logging"); + } + if (HourMetrics != null) + { + writer.WriteObjectValue(HourMetrics, "HourMetrics"); + } + if (MinuteMetrics != null) + { + writer.WriteObjectValue(MinuteMetrics, "MinuteMetrics"); + } + if (Cors != null) + { + writer.WriteStartElement("Cors"); + foreach (var item in Cors) + { + writer.WriteObjectValue(item, "CorsRule"); + } + writer.WriteEndElement(); + } + writer.WriteEndElement(); + } + + internal static StorageServiceProperties DeserializeStorageServiceProperties(XElement element) + { + LoggingSettings logging = default; + RequestMetrics hourMetrics = default; + RequestMetrics minuteMetrics = default; + IList cors = default; + if (element.Element("Logging") is XElement loggingElement) + { + logging = LoggingSettings.DeserializeLoggingSettings(loggingElement); + } + if (element.Element("HourMetrics") is XElement hourMetricsElement) + { + hourMetrics = RequestMetrics.DeserializeRequestMetrics(hourMetricsElement); + } + if (element.Element("MinuteMetrics") is XElement minuteMetricsElement) + { + minuteMetrics = RequestMetrics.DeserializeRequestMetrics(minuteMetricsElement); + } + if (element.Element("Cors") is XElement corsElement) + { + var array = new List(); + foreach (var e in corsElement.Elements("CorsRule")) + { + array.Add(CorsRule.DeserializeCorsRule(e)); + } + cors = array; + } + return new StorageServiceProperties(logging, hourMetrics, minuteMetrics, cors); + } + } +} diff --git a/sdk/tables/Azure.Data.Tables/src/Generated/Models/StorageServiceProperties.cs b/sdk/tables/Azure.Data.Tables/src/Generated/Models/StorageServiceProperties.cs new file mode 100644 index 000000000000..3ed759505892 --- /dev/null +++ b/sdk/tables/Azure.Data.Tables/src/Generated/Models/StorageServiceProperties.cs @@ -0,0 +1,42 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System.Collections.Generic; + +namespace Azure.Data.Tables.Models +{ + /// Storage Service Properties. + public partial class StorageServiceProperties + { + /// Initializes a new instance of StorageServiceProperties. + public StorageServiceProperties() + { + } + + /// Initializes a new instance of StorageServiceProperties. + /// Azure Analytics Logging settings. + /// A summary of request statistics grouped by API in hourly aggregates for queues. + /// a summary of request statistics grouped by API in minute aggregates for queues. + /// The set of CORS rules. + internal StorageServiceProperties(LoggingSettings logging, RequestMetrics hourMetrics, RequestMetrics minuteMetrics, IList cors) + { + Logging = logging; + HourMetrics = hourMetrics; + MinuteMetrics = minuteMetrics; + Cors = cors; + } + + /// Azure Analytics Logging settings. + public LoggingSettings Logging { get; set; } + /// A summary of request statistics grouped by API in hourly aggregates for queues. + public RequestMetrics HourMetrics { get; set; } + /// a summary of request statistics grouped by API in minute aggregates for queues. + public RequestMetrics MinuteMetrics { get; set; } + /// The set of CORS rules. + public IList Cors { get; set; } + } +} diff --git a/sdk/tables/Azure.Data.Tables/src/Generated/Models/StorageServiceStats.Serialization.cs b/sdk/tables/Azure.Data.Tables/src/Generated/Models/StorageServiceStats.Serialization.cs new file mode 100644 index 000000000000..006226a024d1 --- /dev/null +++ b/sdk/tables/Azure.Data.Tables/src/Generated/Models/StorageServiceStats.Serialization.cs @@ -0,0 +1,25 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System.Xml.Linq; +using Azure.Core; + +namespace Azure.Data.Tables.Models +{ + public partial class StorageServiceStats + { + internal static StorageServiceStats DeserializeStorageServiceStats(XElement element) + { + GeoReplication geoReplication = default; + if (element.Element("GeoReplication") is XElement geoReplicationElement) + { + geoReplication = GeoReplication.DeserializeGeoReplication(geoReplicationElement); + } + return new StorageServiceStats(geoReplication); + } + } +} diff --git a/sdk/tables/Azure.Data.Tables/src/Generated/Models/StorageServiceStats.cs b/sdk/tables/Azure.Data.Tables/src/Generated/Models/StorageServiceStats.cs new file mode 100644 index 000000000000..a2f4e8a8fdce --- /dev/null +++ b/sdk/tables/Azure.Data.Tables/src/Generated/Models/StorageServiceStats.cs @@ -0,0 +1,28 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +namespace Azure.Data.Tables.Models +{ + /// Stats for the storage service. + public partial class StorageServiceStats + { + /// Initializes a new instance of StorageServiceStats. + internal StorageServiceStats() + { + } + + /// Initializes a new instance of StorageServiceStats. + /// Geo-Replication information for the Secondary Storage Service. + internal StorageServiceStats(GeoReplication geoReplication) + { + GeoReplication = geoReplication; + } + + /// Geo-Replication information for the Secondary Storage Service. + public GeoReplication GeoReplication { get; } + } +} diff --git a/sdk/tables/Azure.Data.Tables/src/Generated/Models/TableEntityQueryResponse.Serialization.cs b/sdk/tables/Azure.Data.Tables/src/Generated/Models/TableEntityQueryResponse.Serialization.cs new file mode 100644 index 000000000000..8eb765af0a55 --- /dev/null +++ b/sdk/tables/Azure.Data.Tables/src/Generated/Models/TableEntityQueryResponse.Serialization.cs @@ -0,0 +1,68 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System.Collections.Generic; +using System.Text.Json; +using Azure.Core; + +namespace Azure.Data.Tables.Models +{ + public partial class TableEntityQueryResponse + { + internal static TableEntityQueryResponse DeserializeTableEntityQueryResponse(JsonElement element) + { + string odataMetadata = default; + IReadOnlyList> value = default; + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("odata.metadata")) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + odataMetadata = property.Value.GetString(); + continue; + } + if (property.NameEquals("value")) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + List> array = new List>(); + foreach (var item in property.Value.EnumerateArray()) + { + if (item.ValueKind == JsonValueKind.Null) + { + array.Add(null); + } + else + { + Dictionary dictionary = new Dictionary(); + foreach (var property0 in item.EnumerateObject()) + { + if (property0.Value.ValueKind == JsonValueKind.Null) + { + dictionary.Add(property0.Name, null); + } + else + { + dictionary.Add(property0.Name, property0.Value.GetObject()); + } + } + array.Add(dictionary); + } + } + value = array; + continue; + } + } + return new TableEntityQueryResponse(odataMetadata, value); + } + } +} diff --git a/sdk/tables/Azure.Data.Tables/src/Generated/Models/TableEntityQueryResponse.cs b/sdk/tables/Azure.Data.Tables/src/Generated/Models/TableEntityQueryResponse.cs new file mode 100644 index 000000000000..527d0c5ab5f3 --- /dev/null +++ b/sdk/tables/Azure.Data.Tables/src/Generated/Models/TableEntityQueryResponse.cs @@ -0,0 +1,34 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System.Collections.Generic; + +namespace Azure.Data.Tables.Models +{ + /// The properties for the table entity query response. + public partial class TableEntityQueryResponse + { + /// Initializes a new instance of TableEntityQueryResponse. + internal TableEntityQueryResponse() + { + } + + /// Initializes a new instance of TableEntityQueryResponse. + /// The metadata response of the table. + /// List of table entities. + internal TableEntityQueryResponse(string odataMetadata, IReadOnlyList> value) + { + OdataMetadata = odataMetadata; + Value = value; + } + + /// The metadata response of the table. + public string OdataMetadata { get; } + /// List of table entities. + public IReadOnlyList> Value { get; } + } +} diff --git a/sdk/tables/Azure.Data.Tables/src/Generated/Models/TableProperties.Serialization.cs b/sdk/tables/Azure.Data.Tables/src/Generated/Models/TableProperties.Serialization.cs new file mode 100644 index 000000000000..c8e3b17d64e2 --- /dev/null +++ b/sdk/tables/Azure.Data.Tables/src/Generated/Models/TableProperties.Serialization.cs @@ -0,0 +1,26 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System.Text.Json; +using Azure.Core; + +namespace Azure.Data.Tables.Models +{ + public partial class TableProperties : IUtf8JsonSerializable + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) + { + writer.WriteStartObject(); + if (TableName != null) + { + writer.WritePropertyName("TableName"); + writer.WriteStringValue(TableName); + } + writer.WriteEndObject(); + } + } +} diff --git a/sdk/tables/Azure.Data.Tables/src/Generated/Models/TableProperties.cs b/sdk/tables/Azure.Data.Tables/src/Generated/Models/TableProperties.cs new file mode 100644 index 000000000000..56569153f53b --- /dev/null +++ b/sdk/tables/Azure.Data.Tables/src/Generated/Models/TableProperties.cs @@ -0,0 +1,28 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +namespace Azure.Data.Tables.Models +{ + /// The properties for creating a table. + public partial class TableProperties + { + /// Initializes a new instance of TableProperties. + public TableProperties() + { + } + + /// Initializes a new instance of TableProperties. + /// The name of the table to create. + internal TableProperties(string tableName) + { + TableName = tableName; + } + + /// The name of the table to create. + public string TableName { get; set; } + } +} diff --git a/sdk/tables/Azure.Data.Tables/src/Generated/Models/TableQueryResponse.Serialization.cs b/sdk/tables/Azure.Data.Tables/src/Generated/Models/TableQueryResponse.Serialization.cs new file mode 100644 index 000000000000..e01d2e2d9c25 --- /dev/null +++ b/sdk/tables/Azure.Data.Tables/src/Generated/Models/TableQueryResponse.Serialization.cs @@ -0,0 +1,56 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System.Collections.Generic; +using System.Text.Json; +using Azure.Core; + +namespace Azure.Data.Tables.Models +{ + public partial class TableQueryResponse + { + internal static TableQueryResponse DeserializeTableQueryResponse(JsonElement element) + { + string odataMetadata = default; + IReadOnlyList value = default; + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("odata.metadata")) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + odataMetadata = property.Value.GetString(); + continue; + } + if (property.NameEquals("value")) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + List array = new List(); + foreach (var item in property.Value.EnumerateArray()) + { + if (item.ValueKind == JsonValueKind.Null) + { + array.Add(null); + } + else + { + array.Add(TableResponseProperties.DeserializeTableResponseProperties(item)); + } + } + value = array; + continue; + } + } + return new TableQueryResponse(odataMetadata, value); + } + } +} diff --git a/sdk/tables/Azure.Data.Tables/src/Generated/Models/TableQueryResponse.cs b/sdk/tables/Azure.Data.Tables/src/Generated/Models/TableQueryResponse.cs new file mode 100644 index 000000000000..20385b32bc55 --- /dev/null +++ b/sdk/tables/Azure.Data.Tables/src/Generated/Models/TableQueryResponse.cs @@ -0,0 +1,34 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System.Collections.Generic; + +namespace Azure.Data.Tables.Models +{ + /// The properties for the table query response. + public partial class TableQueryResponse + { + /// Initializes a new instance of TableQueryResponse. + internal TableQueryResponse() + { + } + + /// Initializes a new instance of TableQueryResponse. + /// The metadata response of the table. + /// List of tables. + internal TableQueryResponse(string odataMetadata, IReadOnlyList value) + { + OdataMetadata = odataMetadata; + Value = value; + } + + /// The metadata response of the table. + public string OdataMetadata { get; } + /// List of tables. + public IReadOnlyList Value { get; } + } +} diff --git a/sdk/tables/Azure.Data.Tables/src/Generated/Models/TableResponse.Serialization.cs b/sdk/tables/Azure.Data.Tables/src/Generated/Models/TableResponse.Serialization.cs new file mode 100644 index 000000000000..85404913af0a --- /dev/null +++ b/sdk/tables/Azure.Data.Tables/src/Generated/Models/TableResponse.Serialization.cs @@ -0,0 +1,73 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System.Text.Json; +using Azure.Core; + +namespace Azure.Data.Tables.Models +{ + public partial class TableResponse + { + internal static TableResponse DeserializeTableResponse(JsonElement element) + { + string odataMetadata = default; + string tableName = default; + string odataType = default; + string odataId = default; + string odataEditLink = default; + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("odata.metadata")) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + odataMetadata = property.Value.GetString(); + continue; + } + if (property.NameEquals("TableName")) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + tableName = property.Value.GetString(); + continue; + } + if (property.NameEquals("odata.type")) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + odataType = property.Value.GetString(); + continue; + } + if (property.NameEquals("odata.id")) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + odataId = property.Value.GetString(); + continue; + } + if (property.NameEquals("odata.editLink")) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + odataEditLink = property.Value.GetString(); + continue; + } + } + return new TableResponse(tableName, odataType, odataId, odataEditLink, odataMetadata); + } + } +} diff --git a/sdk/tables/Azure.Data.Tables/src/Generated/Models/TableResponse.cs b/sdk/tables/Azure.Data.Tables/src/Generated/Models/TableResponse.cs new file mode 100644 index 000000000000..178b526f8d43 --- /dev/null +++ b/sdk/tables/Azure.Data.Tables/src/Generated/Models/TableResponse.cs @@ -0,0 +1,32 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +namespace Azure.Data.Tables.Models +{ + /// The response for a single table. + public partial class TableResponse : TableResponseProperties + { + /// Initializes a new instance of TableResponse. + internal TableResponse() + { + } + + /// Initializes a new instance of TableResponse. + /// The name of the table. + /// The odata type of the table. + /// The id of the table. + /// The edit link of the table. + /// The metadata response of the table. + internal TableResponse(string tableName, string odataType, string odataId, string odataEditLink, string odataMetadata) : base(tableName, odataType, odataId, odataEditLink) + { + OdataMetadata = odataMetadata; + } + + /// The metadata response of the table. + public string OdataMetadata { get; } + } +} diff --git a/sdk/tables/Azure.Data.Tables/src/Generated/Models/TableResponseProperties.Serialization.cs b/sdk/tables/Azure.Data.Tables/src/Generated/Models/TableResponseProperties.Serialization.cs new file mode 100644 index 000000000000..5b9e87e69e4c --- /dev/null +++ b/sdk/tables/Azure.Data.Tables/src/Generated/Models/TableResponseProperties.Serialization.cs @@ -0,0 +1,63 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System.Text.Json; +using Azure.Core; + +namespace Azure.Data.Tables.Models +{ + public partial class TableResponseProperties + { + internal static TableResponseProperties DeserializeTableResponseProperties(JsonElement element) + { + string tableName = default; + string odataType = default; + string odataId = default; + string odataEditLink = default; + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("TableName")) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + tableName = property.Value.GetString(); + continue; + } + if (property.NameEquals("odata.type")) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + odataType = property.Value.GetString(); + continue; + } + if (property.NameEquals("odata.id")) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + odataId = property.Value.GetString(); + continue; + } + if (property.NameEquals("odata.editLink")) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + odataEditLink = property.Value.GetString(); + continue; + } + } + return new TableResponseProperties(tableName, odataType, odataId, odataEditLink); + } + } +} diff --git a/sdk/tables/Azure.Data.Tables/src/Generated/Models/TableResponseProperties.cs b/sdk/tables/Azure.Data.Tables/src/Generated/Models/TableResponseProperties.cs new file mode 100644 index 000000000000..85ab80f2460d --- /dev/null +++ b/sdk/tables/Azure.Data.Tables/src/Generated/Models/TableResponseProperties.cs @@ -0,0 +1,40 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +namespace Azure.Data.Tables.Models +{ + /// The properties for the table response. + public partial class TableResponseProperties + { + /// Initializes a new instance of TableResponseProperties. + internal TableResponseProperties() + { + } + + /// Initializes a new instance of TableResponseProperties. + /// The name of the table. + /// The odata type of the table. + /// The id of the table. + /// The edit link of the table. + internal TableResponseProperties(string tableName, string odataType, string odataId, string odataEditLink) + { + TableName = tableName; + OdataType = odataType; + OdataId = odataId; + OdataEditLink = odataEditLink; + } + + /// The name of the table. + public string TableName { get; } + /// The odata type of the table. + public string OdataType { get; } + /// The id of the table. + public string OdataId { get; } + /// The edit link of the table. + public string OdataEditLink { get; } + } +} diff --git a/sdk/tables/Azure.Data.Tables/src/Generated/Operations/ServiceClient.cs b/sdk/tables/Azure.Data.Tables/src/Generated/Operations/ServiceClient.cs new file mode 100644 index 000000000000..f90ef100cda2 --- /dev/null +++ b/sdk/tables/Azure.Data.Tables/src/Generated/Operations/ServiceClient.cs @@ -0,0 +1,89 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System.Threading; +using System.Threading.Tasks; +using Azure; +using Azure.Core.Pipeline; +using Azure.Data.Tables.Models; + +namespace Azure.Data.Tables +{ + internal partial class ServiceClient + { + private readonly ClientDiagnostics _clientDiagnostics; + private readonly HttpPipeline _pipeline; + internal ServiceRestClient RestClient { get; } + /// Initializes a new instance of ServiceClient for mocking. + protected ServiceClient() + { + } + /// Initializes a new instance of ServiceClient. + internal ServiceClient(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string url, string version = "2018-10-10") + { + RestClient = new ServiceRestClient(clientDiagnostics, pipeline, url, version); + _clientDiagnostics = clientDiagnostics; + _pipeline = pipeline; + } + + /// Sets properties for a storage account's Table service endpoint, including properties for Storage Analytics and CORS (Cross-Origin Resource Sharing) rules. + /// The StorageService properties. + /// The The timeout parameter is expressed in seconds. For more information, see <a href="https://docs.microsoft.com/en-us/rest/api/storageservices/setting-timeouts-for-queue-service-operations>Setting Timeouts for Queue Service Operations.</a>. + /// Provides a client-generated, opaque value with a 1 KB character limit that is recorded in the analytics logs when storage analytics logging is enabled. + /// The cancellation token to use. + public virtual async Task SetPropertiesAsync(StorageServiceProperties storageServiceProperties, int? timeout = null, string requestId = null, CancellationToken cancellationToken = default) + { + return (await RestClient.SetPropertiesAsync(storageServiceProperties, timeout, requestId, cancellationToken).ConfigureAwait(false)).GetRawResponse(); + } + + /// Sets properties for a storage account's Table service endpoint, including properties for Storage Analytics and CORS (Cross-Origin Resource Sharing) rules. + /// The StorageService properties. + /// The The timeout parameter is expressed in seconds. For more information, see <a href="https://docs.microsoft.com/en-us/rest/api/storageservices/setting-timeouts-for-queue-service-operations>Setting Timeouts for Queue Service Operations.</a>. + /// Provides a client-generated, opaque value with a 1 KB character limit that is recorded in the analytics logs when storage analytics logging is enabled. + /// The cancellation token to use. + public virtual Response SetProperties(StorageServiceProperties storageServiceProperties, int? timeout = null, string requestId = null, CancellationToken cancellationToken = default) + { + return RestClient.SetProperties(storageServiceProperties, timeout, requestId, cancellationToken).GetRawResponse(); + } + + /// gets the properties of a storage account's Table service, including properties for Storage Analytics and CORS (Cross-Origin Resource Sharing) rules. + /// The The timeout parameter is expressed in seconds. For more information, see <a href="https://docs.microsoft.com/en-us/rest/api/storageservices/setting-timeouts-for-queue-service-operations>Setting Timeouts for Queue Service Operations.</a>. + /// Provides a client-generated, opaque value with a 1 KB character limit that is recorded in the analytics logs when storage analytics logging is enabled. + /// The cancellation token to use. + public virtual async Task> GetPropertiesAsync(int? timeout = null, string requestId = null, CancellationToken cancellationToken = default) + { + return await RestClient.GetPropertiesAsync(timeout, requestId, cancellationToken).ConfigureAwait(false); + } + + /// gets the properties of a storage account's Table service, including properties for Storage Analytics and CORS (Cross-Origin Resource Sharing) rules. + /// The The timeout parameter is expressed in seconds. For more information, see <a href="https://docs.microsoft.com/en-us/rest/api/storageservices/setting-timeouts-for-queue-service-operations>Setting Timeouts for Queue Service Operations.</a>. + /// Provides a client-generated, opaque value with a 1 KB character limit that is recorded in the analytics logs when storage analytics logging is enabled. + /// The cancellation token to use. + public virtual Response GetProperties(int? timeout = null, string requestId = null, CancellationToken cancellationToken = default) + { + return RestClient.GetProperties(timeout, requestId, cancellationToken); + } + + /// Retrieves statistics related to replication for the Table service. It is only available on the secondary location endpoint when read-access geo-redundant replication is enabled for the storage account. + /// The The timeout parameter is expressed in seconds. For more information, see <a href="https://docs.microsoft.com/en-us/rest/api/storageservices/setting-timeouts-for-queue-service-operations>Setting Timeouts for Queue Service Operations.</a>. + /// Provides a client-generated, opaque value with a 1 KB character limit that is recorded in the analytics logs when storage analytics logging is enabled. + /// The cancellation token to use. + public virtual async Task> GetStatisticsAsync(int? timeout = null, string requestId = null, CancellationToken cancellationToken = default) + { + return await RestClient.GetStatisticsAsync(timeout, requestId, cancellationToken).ConfigureAwait(false); + } + + /// Retrieves statistics related to replication for the Table service. It is only available on the secondary location endpoint when read-access geo-redundant replication is enabled for the storage account. + /// The The timeout parameter is expressed in seconds. For more information, see <a href="https://docs.microsoft.com/en-us/rest/api/storageservices/setting-timeouts-for-queue-service-operations>Setting Timeouts for Queue Service Operations.</a>. + /// Provides a client-generated, opaque value with a 1 KB character limit that is recorded in the analytics logs when storage analytics logging is enabled. + /// The cancellation token to use. + public virtual Response GetStatistics(int? timeout = null, string requestId = null, CancellationToken cancellationToken = default) + { + return RestClient.GetStatistics(timeout, requestId, cancellationToken); + } + } +} diff --git a/sdk/tables/Azure.Data.Tables/src/Generated/Operations/ServiceGetPropertiesHeaders.cs b/sdk/tables/Azure.Data.Tables/src/Generated/Operations/ServiceGetPropertiesHeaders.cs new file mode 100644 index 000000000000..d3eed424efa1 --- /dev/null +++ b/sdk/tables/Azure.Data.Tables/src/Generated/Operations/ServiceGetPropertiesHeaders.cs @@ -0,0 +1,22 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using Azure; +using Azure.Core; + +namespace Azure.Data.Tables +{ + internal class ServiceGetPropertiesHeaders + { + private readonly Response _response; + public ServiceGetPropertiesHeaders(Response response) + { + _response = response; + } + public string XMsVersion => _response.Headers.TryGetValue("x-ms-version", out string value) ? value : null; + } +} diff --git a/sdk/tables/Azure.Data.Tables/src/Generated/Operations/ServiceGetStatisticsHeaders.cs b/sdk/tables/Azure.Data.Tables/src/Generated/Operations/ServiceGetStatisticsHeaders.cs new file mode 100644 index 000000000000..f0a4868abaec --- /dev/null +++ b/sdk/tables/Azure.Data.Tables/src/Generated/Operations/ServiceGetStatisticsHeaders.cs @@ -0,0 +1,22 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using Azure; +using Azure.Core; + +namespace Azure.Data.Tables +{ + internal class ServiceGetStatisticsHeaders + { + private readonly Response _response; + public ServiceGetStatisticsHeaders(Response response) + { + _response = response; + } + public string XMsVersion => _response.Headers.TryGetValue("x-ms-version", out string value) ? value : null; + } +} diff --git a/sdk/tables/Azure.Data.Tables/src/Generated/Operations/ServiceRestClient.cs b/sdk/tables/Azure.Data.Tables/src/Generated/Operations/ServiceRestClient.cs new file mode 100644 index 000000000000..54fdd0fc1bc4 --- /dev/null +++ b/sdk/tables/Azure.Data.Tables/src/Generated/Operations/ServiceRestClient.cs @@ -0,0 +1,328 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Threading; +using System.Threading.Tasks; +using System.Xml.Linq; +using Azure.Core; +using Azure.Core.Pipeline; +using Azure.Data.Tables.Models; + +namespace Azure.Data.Tables +{ + internal partial class ServiceRestClient + { + private string url; + private string version; + private ClientDiagnostics _clientDiagnostics; + private HttpPipeline _pipeline; + + /// Initializes a new instance of ServiceRestClient. + public ServiceRestClient(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string url, string version = "2018-10-10") + { + if (url == null) + { + throw new ArgumentNullException(nameof(url)); + } + if (version == null) + { + throw new ArgumentNullException(nameof(version)); + } + + this.url = url; + this.version = version; + _clientDiagnostics = clientDiagnostics; + _pipeline = pipeline; + } + + internal HttpMessage CreateSetPropertiesRequest(StorageServiceProperties storageServiceProperties, int? timeout, string requestId) + { + var message = _pipeline.CreateMessage(); + var request = message.Request; + request.Method = RequestMethod.Put; + var uri = new RawRequestUriBuilder(); + uri.AppendRaw(url, false); + uri.AppendPath("/", false); + uri.AppendQuery("restype", "service", true); + uri.AppendQuery("comp", "properties", true); + if (timeout != null) + { + uri.AppendQuery("timeout", timeout.Value, true); + } + request.Uri = uri; + request.Headers.Add("x-ms-version", version); + if (requestId != null) + { + request.Headers.Add("x-ms-client-request-id", requestId); + } + request.Headers.Add("Content-Type", "application/xml"); + using var content = new XmlWriterContent(); + content.XmlWriter.WriteObjectValue(storageServiceProperties, "StorageServiceProperties"); + request.Content = content; + return message; + } + + /// Sets properties for a storage account's Table service endpoint, including properties for Storage Analytics and CORS (Cross-Origin Resource Sharing) rules. + /// The StorageService properties. + /// The The timeout parameter is expressed in seconds. For more information, see <a href="https://docs.microsoft.com/en-us/rest/api/storageservices/setting-timeouts-for-queue-service-operations>Setting Timeouts for Queue Service Operations.</a>. + /// Provides a client-generated, opaque value with a 1 KB character limit that is recorded in the analytics logs when storage analytics logging is enabled. + /// The cancellation token to use. + public async ValueTask> SetPropertiesAsync(StorageServiceProperties storageServiceProperties, int? timeout = null, string requestId = null, CancellationToken cancellationToken = default) + { + if (storageServiceProperties == null) + { + throw new ArgumentNullException(nameof(storageServiceProperties)); + } + + using var scope = _clientDiagnostics.CreateScope("ServiceClient.SetProperties"); + scope.Start(); + try + { + using var message = CreateSetPropertiesRequest(storageServiceProperties, timeout, requestId); + await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); + var headers = new ServiceSetPropertiesHeaders(message.Response); + switch (message.Response.Status) + { + case 202: + return ResponseWithHeaders.FromValue(headers, message.Response); + default: + throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + } + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Sets properties for a storage account's Table service endpoint, including properties for Storage Analytics and CORS (Cross-Origin Resource Sharing) rules. + /// The StorageService properties. + /// The The timeout parameter is expressed in seconds. For more information, see <a href="https://docs.microsoft.com/en-us/rest/api/storageservices/setting-timeouts-for-queue-service-operations>Setting Timeouts for Queue Service Operations.</a>. + /// Provides a client-generated, opaque value with a 1 KB character limit that is recorded in the analytics logs when storage analytics logging is enabled. + /// The cancellation token to use. + public ResponseWithHeaders SetProperties(StorageServiceProperties storageServiceProperties, int? timeout = null, string requestId = null, CancellationToken cancellationToken = default) + { + if (storageServiceProperties == null) + { + throw new ArgumentNullException(nameof(storageServiceProperties)); + } + + using var scope = _clientDiagnostics.CreateScope("ServiceClient.SetProperties"); + scope.Start(); + try + { + using var message = CreateSetPropertiesRequest(storageServiceProperties, timeout, requestId); + _pipeline.Send(message, cancellationToken); + var headers = new ServiceSetPropertiesHeaders(message.Response); + switch (message.Response.Status) + { + case 202: + return ResponseWithHeaders.FromValue(headers, message.Response); + default: + throw _clientDiagnostics.CreateRequestFailedException(message.Response); + } + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + internal HttpMessage CreateGetPropertiesRequest(int? timeout, string requestId) + { + var message = _pipeline.CreateMessage(); + var request = message.Request; + request.Method = RequestMethod.Get; + var uri = new RawRequestUriBuilder(); + uri.AppendRaw(url, false); + uri.AppendPath("/", false); + uri.AppendQuery("restype", "service", true); + uri.AppendQuery("comp", "properties", true); + if (timeout != null) + { + uri.AppendQuery("timeout", timeout.Value, true); + } + request.Uri = uri; + request.Headers.Add("x-ms-version", version); + if (requestId != null) + { + request.Headers.Add("x-ms-client-request-id", requestId); + } + return message; + } + + /// gets the properties of a storage account's Table service, including properties for Storage Analytics and CORS (Cross-Origin Resource Sharing) rules. + /// The The timeout parameter is expressed in seconds. For more information, see <a href="https://docs.microsoft.com/en-us/rest/api/storageservices/setting-timeouts-for-queue-service-operations>Setting Timeouts for Queue Service Operations.</a>. + /// Provides a client-generated, opaque value with a 1 KB character limit that is recorded in the analytics logs when storage analytics logging is enabled. + /// The cancellation token to use. + public async ValueTask> GetPropertiesAsync(int? timeout = null, string requestId = null, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("ServiceClient.GetProperties"); + scope.Start(); + try + { + using var message = CreateGetPropertiesRequest(timeout, requestId); + await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); + var headers = new ServiceGetPropertiesHeaders(message.Response); + switch (message.Response.Status) + { + case 200: + { + StorageServiceProperties value = default; + var document = XDocument.Load(message.Response.ContentStream, LoadOptions.PreserveWhitespace); + if (document.Element("StorageServiceProperties") is XElement storageServicePropertiesElement) + { + value = StorageServiceProperties.DeserializeStorageServiceProperties(storageServicePropertiesElement); + } + return ResponseWithHeaders.FromValue(value, headers, message.Response); + } + default: + throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + } + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// gets the properties of a storage account's Table service, including properties for Storage Analytics and CORS (Cross-Origin Resource Sharing) rules. + /// The The timeout parameter is expressed in seconds. For more information, see <a href="https://docs.microsoft.com/en-us/rest/api/storageservices/setting-timeouts-for-queue-service-operations>Setting Timeouts for Queue Service Operations.</a>. + /// Provides a client-generated, opaque value with a 1 KB character limit that is recorded in the analytics logs when storage analytics logging is enabled. + /// The cancellation token to use. + public ResponseWithHeaders GetProperties(int? timeout = null, string requestId = null, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("ServiceClient.GetProperties"); + scope.Start(); + try + { + using var message = CreateGetPropertiesRequest(timeout, requestId); + _pipeline.Send(message, cancellationToken); + var headers = new ServiceGetPropertiesHeaders(message.Response); + switch (message.Response.Status) + { + case 200: + { + StorageServiceProperties value = default; + var document = XDocument.Load(message.Response.ContentStream, LoadOptions.PreserveWhitespace); + if (document.Element("StorageServiceProperties") is XElement storageServicePropertiesElement) + { + value = StorageServiceProperties.DeserializeStorageServiceProperties(storageServicePropertiesElement); + } + return ResponseWithHeaders.FromValue(value, headers, message.Response); + } + default: + throw _clientDiagnostics.CreateRequestFailedException(message.Response); + } + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + internal HttpMessage CreateGetStatisticsRequest(int? timeout, string requestId) + { + var message = _pipeline.CreateMessage(); + var request = message.Request; + request.Method = RequestMethod.Get; + var uri = new RawRequestUriBuilder(); + uri.AppendRaw(url, false); + uri.AppendPath("/", false); + uri.AppendQuery("restype", "service", true); + uri.AppendQuery("comp", "stats", true); + if (timeout != null) + { + uri.AppendQuery("timeout", timeout.Value, true); + } + request.Uri = uri; + request.Headers.Add("x-ms-version", version); + if (requestId != null) + { + request.Headers.Add("x-ms-client-request-id", requestId); + } + return message; + } + + /// Retrieves statistics related to replication for the Table service. It is only available on the secondary location endpoint when read-access geo-redundant replication is enabled for the storage account. + /// The The timeout parameter is expressed in seconds. For more information, see <a href="https://docs.microsoft.com/en-us/rest/api/storageservices/setting-timeouts-for-queue-service-operations>Setting Timeouts for Queue Service Operations.</a>. + /// Provides a client-generated, opaque value with a 1 KB character limit that is recorded in the analytics logs when storage analytics logging is enabled. + /// The cancellation token to use. + public async ValueTask> GetStatisticsAsync(int? timeout = null, string requestId = null, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("ServiceClient.GetStatistics"); + scope.Start(); + try + { + using var message = CreateGetStatisticsRequest(timeout, requestId); + await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); + var headers = new ServiceGetStatisticsHeaders(message.Response); + switch (message.Response.Status) + { + case 200: + { + StorageServiceStats value = default; + var document = XDocument.Load(message.Response.ContentStream, LoadOptions.PreserveWhitespace); + if (document.Element("StorageServiceStats") is XElement storageServiceStatsElement) + { + value = StorageServiceStats.DeserializeStorageServiceStats(storageServiceStatsElement); + } + return ResponseWithHeaders.FromValue(value, headers, message.Response); + } + default: + throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + } + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Retrieves statistics related to replication for the Table service. It is only available on the secondary location endpoint when read-access geo-redundant replication is enabled for the storage account. + /// The The timeout parameter is expressed in seconds. For more information, see <a href="https://docs.microsoft.com/en-us/rest/api/storageservices/setting-timeouts-for-queue-service-operations>Setting Timeouts for Queue Service Operations.</a>. + /// Provides a client-generated, opaque value with a 1 KB character limit that is recorded in the analytics logs when storage analytics logging is enabled. + /// The cancellation token to use. + public ResponseWithHeaders GetStatistics(int? timeout = null, string requestId = null, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("ServiceClient.GetStatistics"); + scope.Start(); + try + { + using var message = CreateGetStatisticsRequest(timeout, requestId); + _pipeline.Send(message, cancellationToken); + var headers = new ServiceGetStatisticsHeaders(message.Response); + switch (message.Response.Status) + { + case 200: + { + StorageServiceStats value = default; + var document = XDocument.Load(message.Response.ContentStream, LoadOptions.PreserveWhitespace); + if (document.Element("StorageServiceStats") is XElement storageServiceStatsElement) + { + value = StorageServiceStats.DeserializeStorageServiceStats(storageServiceStatsElement); + } + return ResponseWithHeaders.FromValue(value, headers, message.Response); + } + default: + throw _clientDiagnostics.CreateRequestFailedException(message.Response); + } + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + } +} diff --git a/sdk/tables/Azure.Data.Tables/src/Generated/Operations/ServiceSetPropertiesHeaders.cs b/sdk/tables/Azure.Data.Tables/src/Generated/Operations/ServiceSetPropertiesHeaders.cs new file mode 100644 index 000000000000..6ed98a913bb8 --- /dev/null +++ b/sdk/tables/Azure.Data.Tables/src/Generated/Operations/ServiceSetPropertiesHeaders.cs @@ -0,0 +1,22 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using Azure; +using Azure.Core; + +namespace Azure.Data.Tables +{ + internal class ServiceSetPropertiesHeaders + { + private readonly Response _response; + public ServiceSetPropertiesHeaders(Response response) + { + _response = response; + } + public string XMsVersion => _response.Headers.TryGetValue("x-ms-version", out string value) ? value : null; + } +} diff --git a/sdk/tables/Azure.Data.Tables/src/Generated/Operations/TableCreateHeaders.cs b/sdk/tables/Azure.Data.Tables/src/Generated/Operations/TableCreateHeaders.cs new file mode 100644 index 000000000000..18c9d008a038 --- /dev/null +++ b/sdk/tables/Azure.Data.Tables/src/Generated/Operations/TableCreateHeaders.cs @@ -0,0 +1,22 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using Azure; +using Azure.Core; + +namespace Azure.Data.Tables +{ + internal class TableCreateHeaders + { + private readonly Response _response; + public TableCreateHeaders(Response response) + { + _response = response; + } + public string XMsVersion => _response.Headers.TryGetValue("x-ms-version", out string value) ? value : null; + } +} diff --git a/sdk/tables/Azure.Data.Tables/src/Generated/Operations/TableDeleteEntityHeaders.cs b/sdk/tables/Azure.Data.Tables/src/Generated/Operations/TableDeleteEntityHeaders.cs new file mode 100644 index 000000000000..97c54c2d17d2 --- /dev/null +++ b/sdk/tables/Azure.Data.Tables/src/Generated/Operations/TableDeleteEntityHeaders.cs @@ -0,0 +1,22 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using Azure; +using Azure.Core; + +namespace Azure.Data.Tables +{ + internal class TableDeleteEntityHeaders + { + private readonly Response _response; + public TableDeleteEntityHeaders(Response response) + { + _response = response; + } + public string XMsVersion => _response.Headers.TryGetValue("x-ms-version", out string value) ? value : null; + } +} diff --git a/sdk/tables/Azure.Data.Tables/src/Generated/Operations/TableDeleteHeaders.cs b/sdk/tables/Azure.Data.Tables/src/Generated/Operations/TableDeleteHeaders.cs new file mode 100644 index 000000000000..a54d41a29133 --- /dev/null +++ b/sdk/tables/Azure.Data.Tables/src/Generated/Operations/TableDeleteHeaders.cs @@ -0,0 +1,22 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using Azure; +using Azure.Core; + +namespace Azure.Data.Tables +{ + internal class TableDeleteHeaders + { + private readonly Response _response; + public TableDeleteHeaders(Response response) + { + _response = response; + } + public string XMsVersion => _response.Headers.TryGetValue("x-ms-version", out string value) ? value : null; + } +} diff --git a/sdk/tables/Azure.Data.Tables/src/Generated/Operations/TableGetAccessPolicyHeaders.cs b/sdk/tables/Azure.Data.Tables/src/Generated/Operations/TableGetAccessPolicyHeaders.cs new file mode 100644 index 000000000000..5e1058eef8a2 --- /dev/null +++ b/sdk/tables/Azure.Data.Tables/src/Generated/Operations/TableGetAccessPolicyHeaders.cs @@ -0,0 +1,22 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using Azure; +using Azure.Core; + +namespace Azure.Data.Tables +{ + internal class TableGetAccessPolicyHeaders + { + private readonly Response _response; + public TableGetAccessPolicyHeaders(Response response) + { + _response = response; + } + public string XMsVersion => _response.Headers.TryGetValue("x-ms-version", out string value) ? value : null; + } +} diff --git a/sdk/tables/Azure.Data.Tables/src/Generated/Operations/TableInsertEntityHeaders.cs b/sdk/tables/Azure.Data.Tables/src/Generated/Operations/TableInsertEntityHeaders.cs new file mode 100644 index 000000000000..108a93e593b9 --- /dev/null +++ b/sdk/tables/Azure.Data.Tables/src/Generated/Operations/TableInsertEntityHeaders.cs @@ -0,0 +1,22 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using Azure; +using Azure.Core; + +namespace Azure.Data.Tables +{ + internal class TableInsertEntityHeaders + { + private readonly Response _response; + public TableInsertEntityHeaders(Response response) + { + _response = response; + } + public string XMsVersion => _response.Headers.TryGetValue("x-ms-version", out string value) ? value : null; + } +} diff --git a/sdk/tables/Azure.Data.Tables/src/Generated/Operations/TableInternalClient.cs b/sdk/tables/Azure.Data.Tables/src/Generated/Operations/TableInternalClient.cs new file mode 100644 index 000000000000..f26156bf4d23 --- /dev/null +++ b/sdk/tables/Azure.Data.Tables/src/Generated/Operations/TableInternalClient.cs @@ -0,0 +1,258 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System.Collections.Generic; +using System.Threading; +using System.Threading.Tasks; +using Azure; +using Azure.Core.Pipeline; +using Azure.Data.Tables.Models; + +namespace Azure.Data.Tables +{ + internal partial class TableInternalClient + { + private readonly ClientDiagnostics _clientDiagnostics; + private readonly HttpPipeline _pipeline; + internal TableRestClient RestClient { get; } + /// Initializes a new instance of TableInternalClient for mocking. + protected TableInternalClient() + { + } + /// Initializes a new instance of TableInternalClient. + internal TableInternalClient(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string url, string version = "2018-10-10") + { + RestClient = new TableRestClient(clientDiagnostics, pipeline, url, version); + _clientDiagnostics = clientDiagnostics; + _pipeline = pipeline; + } + + /// Queries tables under the given account. + /// Provides a client-generated, opaque value with a 1 KB character limit that is recorded in the analytics logs when storage analytics logging is enabled. + /// Parameter group. + /// The cancellation token to use. + public virtual async Task> QueryAsync(string requestId = null, QueryOptions queryOptions = null, CancellationToken cancellationToken = default) + { + return await RestClient.QueryAsync(requestId, queryOptions, cancellationToken).ConfigureAwait(false); + } + + /// Queries tables under the given account. + /// Provides a client-generated, opaque value with a 1 KB character limit that is recorded in the analytics logs when storage analytics logging is enabled. + /// Parameter group. + /// The cancellation token to use. + public virtual Response Query(string requestId = null, QueryOptions queryOptions = null, CancellationToken cancellationToken = default) + { + return RestClient.Query(requestId, queryOptions, cancellationToken); + } + + /// Creates a new table under the given account. + /// The Table properties. + /// Provides a client-generated, opaque value with a 1 KB character limit that is recorded in the analytics logs when storage analytics logging is enabled. + /// Parameter group. + /// The cancellation token to use. + public virtual async Task> CreateAsync(TableProperties tableProperties, string requestId = null, QueryOptions queryOptions = null, CancellationToken cancellationToken = default) + { + return await RestClient.CreateAsync(tableProperties, requestId, queryOptions, cancellationToken).ConfigureAwait(false); + } + + /// Creates a new table under the given account. + /// The Table properties. + /// Provides a client-generated, opaque value with a 1 KB character limit that is recorded in the analytics logs when storage analytics logging is enabled. + /// Parameter group. + /// The cancellation token to use. + public virtual Response Create(TableProperties tableProperties, string requestId = null, QueryOptions queryOptions = null, CancellationToken cancellationToken = default) + { + return RestClient.Create(tableProperties, requestId, queryOptions, cancellationToken); + } + + /// Operation permanently deletes the specified table. + /// The name of the table. + /// Provides a client-generated, opaque value with a 1 KB character limit that is recorded in the analytics logs when storage analytics logging is enabled. + /// The cancellation token to use. + public virtual async Task DeleteAsync(string table, string requestId = null, CancellationToken cancellationToken = default) + { + return (await RestClient.DeleteAsync(table, requestId, cancellationToken).ConfigureAwait(false)).GetRawResponse(); + } + + /// Operation permanently deletes the specified table. + /// The name of the table. + /// Provides a client-generated, opaque value with a 1 KB character limit that is recorded in the analytics logs when storage analytics logging is enabled. + /// The cancellation token to use. + public virtual Response Delete(string table, string requestId = null, CancellationToken cancellationToken = default) + { + return RestClient.Delete(table, requestId, cancellationToken).GetRawResponse(); + } + + /// Queries entities in a table. + /// The name of the table. + /// The The timeout parameter is expressed in seconds. For more information, see <a href="https://docs.microsoft.com/en-us/rest/api/storageservices/setting-timeouts-for-queue-service-operations>Setting Timeouts for Queue Service Operations.</a>. + /// Provides a client-generated, opaque value with a 1 KB character limit that is recorded in the analytics logs when storage analytics logging is enabled. + /// Parameter group. + /// The cancellation token to use. + public virtual async Task> QueryEntitiesAsync(string table, int? timeout = null, string requestId = null, QueryOptions queryOptions = null, CancellationToken cancellationToken = default) + { + return await RestClient.QueryEntitiesAsync(table, timeout, requestId, queryOptions, cancellationToken).ConfigureAwait(false); + } + + /// Queries entities in a table. + /// The name of the table. + /// The The timeout parameter is expressed in seconds. For more information, see <a href="https://docs.microsoft.com/en-us/rest/api/storageservices/setting-timeouts-for-queue-service-operations>Setting Timeouts for Queue Service Operations.</a>. + /// Provides a client-generated, opaque value with a 1 KB character limit that is recorded in the analytics logs when storage analytics logging is enabled. + /// Parameter group. + /// The cancellation token to use. + public virtual Response QueryEntities(string table, int? timeout = null, string requestId = null, QueryOptions queryOptions = null, CancellationToken cancellationToken = default) + { + return RestClient.QueryEntities(table, timeout, requestId, queryOptions, cancellationToken); + } + + /// Queries entities in a table. + /// The name of the table. + /// The partition key of the entity. + /// The row key of the entity. + /// The The timeout parameter is expressed in seconds. For more information, see <a href="https://docs.microsoft.com/en-us/rest/api/storageservices/setting-timeouts-for-queue-service-operations>Setting Timeouts for Queue Service Operations.</a>. + /// Provides a client-generated, opaque value with a 1 KB character limit that is recorded in the analytics logs when storage analytics logging is enabled. + /// Parameter group. + /// The cancellation token to use. + public virtual async Task> QueryEntitiesWithPartitionAndRowKeyAsync(string table, string partitionKey, string rowKey, int? timeout = null, string requestId = null, QueryOptions queryOptions = null, CancellationToken cancellationToken = default) + { + return await RestClient.QueryEntitiesWithPartitionAndRowKeyAsync(table, partitionKey, rowKey, timeout, requestId, queryOptions, cancellationToken).ConfigureAwait(false); + } + + /// Queries entities in a table. + /// The name of the table. + /// The partition key of the entity. + /// The row key of the entity. + /// The The timeout parameter is expressed in seconds. For more information, see <a href="https://docs.microsoft.com/en-us/rest/api/storageservices/setting-timeouts-for-queue-service-operations>Setting Timeouts for Queue Service Operations.</a>. + /// Provides a client-generated, opaque value with a 1 KB character limit that is recorded in the analytics logs when storage analytics logging is enabled. + /// Parameter group. + /// The cancellation token to use. + public virtual Response QueryEntitiesWithPartitionAndRowKey(string table, string partitionKey, string rowKey, int? timeout = null, string requestId = null, QueryOptions queryOptions = null, CancellationToken cancellationToken = default) + { + return RestClient.QueryEntitiesWithPartitionAndRowKey(table, partitionKey, rowKey, timeout, requestId, queryOptions, cancellationToken); + } + + /// Update entity in a table. + /// The name of the table. + /// The partition key of the entity. + /// The row key of the entity. + /// The The timeout parameter is expressed in seconds. For more information, see <a href="https://docs.microsoft.com/en-us/rest/api/storageservices/setting-timeouts-for-queue-service-operations>Setting Timeouts for Queue Service Operations.</a>. + /// Provides a client-generated, opaque value with a 1 KB character limit that is recorded in the analytics logs when storage analytics logging is enabled. + /// The properties for the table entity. + /// Parameter group. + /// The cancellation token to use. + public virtual async Task UpdateEntityAsync(string table, string partitionKey, string rowKey, int? timeout = null, string requestId = null, IDictionary tableEntityProperties = null, QueryOptions queryOptions = null, CancellationToken cancellationToken = default) + { + return (await RestClient.UpdateEntityAsync(table, partitionKey, rowKey, timeout, requestId, tableEntityProperties, queryOptions, cancellationToken).ConfigureAwait(false)).GetRawResponse(); + } + + /// Update entity in a table. + /// The name of the table. + /// The partition key of the entity. + /// The row key of the entity. + /// The The timeout parameter is expressed in seconds. For more information, see <a href="https://docs.microsoft.com/en-us/rest/api/storageservices/setting-timeouts-for-queue-service-operations>Setting Timeouts for Queue Service Operations.</a>. + /// Provides a client-generated, opaque value with a 1 KB character limit that is recorded in the analytics logs when storage analytics logging is enabled. + /// The properties for the table entity. + /// Parameter group. + /// The cancellation token to use. + public virtual Response UpdateEntity(string table, string partitionKey, string rowKey, int? timeout = null, string requestId = null, IDictionary tableEntityProperties = null, QueryOptions queryOptions = null, CancellationToken cancellationToken = default) + { + return RestClient.UpdateEntity(table, partitionKey, rowKey, timeout, requestId, tableEntityProperties, queryOptions, cancellationToken).GetRawResponse(); + } + + /// Deletes the specified entity in a table. + /// The name of the table. + /// The partition key of the entity. + /// The row key of the entity. + /// The The timeout parameter is expressed in seconds. For more information, see <a href="https://docs.microsoft.com/en-us/rest/api/storageservices/setting-timeouts-for-queue-service-operations>Setting Timeouts for Queue Service Operations.</a>. + /// Provides a client-generated, opaque value with a 1 KB character limit that is recorded in the analytics logs when storage analytics logging is enabled. + /// Parameter group. + /// The cancellation token to use. + public virtual async Task DeleteEntityAsync(string table, string partitionKey, string rowKey, int? timeout = null, string requestId = null, QueryOptions queryOptions = null, CancellationToken cancellationToken = default) + { + return (await RestClient.DeleteEntityAsync(table, partitionKey, rowKey, timeout, requestId, queryOptions, cancellationToken).ConfigureAwait(false)).GetRawResponse(); + } + + /// Deletes the specified entity in a table. + /// The name of the table. + /// The partition key of the entity. + /// The row key of the entity. + /// The The timeout parameter is expressed in seconds. For more information, see <a href="https://docs.microsoft.com/en-us/rest/api/storageservices/setting-timeouts-for-queue-service-operations>Setting Timeouts for Queue Service Operations.</a>. + /// Provides a client-generated, opaque value with a 1 KB character limit that is recorded in the analytics logs when storage analytics logging is enabled. + /// Parameter group. + /// The cancellation token to use. + public virtual Response DeleteEntity(string table, string partitionKey, string rowKey, int? timeout = null, string requestId = null, QueryOptions queryOptions = null, CancellationToken cancellationToken = default) + { + return RestClient.DeleteEntity(table, partitionKey, rowKey, timeout, requestId, queryOptions, cancellationToken).GetRawResponse(); + } + + /// Insert entity in a table. + /// The name of the table. + /// The The timeout parameter is expressed in seconds. For more information, see <a href="https://docs.microsoft.com/en-us/rest/api/storageservices/setting-timeouts-for-queue-service-operations>Setting Timeouts for Queue Service Operations.</a>. + /// Provides a client-generated, opaque value with a 1 KB character limit that is recorded in the analytics logs when storage analytics logging is enabled. + /// The properties for the table entity. + /// Parameter group. + /// The cancellation token to use. + public virtual async Task>> InsertEntityAsync(string table, int? timeout = null, string requestId = null, IDictionary tableEntityProperties = null, QueryOptions queryOptions = null, CancellationToken cancellationToken = default) + { + return await RestClient.InsertEntityAsync(table, timeout, requestId, tableEntityProperties, queryOptions, cancellationToken).ConfigureAwait(false); + } + + /// Insert entity in a table. + /// The name of the table. + /// The The timeout parameter is expressed in seconds. For more information, see <a href="https://docs.microsoft.com/en-us/rest/api/storageservices/setting-timeouts-for-queue-service-operations>Setting Timeouts for Queue Service Operations.</a>. + /// Provides a client-generated, opaque value with a 1 KB character limit that is recorded in the analytics logs when storage analytics logging is enabled. + /// The properties for the table entity. + /// Parameter group. + /// The cancellation token to use. + public virtual Response> InsertEntity(string table, int? timeout = null, string requestId = null, IDictionary tableEntityProperties = null, QueryOptions queryOptions = null, CancellationToken cancellationToken = default) + { + return RestClient.InsertEntity(table, timeout, requestId, tableEntityProperties, queryOptions, cancellationToken); + } + + /// Retrieves details about any stored access policies specified on the table that may be used wit Shared Access Signatures. + /// The name of the table. + /// The The timeout parameter is expressed in seconds. For more information, see <a href="https://docs.microsoft.com/en-us/rest/api/storageservices/setting-timeouts-for-queue-service-operations>Setting Timeouts for Queue Service Operations.</a>. + /// Provides a client-generated, opaque value with a 1 KB character limit that is recorded in the analytics logs when storage analytics logging is enabled. + /// The cancellation token to use. + public virtual async Task>> GetAccessPolicyAsync(string table, int? timeout = null, string requestId = null, CancellationToken cancellationToken = default) + { + return await RestClient.GetAccessPolicyAsync(table, timeout, requestId, cancellationToken).ConfigureAwait(false); + } + + /// Retrieves details about any stored access policies specified on the table that may be used wit Shared Access Signatures. + /// The name of the table. + /// The The timeout parameter is expressed in seconds. For more information, see <a href="https://docs.microsoft.com/en-us/rest/api/storageservices/setting-timeouts-for-queue-service-operations>Setting Timeouts for Queue Service Operations.</a>. + /// Provides a client-generated, opaque value with a 1 KB character limit that is recorded in the analytics logs when storage analytics logging is enabled. + /// The cancellation token to use. + public virtual Response> GetAccessPolicy(string table, int? timeout = null, string requestId = null, CancellationToken cancellationToken = default) + { + return RestClient.GetAccessPolicy(table, timeout, requestId, cancellationToken); + } + + /// sets stored access policies for the table that may be used with Shared Access Signatures. + /// The name of the table. + /// The The timeout parameter is expressed in seconds. For more information, see <a href="https://docs.microsoft.com/en-us/rest/api/storageservices/setting-timeouts-for-queue-service-operations>Setting Timeouts for Queue Service Operations.</a>. + /// Provides a client-generated, opaque value with a 1 KB character limit that is recorded in the analytics logs when storage analytics logging is enabled. + /// the acls for the table. + /// The cancellation token to use. + public virtual async Task SetAccessPolicyAsync(string table, int? timeout = null, string requestId = null, IEnumerable tableAcl = null, CancellationToken cancellationToken = default) + { + return (await RestClient.SetAccessPolicyAsync(table, timeout, requestId, tableAcl, cancellationToken).ConfigureAwait(false)).GetRawResponse(); + } + + /// sets stored access policies for the table that may be used with Shared Access Signatures. + /// The name of the table. + /// The The timeout parameter is expressed in seconds. For more information, see <a href="https://docs.microsoft.com/en-us/rest/api/storageservices/setting-timeouts-for-queue-service-operations>Setting Timeouts for Queue Service Operations.</a>. + /// Provides a client-generated, opaque value with a 1 KB character limit that is recorded in the analytics logs when storage analytics logging is enabled. + /// the acls for the table. + /// The cancellation token to use. + public virtual Response SetAccessPolicy(string table, int? timeout = null, string requestId = null, IEnumerable tableAcl = null, CancellationToken cancellationToken = default) + { + return RestClient.SetAccessPolicy(table, timeout, requestId, tableAcl, cancellationToken).GetRawResponse(); + } + } +} diff --git a/sdk/tables/Azure.Data.Tables/src/Generated/Operations/TableQueryEntitiesHeaders.cs b/sdk/tables/Azure.Data.Tables/src/Generated/Operations/TableQueryEntitiesHeaders.cs new file mode 100644 index 000000000000..955de4b343bf --- /dev/null +++ b/sdk/tables/Azure.Data.Tables/src/Generated/Operations/TableQueryEntitiesHeaders.cs @@ -0,0 +1,24 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using Azure; +using Azure.Core; + +namespace Azure.Data.Tables +{ + internal class TableQueryEntitiesHeaders + { + private readonly Response _response; + public TableQueryEntitiesHeaders(Response response) + { + _response = response; + } + public string XMsVersion => _response.Headers.TryGetValue("x-ms-version", out string value) ? value : null; + public string XMsContinuationNextPartitionKey => _response.Headers.TryGetValue("x-ms-continuation-NextPartitionKey", out string value) ? value : null; + public string XMsContinuationNextRowKey => _response.Headers.TryGetValue("x-ms-continuation-NextRowKey", out string value) ? value : null; + } +} diff --git a/sdk/tables/Azure.Data.Tables/src/Generated/Operations/TableQueryEntitiesWithPartitionAndRowKeyHeaders.cs b/sdk/tables/Azure.Data.Tables/src/Generated/Operations/TableQueryEntitiesWithPartitionAndRowKeyHeaders.cs new file mode 100644 index 000000000000..e6c25a700429 --- /dev/null +++ b/sdk/tables/Azure.Data.Tables/src/Generated/Operations/TableQueryEntitiesWithPartitionAndRowKeyHeaders.cs @@ -0,0 +1,24 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using Azure; +using Azure.Core; + +namespace Azure.Data.Tables +{ + internal class TableQueryEntitiesWithPartitionAndRowKeyHeaders + { + private readonly Response _response; + public TableQueryEntitiesWithPartitionAndRowKeyHeaders(Response response) + { + _response = response; + } + public string XMsVersion => _response.Headers.TryGetValue("x-ms-version", out string value) ? value : null; + public string XMsContinuationNextPartitionKey => _response.Headers.TryGetValue("x-ms-continuation-NextPartitionKey", out string value) ? value : null; + public string XMsContinuationNextRowKey => _response.Headers.TryGetValue("x-ms-continuation-NextRowKey", out string value) ? value : null; + } +} diff --git a/sdk/tables/Azure.Data.Tables/src/Generated/Operations/TableQueryHeaders.cs b/sdk/tables/Azure.Data.Tables/src/Generated/Operations/TableQueryHeaders.cs new file mode 100644 index 000000000000..8f08eea0ee80 --- /dev/null +++ b/sdk/tables/Azure.Data.Tables/src/Generated/Operations/TableQueryHeaders.cs @@ -0,0 +1,23 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using Azure; +using Azure.Core; + +namespace Azure.Data.Tables +{ + internal class TableQueryHeaders + { + private readonly Response _response; + public TableQueryHeaders(Response response) + { + _response = response; + } + public string XMsVersion => _response.Headers.TryGetValue("x-ms-version", out string value) ? value : null; + public string XMsContinuationNextTableName => _response.Headers.TryGetValue("x-ms-continuation-NextTableName", out string value) ? value : null; + } +} diff --git a/sdk/tables/Azure.Data.Tables/src/Generated/Operations/TableRestClient.cs b/sdk/tables/Azure.Data.Tables/src/Generated/Operations/TableRestClient.cs new file mode 100644 index 000000000000..a08c609bf7ec --- /dev/null +++ b/sdk/tables/Azure.Data.Tables/src/Generated/Operations/TableRestClient.cs @@ -0,0 +1,1295 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; +using System.Text.Json; +using System.Threading; +using System.Threading.Tasks; +using System.Xml.Linq; +using Azure.Core; +using Azure.Core.Pipeline; +using Azure.Data.Tables.Models; + +namespace Azure.Data.Tables +{ + internal partial class TableRestClient + { + private string url; + private string version; + private ClientDiagnostics _clientDiagnostics; + private HttpPipeline _pipeline; + + /// Initializes a new instance of TableRestClient. + public TableRestClient(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string url, string version = "2018-10-10") + { + if (url == null) + { + throw new ArgumentNullException(nameof(url)); + } + if (version == null) + { + throw new ArgumentNullException(nameof(version)); + } + + this.url = url; + this.version = version; + _clientDiagnostics = clientDiagnostics; + _pipeline = pipeline; + } + + internal HttpMessage CreateQueryRequest(string requestId, QueryOptions queryOptions) + { + var message = _pipeline.CreateMessage(); + var request = message.Request; + request.Method = RequestMethod.Get; + var uri = new RawRequestUriBuilder(); + uri.AppendRaw(url, false); + uri.AppendPath("/Tables", false); + if (queryOptions?.Format != null) + { + uri.AppendQuery("$format", queryOptions.Format.Value.ToString(), true); + } + if (queryOptions?.Top != null) + { + uri.AppendQuery("$top", queryOptions.Top.Value, true); + } + if (queryOptions?.Select != null) + { + uri.AppendQuery("$select", queryOptions.Select, true); + } + if (queryOptions?.Filter != null) + { + uri.AppendQuery("$filter", queryOptions.Filter, true); + } + request.Uri = uri; + request.Headers.Add("x-ms-version", version); + if (requestId != null) + { + request.Headers.Add("x-ms-client-request-id", requestId); + } + request.Headers.Add("DataServiceVersion", "3.0"); + return message; + } + + /// Queries tables under the given account. + /// Provides a client-generated, opaque value with a 1 KB character limit that is recorded in the analytics logs when storage analytics logging is enabled. + /// Parameter group. + /// The cancellation token to use. + public async ValueTask> QueryAsync(string requestId = null, QueryOptions queryOptions = null, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("TableClient.Query"); + scope.Start(); + try + { + using var message = CreateQueryRequest(requestId, queryOptions); + await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); + var headers = new TableQueryHeaders(message.Response); + switch (message.Response.Status) + { + case 200: + { + TableQueryResponse value = default; + using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, cancellationToken).ConfigureAwait(false); + if (document.RootElement.ValueKind == JsonValueKind.Null) + { + value = null; + } + else + { + value = TableQueryResponse.DeserializeTableQueryResponse(document.RootElement); + } + return ResponseWithHeaders.FromValue(value, headers, message.Response); + } + default: + throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + } + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Queries tables under the given account. + /// Provides a client-generated, opaque value with a 1 KB character limit that is recorded in the analytics logs when storage analytics logging is enabled. + /// Parameter group. + /// The cancellation token to use. + public ResponseWithHeaders Query(string requestId = null, QueryOptions queryOptions = null, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("TableClient.Query"); + scope.Start(); + try + { + using var message = CreateQueryRequest(requestId, queryOptions); + _pipeline.Send(message, cancellationToken); + var headers = new TableQueryHeaders(message.Response); + switch (message.Response.Status) + { + case 200: + { + TableQueryResponse value = default; + using var document = JsonDocument.Parse(message.Response.ContentStream); + if (document.RootElement.ValueKind == JsonValueKind.Null) + { + value = null; + } + else + { + value = TableQueryResponse.DeserializeTableQueryResponse(document.RootElement); + } + return ResponseWithHeaders.FromValue(value, headers, message.Response); + } + default: + throw _clientDiagnostics.CreateRequestFailedException(message.Response); + } + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + internal HttpMessage CreateCreateRequest(TableProperties tableProperties, string requestId, QueryOptions queryOptions) + { + var message = _pipeline.CreateMessage(); + var request = message.Request; + request.Method = RequestMethod.Post; + var uri = new RawRequestUriBuilder(); + uri.AppendRaw(url, false); + uri.AppendPath("/Tables", false); + if (queryOptions?.Format != null) + { + uri.AppendQuery("$format", queryOptions.Format.Value.ToString(), true); + } + request.Uri = uri; + request.Headers.Add("x-ms-version", version); + if (requestId != null) + { + request.Headers.Add("x-ms-client-request-id", requestId); + } + request.Headers.Add("DataServiceVersion", "3.0"); + request.Headers.Add("Content-Type", "application/json;odata=nometadata"); + using var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(tableProperties); + request.Content = content; + return message; + } + + /// Creates a new table under the given account. + /// The Table properties. + /// Provides a client-generated, opaque value with a 1 KB character limit that is recorded in the analytics logs when storage analytics logging is enabled. + /// Parameter group. + /// The cancellation token to use. + public async ValueTask> CreateAsync(TableProperties tableProperties, string requestId = null, QueryOptions queryOptions = null, CancellationToken cancellationToken = default) + { + if (tableProperties == null) + { + throw new ArgumentNullException(nameof(tableProperties)); + } + + using var scope = _clientDiagnostics.CreateScope("TableClient.Create"); + scope.Start(); + try + { + using var message = CreateCreateRequest(tableProperties, requestId, queryOptions); + await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); + var headers = new TableCreateHeaders(message.Response); + switch (message.Response.Status) + { + case 201: + { + TableResponse value = default; + using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, cancellationToken).ConfigureAwait(false); + if (document.RootElement.ValueKind == JsonValueKind.Null) + { + value = null; + } + else + { + value = TableResponse.DeserializeTableResponse(document.RootElement); + } + return ResponseWithHeaders.FromValue(value, headers, message.Response); + } + case 204: + return ResponseWithHeaders.FromValue(null, headers, message.Response); + default: + throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + } + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Creates a new table under the given account. + /// The Table properties. + /// Provides a client-generated, opaque value with a 1 KB character limit that is recorded in the analytics logs when storage analytics logging is enabled. + /// Parameter group. + /// The cancellation token to use. + public ResponseWithHeaders Create(TableProperties tableProperties, string requestId = null, QueryOptions queryOptions = null, CancellationToken cancellationToken = default) + { + if (tableProperties == null) + { + throw new ArgumentNullException(nameof(tableProperties)); + } + + using var scope = _clientDiagnostics.CreateScope("TableClient.Create"); + scope.Start(); + try + { + using var message = CreateCreateRequest(tableProperties, requestId, queryOptions); + _pipeline.Send(message, cancellationToken); + var headers = new TableCreateHeaders(message.Response); + switch (message.Response.Status) + { + case 201: + { + TableResponse value = default; + using var document = JsonDocument.Parse(message.Response.ContentStream); + if (document.RootElement.ValueKind == JsonValueKind.Null) + { + value = null; + } + else + { + value = TableResponse.DeserializeTableResponse(document.RootElement); + } + return ResponseWithHeaders.FromValue(value, headers, message.Response); + } + case 204: + return ResponseWithHeaders.FromValue(null, headers, message.Response); + default: + throw _clientDiagnostics.CreateRequestFailedException(message.Response); + } + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + internal HttpMessage CreateDeleteRequest(string table, string requestId) + { + var message = _pipeline.CreateMessage(); + var request = message.Request; + request.Method = RequestMethod.Delete; + var uri = new RawRequestUriBuilder(); + uri.AppendRaw(url, false); + uri.AppendPath("/Tables('", false); + uri.AppendPath(table, true); + uri.AppendPath("')", false); + request.Uri = uri; + request.Headers.Add("x-ms-version", version); + if (requestId != null) + { + request.Headers.Add("x-ms-client-request-id", requestId); + } + return message; + } + + /// Operation permanently deletes the specified table. + /// The name of the table. + /// Provides a client-generated, opaque value with a 1 KB character limit that is recorded in the analytics logs when storage analytics logging is enabled. + /// The cancellation token to use. + public async ValueTask> DeleteAsync(string table, string requestId = null, CancellationToken cancellationToken = default) + { + if (table == null) + { + throw new ArgumentNullException(nameof(table)); + } + + using var scope = _clientDiagnostics.CreateScope("TableClient.Delete"); + scope.Start(); + try + { + using var message = CreateDeleteRequest(table, requestId); + await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); + var headers = new TableDeleteHeaders(message.Response); + switch (message.Response.Status) + { + case 204: + return ResponseWithHeaders.FromValue(headers, message.Response); + default: + throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + } + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Operation permanently deletes the specified table. + /// The name of the table. + /// Provides a client-generated, opaque value with a 1 KB character limit that is recorded in the analytics logs when storage analytics logging is enabled. + /// The cancellation token to use. + public ResponseWithHeaders Delete(string table, string requestId = null, CancellationToken cancellationToken = default) + { + if (table == null) + { + throw new ArgumentNullException(nameof(table)); + } + + using var scope = _clientDiagnostics.CreateScope("TableClient.Delete"); + scope.Start(); + try + { + using var message = CreateDeleteRequest(table, requestId); + _pipeline.Send(message, cancellationToken); + var headers = new TableDeleteHeaders(message.Response); + switch (message.Response.Status) + { + case 204: + return ResponseWithHeaders.FromValue(headers, message.Response); + default: + throw _clientDiagnostics.CreateRequestFailedException(message.Response); + } + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + internal HttpMessage CreateQueryEntitiesRequest(string table, int? timeout, string requestId, QueryOptions queryOptions) + { + var message = _pipeline.CreateMessage(); + var request = message.Request; + request.Method = RequestMethod.Get; + var uri = new RawRequestUriBuilder(); + uri.AppendRaw(url, false); + uri.AppendPath("/", false); + uri.AppendPath(table, true); + uri.AppendPath("()", false); + if (timeout != null) + { + uri.AppendQuery("timeout", timeout.Value, true); + } + if (queryOptions?.Format != null) + { + uri.AppendQuery("$format", queryOptions.Format.Value.ToString(), true); + } + if (queryOptions?.Top != null) + { + uri.AppendQuery("$top", queryOptions.Top.Value, true); + } + if (queryOptions?.Select != null) + { + uri.AppendQuery("$select", queryOptions.Select, true); + } + if (queryOptions?.Filter != null) + { + uri.AppendQuery("$filter", queryOptions.Filter, true); + } + request.Uri = uri; + request.Headers.Add("x-ms-version", version); + if (requestId != null) + { + request.Headers.Add("x-ms-client-request-id", requestId); + } + request.Headers.Add("DataServiceVersion", "3.0"); + return message; + } + + /// Queries entities in a table. + /// The name of the table. + /// The The timeout parameter is expressed in seconds. For more information, see <a href="https://docs.microsoft.com/en-us/rest/api/storageservices/setting-timeouts-for-queue-service-operations>Setting Timeouts for Queue Service Operations.</a>. + /// Provides a client-generated, opaque value with a 1 KB character limit that is recorded in the analytics logs when storage analytics logging is enabled. + /// Parameter group. + /// The cancellation token to use. + public async ValueTask> QueryEntitiesAsync(string table, int? timeout = null, string requestId = null, QueryOptions queryOptions = null, CancellationToken cancellationToken = default) + { + if (table == null) + { + throw new ArgumentNullException(nameof(table)); + } + + using var scope = _clientDiagnostics.CreateScope("TableClient.QueryEntities"); + scope.Start(); + try + { + using var message = CreateQueryEntitiesRequest(table, timeout, requestId, queryOptions); + await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); + var headers = new TableQueryEntitiesHeaders(message.Response); + switch (message.Response.Status) + { + case 200: + { + TableEntityQueryResponse value = default; + using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, cancellationToken).ConfigureAwait(false); + if (document.RootElement.ValueKind == JsonValueKind.Null) + { + value = null; + } + else + { + value = TableEntityQueryResponse.DeserializeTableEntityQueryResponse(document.RootElement); + } + return ResponseWithHeaders.FromValue(value, headers, message.Response); + } + default: + throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + } + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Queries entities in a table. + /// The name of the table. + /// The The timeout parameter is expressed in seconds. For more information, see <a href="https://docs.microsoft.com/en-us/rest/api/storageservices/setting-timeouts-for-queue-service-operations>Setting Timeouts for Queue Service Operations.</a>. + /// Provides a client-generated, opaque value with a 1 KB character limit that is recorded in the analytics logs when storage analytics logging is enabled. + /// Parameter group. + /// The cancellation token to use. + public ResponseWithHeaders QueryEntities(string table, int? timeout = null, string requestId = null, QueryOptions queryOptions = null, CancellationToken cancellationToken = default) + { + if (table == null) + { + throw new ArgumentNullException(nameof(table)); + } + + using var scope = _clientDiagnostics.CreateScope("TableClient.QueryEntities"); + scope.Start(); + try + { + using var message = CreateQueryEntitiesRequest(table, timeout, requestId, queryOptions); + _pipeline.Send(message, cancellationToken); + var headers = new TableQueryEntitiesHeaders(message.Response); + switch (message.Response.Status) + { + case 200: + { + TableEntityQueryResponse value = default; + using var document = JsonDocument.Parse(message.Response.ContentStream); + if (document.RootElement.ValueKind == JsonValueKind.Null) + { + value = null; + } + else + { + value = TableEntityQueryResponse.DeserializeTableEntityQueryResponse(document.RootElement); + } + return ResponseWithHeaders.FromValue(value, headers, message.Response); + } + default: + throw _clientDiagnostics.CreateRequestFailedException(message.Response); + } + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + internal HttpMessage CreateQueryEntitiesWithPartitionAndRowKeyRequest(string table, string partitionKey, string rowKey, int? timeout, string requestId, QueryOptions queryOptions) + { + var message = _pipeline.CreateMessage(); + var request = message.Request; + request.Method = RequestMethod.Get; + var uri = new RawRequestUriBuilder(); + uri.AppendRaw(url, false); + uri.AppendPath("/", false); + uri.AppendPath(table, true); + uri.AppendPath("(PartitionKey='", false); + uri.AppendPath(partitionKey, true); + uri.AppendPath("',RowKey='", false); + uri.AppendPath(rowKey, true); + uri.AppendPath("')", false); + if (timeout != null) + { + uri.AppendQuery("timeout", timeout.Value, true); + } + if (queryOptions?.Format != null) + { + uri.AppendQuery("$format", queryOptions.Format.Value.ToString(), true); + } + if (queryOptions?.Select != null) + { + uri.AppendQuery("$select", queryOptions.Select, true); + } + if (queryOptions?.Filter != null) + { + uri.AppendQuery("$filter", queryOptions.Filter, true); + } + request.Uri = uri; + request.Headers.Add("x-ms-version", version); + if (requestId != null) + { + request.Headers.Add("x-ms-client-request-id", requestId); + } + request.Headers.Add("DataServiceVersion", "3.0"); + return message; + } + + /// Queries entities in a table. + /// The name of the table. + /// The partition key of the entity. + /// The row key of the entity. + /// The The timeout parameter is expressed in seconds. For more information, see <a href="https://docs.microsoft.com/en-us/rest/api/storageservices/setting-timeouts-for-queue-service-operations>Setting Timeouts for Queue Service Operations.</a>. + /// Provides a client-generated, opaque value with a 1 KB character limit that is recorded in the analytics logs when storage analytics logging is enabled. + /// Parameter group. + /// The cancellation token to use. + public async ValueTask> QueryEntitiesWithPartitionAndRowKeyAsync(string table, string partitionKey, string rowKey, int? timeout = null, string requestId = null, QueryOptions queryOptions = null, CancellationToken cancellationToken = default) + { + if (table == null) + { + throw new ArgumentNullException(nameof(table)); + } + if (partitionKey == null) + { + throw new ArgumentNullException(nameof(partitionKey)); + } + if (rowKey == null) + { + throw new ArgumentNullException(nameof(rowKey)); + } + + using var scope = _clientDiagnostics.CreateScope("TableClient.QueryEntitiesWithPartitionAndRowKey"); + scope.Start(); + try + { + using var message = CreateQueryEntitiesWithPartitionAndRowKeyRequest(table, partitionKey, rowKey, timeout, requestId, queryOptions); + await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); + var headers = new TableQueryEntitiesWithPartitionAndRowKeyHeaders(message.Response); + switch (message.Response.Status) + { + case 200: + { + TableEntityQueryResponse value = default; + using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, cancellationToken).ConfigureAwait(false); + if (document.RootElement.ValueKind == JsonValueKind.Null) + { + value = null; + } + else + { + value = TableEntityQueryResponse.DeserializeTableEntityQueryResponse(document.RootElement); + } + return ResponseWithHeaders.FromValue(value, headers, message.Response); + } + default: + throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + } + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Queries entities in a table. + /// The name of the table. + /// The partition key of the entity. + /// The row key of the entity. + /// The The timeout parameter is expressed in seconds. For more information, see <a href="https://docs.microsoft.com/en-us/rest/api/storageservices/setting-timeouts-for-queue-service-operations>Setting Timeouts for Queue Service Operations.</a>. + /// Provides a client-generated, opaque value with a 1 KB character limit that is recorded in the analytics logs when storage analytics logging is enabled. + /// Parameter group. + /// The cancellation token to use. + public ResponseWithHeaders QueryEntitiesWithPartitionAndRowKey(string table, string partitionKey, string rowKey, int? timeout = null, string requestId = null, QueryOptions queryOptions = null, CancellationToken cancellationToken = default) + { + if (table == null) + { + throw new ArgumentNullException(nameof(table)); + } + if (partitionKey == null) + { + throw new ArgumentNullException(nameof(partitionKey)); + } + if (rowKey == null) + { + throw new ArgumentNullException(nameof(rowKey)); + } + + using var scope = _clientDiagnostics.CreateScope("TableClient.QueryEntitiesWithPartitionAndRowKey"); + scope.Start(); + try + { + using var message = CreateQueryEntitiesWithPartitionAndRowKeyRequest(table, partitionKey, rowKey, timeout, requestId, queryOptions); + _pipeline.Send(message, cancellationToken); + var headers = new TableQueryEntitiesWithPartitionAndRowKeyHeaders(message.Response); + switch (message.Response.Status) + { + case 200: + { + TableEntityQueryResponse value = default; + using var document = JsonDocument.Parse(message.Response.ContentStream); + if (document.RootElement.ValueKind == JsonValueKind.Null) + { + value = null; + } + else + { + value = TableEntityQueryResponse.DeserializeTableEntityQueryResponse(document.RootElement); + } + return ResponseWithHeaders.FromValue(value, headers, message.Response); + } + default: + throw _clientDiagnostics.CreateRequestFailedException(message.Response); + } + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + internal HttpMessage CreateUpdateEntityRequest(string table, string partitionKey, string rowKey, int? timeout, string requestId, IDictionary tableEntityProperties, QueryOptions queryOptions) + { + var message = _pipeline.CreateMessage(); + var request = message.Request; + request.Method = RequestMethod.Put; + var uri = new RawRequestUriBuilder(); + uri.AppendRaw(url, false); + uri.AppendPath("/", false); + uri.AppendPath(table, true); + uri.AppendPath("(PartitionKey='", false); + uri.AppendPath(partitionKey, true); + uri.AppendPath("',RowKey='", false); + uri.AppendPath(rowKey, true); + uri.AppendPath("')", false); + if (timeout != null) + { + uri.AppendQuery("timeout", timeout.Value, true); + } + if (queryOptions?.Format != null) + { + uri.AppendQuery("$format", queryOptions.Format.Value.ToString(), true); + } + request.Uri = uri; + request.Headers.Add("x-ms-version", version); + if (requestId != null) + { + request.Headers.Add("x-ms-client-request-id", requestId); + } + request.Headers.Add("DataServiceVersion", "3.0"); + request.Headers.Add("Content-Type", "application/json;odata=nometadata"); + if (tableEntityProperties != null) + { + using var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteStartObject(); + foreach (var item in tableEntityProperties) + { + content.JsonWriter.WritePropertyName(item.Key); + content.JsonWriter.WriteObjectValue(item.Value); + } + content.JsonWriter.WriteEndObject(); + request.Content = content; + } + return message; + } + + /// Update entity in a table. + /// The name of the table. + /// The partition key of the entity. + /// The row key of the entity. + /// The The timeout parameter is expressed in seconds. For more information, see <a href="https://docs.microsoft.com/en-us/rest/api/storageservices/setting-timeouts-for-queue-service-operations>Setting Timeouts for Queue Service Operations.</a>. + /// Provides a client-generated, opaque value with a 1 KB character limit that is recorded in the analytics logs when storage analytics logging is enabled. + /// The properties for the table entity. + /// Parameter group. + /// The cancellation token to use. + public async ValueTask> UpdateEntityAsync(string table, string partitionKey, string rowKey, int? timeout = null, string requestId = null, IDictionary tableEntityProperties = null, QueryOptions queryOptions = null, CancellationToken cancellationToken = default) + { + if (table == null) + { + throw new ArgumentNullException(nameof(table)); + } + if (partitionKey == null) + { + throw new ArgumentNullException(nameof(partitionKey)); + } + if (rowKey == null) + { + throw new ArgumentNullException(nameof(rowKey)); + } + + using var scope = _clientDiagnostics.CreateScope("TableClient.UpdateEntity"); + scope.Start(); + try + { + using var message = CreateUpdateEntityRequest(table, partitionKey, rowKey, timeout, requestId, tableEntityProperties, queryOptions); + await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); + var headers = new TableUpdateEntityHeaders(message.Response); + switch (message.Response.Status) + { + case 204: + return ResponseWithHeaders.FromValue(headers, message.Response); + default: + throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + } + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Update entity in a table. + /// The name of the table. + /// The partition key of the entity. + /// The row key of the entity. + /// The The timeout parameter is expressed in seconds. For more information, see <a href="https://docs.microsoft.com/en-us/rest/api/storageservices/setting-timeouts-for-queue-service-operations>Setting Timeouts for Queue Service Operations.</a>. + /// Provides a client-generated, opaque value with a 1 KB character limit that is recorded in the analytics logs when storage analytics logging is enabled. + /// The properties for the table entity. + /// Parameter group. + /// The cancellation token to use. + public ResponseWithHeaders UpdateEntity(string table, string partitionKey, string rowKey, int? timeout = null, string requestId = null, IDictionary tableEntityProperties = null, QueryOptions queryOptions = null, CancellationToken cancellationToken = default) + { + if (table == null) + { + throw new ArgumentNullException(nameof(table)); + } + if (partitionKey == null) + { + throw new ArgumentNullException(nameof(partitionKey)); + } + if (rowKey == null) + { + throw new ArgumentNullException(nameof(rowKey)); + } + + using var scope = _clientDiagnostics.CreateScope("TableClient.UpdateEntity"); + scope.Start(); + try + { + using var message = CreateUpdateEntityRequest(table, partitionKey, rowKey, timeout, requestId, tableEntityProperties, queryOptions); + _pipeline.Send(message, cancellationToken); + var headers = new TableUpdateEntityHeaders(message.Response); + switch (message.Response.Status) + { + case 204: + return ResponseWithHeaders.FromValue(headers, message.Response); + default: + throw _clientDiagnostics.CreateRequestFailedException(message.Response); + } + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + internal HttpMessage CreateDeleteEntityRequest(string table, string partitionKey, string rowKey, int? timeout, string requestId, QueryOptions queryOptions) + { + var message = _pipeline.CreateMessage(); + var request = message.Request; + request.Method = RequestMethod.Delete; + var uri = new RawRequestUriBuilder(); + uri.AppendRaw(url, false); + uri.AppendPath("/", false); + uri.AppendPath(table, true); + uri.AppendPath("(PartitionKey='", false); + uri.AppendPath(partitionKey, true); + uri.AppendPath("',RowKey='", false); + uri.AppendPath(rowKey, true); + uri.AppendPath("')", false); + if (timeout != null) + { + uri.AppendQuery("timeout", timeout.Value, true); + } + if (queryOptions?.Format != null) + { + uri.AppendQuery("$format", queryOptions.Format.Value.ToString(), true); + } + request.Uri = uri; + request.Headers.Add("x-ms-version", version); + if (requestId != null) + { + request.Headers.Add("x-ms-client-request-id", requestId); + } + request.Headers.Add("DataServiceVersion", "3.0"); + return message; + } + + /// Deletes the specified entity in a table. + /// The name of the table. + /// The partition key of the entity. + /// The row key of the entity. + /// The The timeout parameter is expressed in seconds. For more information, see <a href="https://docs.microsoft.com/en-us/rest/api/storageservices/setting-timeouts-for-queue-service-operations>Setting Timeouts for Queue Service Operations.</a>. + /// Provides a client-generated, opaque value with a 1 KB character limit that is recorded in the analytics logs when storage analytics logging is enabled. + /// Parameter group. + /// The cancellation token to use. + public async ValueTask> DeleteEntityAsync(string table, string partitionKey, string rowKey, int? timeout = null, string requestId = null, QueryOptions queryOptions = null, CancellationToken cancellationToken = default) + { + if (table == null) + { + throw new ArgumentNullException(nameof(table)); + } + if (partitionKey == null) + { + throw new ArgumentNullException(nameof(partitionKey)); + } + if (rowKey == null) + { + throw new ArgumentNullException(nameof(rowKey)); + } + + using var scope = _clientDiagnostics.CreateScope("TableClient.DeleteEntity"); + scope.Start(); + try + { + using var message = CreateDeleteEntityRequest(table, partitionKey, rowKey, timeout, requestId, queryOptions); + await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); + var headers = new TableDeleteEntityHeaders(message.Response); + switch (message.Response.Status) + { + case 204: + return ResponseWithHeaders.FromValue(headers, message.Response); + default: + throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + } + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Deletes the specified entity in a table. + /// The name of the table. + /// The partition key of the entity. + /// The row key of the entity. + /// The The timeout parameter is expressed in seconds. For more information, see <a href="https://docs.microsoft.com/en-us/rest/api/storageservices/setting-timeouts-for-queue-service-operations>Setting Timeouts for Queue Service Operations.</a>. + /// Provides a client-generated, opaque value with a 1 KB character limit that is recorded in the analytics logs when storage analytics logging is enabled. + /// Parameter group. + /// The cancellation token to use. + public ResponseWithHeaders DeleteEntity(string table, string partitionKey, string rowKey, int? timeout = null, string requestId = null, QueryOptions queryOptions = null, CancellationToken cancellationToken = default) + { + if (table == null) + { + throw new ArgumentNullException(nameof(table)); + } + if (partitionKey == null) + { + throw new ArgumentNullException(nameof(partitionKey)); + } + if (rowKey == null) + { + throw new ArgumentNullException(nameof(rowKey)); + } + + using var scope = _clientDiagnostics.CreateScope("TableClient.DeleteEntity"); + scope.Start(); + try + { + using var message = CreateDeleteEntityRequest(table, partitionKey, rowKey, timeout, requestId, queryOptions); + _pipeline.Send(message, cancellationToken); + var headers = new TableDeleteEntityHeaders(message.Response); + switch (message.Response.Status) + { + case 204: + return ResponseWithHeaders.FromValue(headers, message.Response); + default: + throw _clientDiagnostics.CreateRequestFailedException(message.Response); + } + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + internal HttpMessage CreateInsertEntityRequest(string table, int? timeout, string requestId, IDictionary tableEntityProperties, QueryOptions queryOptions) + { + var message = _pipeline.CreateMessage(); + var request = message.Request; + request.Method = RequestMethod.Post; + var uri = new RawRequestUriBuilder(); + uri.AppendRaw(url, false); + uri.AppendPath("/", false); + uri.AppendPath(table, true); + if (timeout != null) + { + uri.AppendQuery("timeout", timeout.Value, true); + } + if (queryOptions?.Format != null) + { + uri.AppendQuery("$format", queryOptions.Format.Value.ToString(), true); + } + request.Uri = uri; + request.Headers.Add("x-ms-version", version); + if (requestId != null) + { + request.Headers.Add("x-ms-client-request-id", requestId); + } + request.Headers.Add("DataServiceVersion", "3.0"); + request.Headers.Add("Content-Type", "application/json;odata=nometadata"); + if (tableEntityProperties != null) + { + using var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteStartObject(); + foreach (var item in tableEntityProperties) + { + content.JsonWriter.WritePropertyName(item.Key); + content.JsonWriter.WriteObjectValue(item.Value); + } + content.JsonWriter.WriteEndObject(); + request.Content = content; + } + return message; + } + + /// Insert entity in a table. + /// The name of the table. + /// The The timeout parameter is expressed in seconds. For more information, see <a href="https://docs.microsoft.com/en-us/rest/api/storageservices/setting-timeouts-for-queue-service-operations>Setting Timeouts for Queue Service Operations.</a>. + /// Provides a client-generated, opaque value with a 1 KB character limit that is recorded in the analytics logs when storage analytics logging is enabled. + /// The properties for the table entity. + /// Parameter group. + /// The cancellation token to use. + public async ValueTask, TableInsertEntityHeaders>> InsertEntityAsync(string table, int? timeout = null, string requestId = null, IDictionary tableEntityProperties = null, QueryOptions queryOptions = null, CancellationToken cancellationToken = default) + { + if (table == null) + { + throw new ArgumentNullException(nameof(table)); + } + + using var scope = _clientDiagnostics.CreateScope("TableClient.InsertEntity"); + scope.Start(); + try + { + using var message = CreateInsertEntityRequest(table, timeout, requestId, tableEntityProperties, queryOptions); + await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); + var headers = new TableInsertEntityHeaders(message.Response); + switch (message.Response.Status) + { + case 201: + { + IReadOnlyDictionary value = default; + using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, cancellationToken).ConfigureAwait(false); + if (document.RootElement.ValueKind == JsonValueKind.Null) + { + value = null; + } + else + { + Dictionary dictionary = new Dictionary(); + foreach (var property in document.RootElement.EnumerateObject()) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + dictionary.Add(property.Name, null); + } + else + { + dictionary.Add(property.Name, property.Value.GetObject()); + } + } + value = dictionary; + } + return ResponseWithHeaders.FromValue(value, headers, message.Response); + } + default: + throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + } + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Insert entity in a table. + /// The name of the table. + /// The The timeout parameter is expressed in seconds. For more information, see <a href="https://docs.microsoft.com/en-us/rest/api/storageservices/setting-timeouts-for-queue-service-operations>Setting Timeouts for Queue Service Operations.</a>. + /// Provides a client-generated, opaque value with a 1 KB character limit that is recorded in the analytics logs when storage analytics logging is enabled. + /// The properties for the table entity. + /// Parameter group. + /// The cancellation token to use. + public ResponseWithHeaders, TableInsertEntityHeaders> InsertEntity(string table, int? timeout = null, string requestId = null, IDictionary tableEntityProperties = null, QueryOptions queryOptions = null, CancellationToken cancellationToken = default) + { + if (table == null) + { + throw new ArgumentNullException(nameof(table)); + } + + using var scope = _clientDiagnostics.CreateScope("TableClient.InsertEntity"); + scope.Start(); + try + { + using var message = CreateInsertEntityRequest(table, timeout, requestId, tableEntityProperties, queryOptions); + _pipeline.Send(message, cancellationToken); + var headers = new TableInsertEntityHeaders(message.Response); + switch (message.Response.Status) + { + case 201: + { + IReadOnlyDictionary value = default; + using var document = JsonDocument.Parse(message.Response.ContentStream); + if (document.RootElement.ValueKind == JsonValueKind.Null) + { + value = null; + } + else + { + Dictionary dictionary = new Dictionary(); + foreach (var property in document.RootElement.EnumerateObject()) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + dictionary.Add(property.Name, null); + } + else + { + dictionary.Add(property.Name, property.Value.GetObject()); + } + } + value = dictionary; + } + return ResponseWithHeaders.FromValue(value, headers, message.Response); + } + default: + throw _clientDiagnostics.CreateRequestFailedException(message.Response); + } + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + internal HttpMessage CreateGetAccessPolicyRequest(string table, int? timeout, string requestId) + { + var message = _pipeline.CreateMessage(); + var request = message.Request; + request.Method = RequestMethod.Get; + var uri = new RawRequestUriBuilder(); + uri.AppendRaw(url, false); + uri.AppendPath("/", false); + uri.AppendPath(table, true); + if (timeout != null) + { + uri.AppendQuery("timeout", timeout.Value, true); + } + uri.AppendQuery("comp", "acl", true); + request.Uri = uri; + request.Headers.Add("x-ms-version", version); + if (requestId != null) + { + request.Headers.Add("x-ms-client-request-id", requestId); + } + return message; + } + + /// Retrieves details about any stored access policies specified on the table that may be used wit Shared Access Signatures. + /// The name of the table. + /// The The timeout parameter is expressed in seconds. For more information, see <a href="https://docs.microsoft.com/en-us/rest/api/storageservices/setting-timeouts-for-queue-service-operations>Setting Timeouts for Queue Service Operations.</a>. + /// Provides a client-generated, opaque value with a 1 KB character limit that is recorded in the analytics logs when storage analytics logging is enabled. + /// The cancellation token to use. + public async ValueTask, TableGetAccessPolicyHeaders>> GetAccessPolicyAsync(string table, int? timeout = null, string requestId = null, CancellationToken cancellationToken = default) + { + if (table == null) + { + throw new ArgumentNullException(nameof(table)); + } + + using var scope = _clientDiagnostics.CreateScope("TableClient.GetAccessPolicy"); + scope.Start(); + try + { + using var message = CreateGetAccessPolicyRequest(table, timeout, requestId); + await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); + var headers = new TableGetAccessPolicyHeaders(message.Response); + switch (message.Response.Status) + { + case 200: + { + IReadOnlyList value = default; + var document = XDocument.Load(message.Response.ContentStream, LoadOptions.PreserveWhitespace); + if (document.Element("SignedIdentifiers") is XElement signedIdentifiersElement) + { + var array = new List(); + foreach (var e in signedIdentifiersElement.Elements("SignedIdentifier")) + { + array.Add(SignedIdentifier.DeserializeSignedIdentifier(e)); + } + value = array; + } + return ResponseWithHeaders.FromValue(value, headers, message.Response); + } + default: + throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + } + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Retrieves details about any stored access policies specified on the table that may be used wit Shared Access Signatures. + /// The name of the table. + /// The The timeout parameter is expressed in seconds. For more information, see <a href="https://docs.microsoft.com/en-us/rest/api/storageservices/setting-timeouts-for-queue-service-operations>Setting Timeouts for Queue Service Operations.</a>. + /// Provides a client-generated, opaque value with a 1 KB character limit that is recorded in the analytics logs when storage analytics logging is enabled. + /// The cancellation token to use. + public ResponseWithHeaders, TableGetAccessPolicyHeaders> GetAccessPolicy(string table, int? timeout = null, string requestId = null, CancellationToken cancellationToken = default) + { + if (table == null) + { + throw new ArgumentNullException(nameof(table)); + } + + using var scope = _clientDiagnostics.CreateScope("TableClient.GetAccessPolicy"); + scope.Start(); + try + { + using var message = CreateGetAccessPolicyRequest(table, timeout, requestId); + _pipeline.Send(message, cancellationToken); + var headers = new TableGetAccessPolicyHeaders(message.Response); + switch (message.Response.Status) + { + case 200: + { + IReadOnlyList value = default; + var document = XDocument.Load(message.Response.ContentStream, LoadOptions.PreserveWhitespace); + if (document.Element("SignedIdentifiers") is XElement signedIdentifiersElement) + { + var array = new List(); + foreach (var e in signedIdentifiersElement.Elements("SignedIdentifier")) + { + array.Add(SignedIdentifier.DeserializeSignedIdentifier(e)); + } + value = array; + } + return ResponseWithHeaders.FromValue(value, headers, message.Response); + } + default: + throw _clientDiagnostics.CreateRequestFailedException(message.Response); + } + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + internal HttpMessage CreateSetAccessPolicyRequest(string table, int? timeout, string requestId, IEnumerable tableAcl) + { + var message = _pipeline.CreateMessage(); + var request = message.Request; + request.Method = RequestMethod.Put; + var uri = new RawRequestUriBuilder(); + uri.AppendRaw(url, false); + uri.AppendPath("/", false); + uri.AppendPath(table, true); + if (timeout != null) + { + uri.AppendQuery("timeout", timeout.Value, true); + } + uri.AppendQuery("comp", "acl", true); + request.Uri = uri; + request.Headers.Add("x-ms-version", version); + if (requestId != null) + { + request.Headers.Add("x-ms-client-request-id", requestId); + } + request.Headers.Add("Content-Type", "application/xml"); + if (tableAcl != null) + { + using var content = new XmlWriterContent(); + content.XmlWriter.WriteStartElement("SignedIdentifiers"); + foreach (var item in tableAcl) + { + content.XmlWriter.WriteObjectValue(item, "SignedIdentifier"); + } + content.XmlWriter.WriteEndElement(); + request.Content = content; + } + return message; + } + + /// sets stored access policies for the table that may be used with Shared Access Signatures. + /// The name of the table. + /// The The timeout parameter is expressed in seconds. For more information, see <a href="https://docs.microsoft.com/en-us/rest/api/storageservices/setting-timeouts-for-queue-service-operations>Setting Timeouts for Queue Service Operations.</a>. + /// Provides a client-generated, opaque value with a 1 KB character limit that is recorded in the analytics logs when storage analytics logging is enabled. + /// the acls for the table. + /// The cancellation token to use. + public async ValueTask> SetAccessPolicyAsync(string table, int? timeout = null, string requestId = null, IEnumerable tableAcl = null, CancellationToken cancellationToken = default) + { + if (table == null) + { + throw new ArgumentNullException(nameof(table)); + } + + using var scope = _clientDiagnostics.CreateScope("TableClient.SetAccessPolicy"); + scope.Start(); + try + { + using var message = CreateSetAccessPolicyRequest(table, timeout, requestId, tableAcl); + await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); + var headers = new TableSetAccessPolicyHeaders(message.Response); + switch (message.Response.Status) + { + case 204: + return ResponseWithHeaders.FromValue(headers, message.Response); + default: + throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + } + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// sets stored access policies for the table that may be used with Shared Access Signatures. + /// The name of the table. + /// The The timeout parameter is expressed in seconds. For more information, see <a href="https://docs.microsoft.com/en-us/rest/api/storageservices/setting-timeouts-for-queue-service-operations>Setting Timeouts for Queue Service Operations.</a>. + /// Provides a client-generated, opaque value with a 1 KB character limit that is recorded in the analytics logs when storage analytics logging is enabled. + /// the acls for the table. + /// The cancellation token to use. + public ResponseWithHeaders SetAccessPolicy(string table, int? timeout = null, string requestId = null, IEnumerable tableAcl = null, CancellationToken cancellationToken = default) + { + if (table == null) + { + throw new ArgumentNullException(nameof(table)); + } + + using var scope = _clientDiagnostics.CreateScope("TableClient.SetAccessPolicy"); + scope.Start(); + try + { + using var message = CreateSetAccessPolicyRequest(table, timeout, requestId, tableAcl); + _pipeline.Send(message, cancellationToken); + var headers = new TableSetAccessPolicyHeaders(message.Response); + switch (message.Response.Status) + { + case 204: + return ResponseWithHeaders.FromValue(headers, message.Response); + default: + throw _clientDiagnostics.CreateRequestFailedException(message.Response); + } + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + } +} diff --git a/sdk/tables/Azure.Data.Tables/src/Generated/Operations/TableSetAccessPolicyHeaders.cs b/sdk/tables/Azure.Data.Tables/src/Generated/Operations/TableSetAccessPolicyHeaders.cs new file mode 100644 index 000000000000..37be083cfe7e --- /dev/null +++ b/sdk/tables/Azure.Data.Tables/src/Generated/Operations/TableSetAccessPolicyHeaders.cs @@ -0,0 +1,22 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using Azure; +using Azure.Core; + +namespace Azure.Data.Tables +{ + internal class TableSetAccessPolicyHeaders + { + private readonly Response _response; + public TableSetAccessPolicyHeaders(Response response) + { + _response = response; + } + public string XMsVersion => _response.Headers.TryGetValue("x-ms-version", out string value) ? value : null; + } +} diff --git a/sdk/tables/Azure.Data.Tables/src/Generated/Operations/TableUpdateEntityHeaders.cs b/sdk/tables/Azure.Data.Tables/src/Generated/Operations/TableUpdateEntityHeaders.cs new file mode 100644 index 000000000000..a104f85a784d --- /dev/null +++ b/sdk/tables/Azure.Data.Tables/src/Generated/Operations/TableUpdateEntityHeaders.cs @@ -0,0 +1,22 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using Azure; +using Azure.Core; + +namespace Azure.Data.Tables +{ + internal class TableUpdateEntityHeaders + { + private readonly Response _response; + public TableUpdateEntityHeaders(Response response) + { + _response = response; + } + public string XMsVersion => _response.Headers.TryGetValue("x-ms-version", out string value) ? value : null; + } +} diff --git a/sdk/tables/Azure.Data.Tables/src/LoggingSettings.cs b/sdk/tables/Azure.Data.Tables/src/LoggingSettings.cs new file mode 100644 index 000000000000..c9a0d1da5524 --- /dev/null +++ b/sdk/tables/Azure.Data.Tables/src/LoggingSettings.cs @@ -0,0 +1,15 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +#nullable disable + +using Azure.Core; + +namespace Azure.Data.Tables.Models +{ + /// Azure Analytics Logging settings. + [CodeGenModel("Logging")] + public partial class LoggingSettings + { + } +} diff --git a/sdk/tables/Azure.Data.Tables/src/ServiceClient.cs b/sdk/tables/Azure.Data.Tables/src/ServiceClient.cs new file mode 100644 index 000000000000..3682dd4fbf83 --- /dev/null +++ b/sdk/tables/Azure.Data.Tables/src/ServiceClient.cs @@ -0,0 +1,13 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +namespace Azure.Data.Tables +{ + /// + /// Partial class stub for to override visibility of code generation. + /// + internal partial class ServiceClient + { + + } +} diff --git a/sdk/tables/Azure.Data.Tables/src/TableClient.cs b/sdk/tables/Azure.Data.Tables/src/TableClient.cs new file mode 100644 index 000000000000..c61c08de3e4a --- /dev/null +++ b/sdk/tables/Azure.Data.Tables/src/TableClient.cs @@ -0,0 +1,165 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.Collections.Generic; +using System.Threading; +using System.Threading.Tasks; +using Azure.Core; +using Azure.Core.Pipeline; +using Azure.Data.Tables.Models; + +namespace Azure.Data.Tables +{ + /// + /// The allows you to interact with Azure Storage + /// Tables. + /// + public class TableClient + { + private readonly string _table; + private readonly OdataMetadataFormat _format; + private readonly TableInternalClient _tableOperations; + + internal TableClient(string table, TableInternalClient tableOperations) + { + _tableOperations = tableOperations; + _table = table; + _format = OdataMetadataFormat.ApplicationJsonOdataFullmetadata; + } + + /// + /// Initializes a new instance of the + /// class for mocking. + /// + protected TableClient() + { } + + /// + /// Inserts a Table Entity into the Table. + /// + /// The entity to insert. + /// A controlling the request lifetime. + /// The inserted Table entity. + public virtual async Task>> InsertAsync(IDictionary entity, CancellationToken cancellationToken = default) => + await InsertInternalAsync(true, entity, cancellationToken).ConfigureAwait(false); + + /// + /// Inserts a Table Entity into the Table. + /// + /// The entity to insert. + /// A controlling the request lifetime. + /// The inserted Table entity. + public virtual Response> Insert(IDictionary entity, CancellationToken cancellationToken = default) => + InsertInternalAsync(false, entity, cancellationToken).EnsureCompleted(); + + /// + /// Updates the specified table entity. + /// + /// The partitionKey that identifies the table entity. + /// The rowKey that identifies the table entity. + /// The entity to update. + /// A controlling the request lifetime. + /// The indicating the result of the operation. + public virtual async Task UpdateAsync(string partitionKey, string rowKey, IDictionary entity, CancellationToken cancellationToken = default) => + await UpdateInternalAsync(true, partitionKey, rowKey, entity, cancellationToken).ConfigureAwait(false); + + /// + /// Updates the specified table entity. + /// + /// The partitionKey that identifies the table entity. + /// The rowKey that identifies the table entity. + /// The entity to update. + /// A controlling the request lifetime. + /// The indicating the result of the operation. + public virtual Response Update(string partitionKey, string rowKey, IDictionary entity, CancellationToken cancellationToken = default) => + UpdateInternalAsync(false, partitionKey, rowKey, entity, cancellationToken).EnsureCompleted(); + + /// + /// Queries entities in the table. + /// + /// Returns the desired properties of an entity from the set. + /// Returns only tables or entities that satisfy the specified filter. + /// Returns only the top n tables or entities from the set. + /// A controlling the request lifetime. + /// + public virtual AsyncPageable> QueryAsync(string select = null, string filter = null, int? top = null, CancellationToken cancellationToken = default) + { + //TODO: support continuation tokens + + return PageableHelpers.CreateAsyncEnumerable(async tableName => + { + var response = await _tableOperations.RestClient.QueryEntitiesAsync(_table, + queryOptions: new QueryOptions() { Format = _format, Top = top, Filter = filter, Select = @select }, + cancellationToken: cancellationToken) + .ConfigureAwait(false); + return Page.FromValues(response.Value.Value, response.Headers.XMsContinuationNextPartitionKey, response.GetRawResponse()); + }, (_, __) => throw new NotImplementedException()); + } + + /// + /// Queries entities in the table. + /// + /// Returns the desired properties of an entity from the set. + /// Returns only tables or entities that satisfy the specified filter. + /// Returns only the top n tables or entities from the set. + /// A controlling the request lifetime. + public virtual Pageable> Query(string select = null, string filter = null, int? top = null, CancellationToken cancellationToken = default) + { + //TODO: support continuation tokens + + return PageableHelpers.CreateEnumerable(tableName => + { + var response = _tableOperations.RestClient.QueryEntities(_table, + queryOptions: new QueryOptions() { Format = _format, Top = top, Filter = filter, Select = @select }, + cancellationToken: cancellationToken); + return Page.FromValues(response.Value.Value, response.Headers.XMsContinuationNextPartitionKey, response.GetRawResponse()); + }, (_, __) => throw new NotImplementedException()); + } + + internal async Task>> InsertInternalAsync(bool async, IDictionary entity, CancellationToken cancellationToken) + { + Response> response; + + if (async) + { + response = await _tableOperations.InsertEntityAsync( + _table, + tableEntityProperties: entity, + queryOptions: new QueryOptions() { Format = _format }, + cancellationToken: cancellationToken).ConfigureAwait(false); + } + { + response = _tableOperations.InsertEntity( + _table, + tableEntityProperties: entity, + queryOptions: new QueryOptions() { Format = _format }, + cancellationToken: cancellationToken); + } + + return response; + } + + internal async Task UpdateInternalAsync(bool async, string partitionKey, string rowKey, IDictionary entity, CancellationToken cancellationToken = default) + { + if (async) + { + return await _tableOperations.UpdateEntityAsync(_table, + partitionKey, + rowKey, + tableEntityProperties: entity, + queryOptions: new QueryOptions() { Format = _format }, + cancellationToken: cancellationToken).ConfigureAwait(false); + } + else + { + return _tableOperations.UpdateEntity(_table, + partitionKey, + rowKey, + tableEntityProperties: entity, + queryOptions: new QueryOptions() { Format = _format }, + cancellationToken: cancellationToken); + } + } + } +} diff --git a/sdk/tables/Azure.Data.Tables/src/TableClientOptions.cs b/sdk/tables/Azure.Data.Tables/src/TableClientOptions.cs new file mode 100644 index 000000000000..759523fcaf96 --- /dev/null +++ b/sdk/tables/Azure.Data.Tables/src/TableClientOptions.cs @@ -0,0 +1,32 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using Azure.Core; + +namespace Azure.Data.Tables +{ + public class TableClientOptions : ClientOptions + { + private const ServiceVersion Latest = ServiceVersion.V2018_10_10; + internal static TableClientOptions Default { get; } = new TableClientOptions(); + + public TableClientOptions(ServiceVersion serviceVersion = Latest) + { + VersionString = serviceVersion switch + { + ServiceVersion.V2018_10_10 => "2018-10-10", + _ => throw new ArgumentOutOfRangeException(nameof(serviceVersion)) + }; + } + + internal string VersionString { get; } + + public enum ServiceVersion + { +#pragma warning disable CA1707 + V2018_10_10 = 1 +#pragma warning restore CA1707 + } + } +} diff --git a/sdk/tables/Azure.Data.Tables/src/TableConstants.cs b/sdk/tables/Azure.Data.Tables/src/TableConstants.cs new file mode 100644 index 000000000000..7ad6c18f78db --- /dev/null +++ b/sdk/tables/Azure.Data.Tables/src/TableConstants.cs @@ -0,0 +1,15 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +namespace Azure.Data.Tables +{ + internal static class TableConstants + { + internal static class HeaderNames + { + public const string Date = "x-ms-date"; + public const string SharedKey = "SharedKeyLite"; + public const string Authorization = "Authorization"; + } + } +} diff --git a/sdk/tables/Azure.Data.Tables/src/TableServiceClient.cs b/sdk/tables/Azure.Data.Tables/src/TableServiceClient.cs new file mode 100644 index 000000000000..128db49e8d8b --- /dev/null +++ b/sdk/tables/Azure.Data.Tables/src/TableServiceClient.cs @@ -0,0 +1,86 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.Threading; +using Azure.Core; +using Azure.Core.Pipeline; +using Azure.Data.Tables.Models; + +namespace Azure.Data.Tables +{ + public class TableServiceClient + { + private readonly TableInternalClient _tableOperations; + private readonly OdataMetadataFormat _format = OdataMetadataFormat.ApplicationJsonOdataFullmetadata; + + public TableServiceClient(Uri endpoint, TablesSharedKeyCredential credential, TableClientOptions options = null) + { + Argument.AssertNotNull(endpoint, nameof(endpoint)); + Argument.AssertNotNull(credential, nameof(credential)); + + options ??= new TableClientOptions(); + + var endpoint1 = endpoint.ToString(); + var pipeline = HttpPipelineBuilder.Build(options, new TablesSharedKeyPipelinePolicy(credential)); + var diagnostics = new ClientDiagnostics(options); + _tableOperations = new TableInternalClient(diagnostics, pipeline, endpoint1, "2019-02-02"); + } + + /// + /// Initializes a new instance of the + /// class for mocking. + /// + protected TableServiceClient() + { } + + public TableClient GetTableClient(string tableName) + { + return new TableClient(tableName, _tableOperations); + } + + /// + /// Gets a list of tables from the storage account. + /// + /// Returns the desired properties of an entity from the set. + /// Returns only tables or entities that satisfy the specified filter. + /// Returns only the top n tables or entities from the set. + /// A controlling the request lifetime. + /// + public virtual AsyncPageable GetTablesAsync(string select = null, string filter = null, int? top = null, CancellationToken cancellationToken = default) + { + //TODO: support continuation tokens + + return PageableHelpers.CreateAsyncEnumerable(async _ => + { + var response = await _tableOperations.RestClient.QueryAsync( + null, + new QueryOptions() { Filter = filter, Select = select, Top = top, Format = _format }, + cancellationToken).ConfigureAwait(false); + return Page.FromValues(response.Value.Value, response.Headers.XMsContinuationNextTableName, response.GetRawResponse()); + }, (_, __) => throw new NotImplementedException()); + } + + /// + /// Gets a list of tables from the storage account. + /// + /// Returns the desired properties of an entity from the set. + /// Returns only tables or entities that satisfy the specified filter. + /// Returns only the top n tables or entities from the set. + /// A controlling the request lifetime. + /// + public virtual Pageable GetTables(string select = null, string filter = null, int? top = null, CancellationToken cancellationToken = default) + { + //TODO: support continuation tokens + + return PageableHelpers.CreateEnumerable(_ => + { + var response = _tableOperations.RestClient.Query( + null, + new QueryOptions() { Filter = filter, Select = select, Top = top, Format = _format }, + cancellationToken); + return Page.FromValues(response.Value.Value, response.Headers.XMsContinuationNextTableName, response.GetRawResponse()); + }, (_, __) => throw new NotImplementedException()); + } + } +} diff --git a/sdk/tables/Azure.Data.Tables/src/TablesSharedKeyCredential.cs b/sdk/tables/Azure.Data.Tables/src/TablesSharedKeyCredential.cs new file mode 100644 index 000000000000..4c0486c3408a --- /dev/null +++ b/sdk/tables/Azure.Data.Tables/src/TablesSharedKeyCredential.cs @@ -0,0 +1,78 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.Security.Cryptography; +using System.Text; +using System.Threading; + +namespace Azure.Data.Tables +{ + /// + /// A is a credential backed by + /// a Storage Account's name and one of its access keys. + /// + public class TablesSharedKeyCredential + { + /// + /// Gets the name of the Storage Account. + /// + public string AccountName { get; } + + /// + /// The value of a Storage Account access key. + /// + private byte[] _accountKeyValue; + + /// + /// Gets the value of a Storage Account access key. + /// + private byte[] AccountKeyValue + { + get => Volatile.Read(ref _accountKeyValue); + set => Volatile.Write(ref _accountKeyValue, value); + } + + /// + /// Initializes a new instance of the + /// class. + /// + /// The name of the Storage Account. + /// A Storage Account access key. + public TablesSharedKeyCredential( + string accountName, + string accountKey) + { + AccountName = accountName; + SetAccountKey(accountKey); + } + + /// + /// Update the Storage Account's access key. This intended to be used + /// when you've regenerated your Storage Account's access keys and want + /// to update long lived clients. + /// + /// A Storage Account access key. + public void SetAccountKey(string accountKey) => + AccountKeyValue = Convert.FromBase64String(accountKey); + + /// + /// Generates a base-64 hash signature string for an HTTP request or + /// for a SAS. + /// + /// The message to sign. + /// The signed message. + internal string ComputeHMACSHA256(string message) => + Convert.ToBase64String(new HMACSHA256(AccountKeyValue).ComputeHash(Encoding.UTF8.GetBytes(message))); + + /// + /// Generates a base-64 hash signature string for an HTTP request or + /// for a SAS. + /// + /// The credential. + /// The message to sign. + /// The signed message. + protected static string ComputeSasSignature(TablesSharedKeyCredential credential, string message) => + credential.ComputeHMACSHA256(message); + } +} diff --git a/sdk/tables/Azure.Data.Tables/src/TablesSharedKeyPipelinePolicy.cs b/sdk/tables/Azure.Data.Tables/src/TablesSharedKeyPipelinePolicy.cs new file mode 100644 index 000000000000..ff667434efd7 --- /dev/null +++ b/sdk/tables/Azure.Data.Tables/src/TablesSharedKeyPipelinePolicy.cs @@ -0,0 +1,136 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Net; +using System.Net.Http.Headers; +using System.Security.Cryptography; +using System.Text; +using Azure.Core; +using Azure.Core.Pipeline; + +namespace Azure.Data.Tables +{ + /// + /// HttpPipelinePolicy to sign requests using an Azure Storage shared key. + /// + internal sealed class TablesSharedKeyPipelinePolicy : HttpPipelineSynchronousPolicy + { + private class InternalStorageCredential: TablesSharedKeyCredential + { + public static InternalStorageCredential Instance = new InternalStorageCredential(); + public InternalStorageCredential(): base(string.Empty, string.Empty) + { + } + + public static string GetSas(TablesSharedKeyCredential credential, string message) + { + return ComputeSasSignature(credential, message); + } + } + /// + /// Shared key credentials used to sign requests + /// + private readonly TablesSharedKeyCredential _credentials; + + /// + /// Create a new SharedKeyPipelinePolicy + /// + /// SharedKeyCredentials to authenticate requests. + public TablesSharedKeyPipelinePolicy(TablesSharedKeyCredential credentials) + => _credentials = credentials; + + /// + /// Sign the request using the shared key credentials. + /// + /// The message with the request to sign. + public override void OnSendingRequest(HttpMessage message) + { + base.OnSendingRequest(message); + + var date = DateTimeOffset.UtcNow.ToString("r", CultureInfo.InvariantCulture); + message.Request.Headers.SetValue(TableConstants.HeaderNames.Date, date); + + var stringToSign = BuildStringToSign(message); + var signature = InternalStorageCredential.GetSas(_credentials, stringToSign); + + var key = new AuthenticationHeaderValue(TableConstants.HeaderNames.SharedKey, _credentials.AccountName + ":" + signature).ToString(); + message.Request.Headers.SetValue(TableConstants.HeaderNames.Authorization, key); + } + + private string BuildStringToSign(HttpMessage message) + { + // https://docs.microsoft.com/en-us/rest/api/storageservices/authorize-with-shared-key + + message.Request.Headers.TryGetValue(TableConstants.HeaderNames.Date, out var date); + + var stringToSign = string.Join("\n", + date, + BuildCanonicalizedResource(message.Request.Uri.ToUri())); + return stringToSign; + } + + private string BuildCanonicalizedResource(Uri resource) + { + // https://docs.microsoft.com/en-us/rest/api/storageservices/authentication-for-the-azure-storage-services + StringBuilder cr = new StringBuilder("/").Append(_credentials.AccountName); + if (resource.AbsolutePath.Length > 0) + { + // Any portion of the CanonicalizedResource string that is derived from + // the resource's URI should be encoded exactly as it is in the URI. + // -- https://msdn.microsoft.com/en-gb/library/azure/dd179428.aspx + cr.Append(resource.AbsolutePath);//EscapedPath() + } + else + { + // a slash is required to indicate the root path + cr.Append('/'); + } + + System.Collections.Generic.IDictionary parameters = GetQueryParameters(resource); // Returns URL decoded values + if (parameters.Count > 0) + { + foreach (var name in parameters.Keys.OrderBy(key => key, StringComparer.Ordinal)) + { + if (name == "comp") + { +#pragma warning disable CA1308 // Normalize strings to uppercase + cr.Append('\n').Append(name.ToLowerInvariant()).Append(':').Append(parameters[name]); +#pragma warning restore CA1308 // Normalize strings to uppercase + } + } + } + return cr.ToString(); + } + public static IDictionary GetQueryParameters(Uri uri) + { + var parameters = new Dictionary(); + var query = uri.Query ?? ""; + if (!string.IsNullOrEmpty(query)) + { + if (query.StartsWith("?", true, CultureInfo.InvariantCulture)) + { + query = query.Substring(1); + } + foreach (var param in query.Split(new[] { '&' }, StringSplitOptions.RemoveEmptyEntries)) + { + var parts = param.Split(new[] { '=' }, 2); + var name = WebUtility.UrlDecode(parts[0]); + if (parts.Length == 1) + { + parameters.Add(name, default); + } + else + { + parameters.Add(name, WebUtility.UrlDecode(parts[1])); + } + } + } + return parameters; + } + + } +} diff --git a/sdk/tables/Azure.Data.Tables/src/autorest.md b/sdk/tables/Azure.Data.Tables/src/autorest.md new file mode 100644 index 000000000000..111f529494a1 --- /dev/null +++ b/sdk/tables/Azure.Data.Tables/src/autorest.md @@ -0,0 +1,12 @@ +# Azure.Data.Tables + +### AutoRest Configuration +> see https://aka.ms/autorest + +``` yaml +title: Azure.Data.Tables +input-file: + - https://github.com/shurd/azure-rest-api-specs/tree/tablesSwagger/specification/cosmos-db/data-plane/Microsoft.TablesStorage/preview/2018-10-10/table.json +namespace: Azure.Data.Tables +include-csproj: disable +``` diff --git a/sdk/tables/Azure.Data.Tables/src/swagger/OdataMetadataFormat.cs b/sdk/tables/Azure.Data.Tables/src/swagger/OdataMetadataFormat.cs new file mode 100644 index 000000000000..1590981e0417 --- /dev/null +++ b/sdk/tables/Azure.Data.Tables/src/swagger/OdataMetadataFormat.cs @@ -0,0 +1,15 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +#nullable disable + +using Azure.Core; + +namespace Azure.Data.Tables.Models +{ + /// The OdataMetadataFormat. + [CodeGenModel("Enum0")] + public readonly partial struct OdataMetadataFormat + { + } +} diff --git a/sdk/tables/Azure.Data.Tables/src/swagger/RequestMetrics.cs b/sdk/tables/Azure.Data.Tables/src/swagger/RequestMetrics.cs new file mode 100644 index 000000000000..be25ada55b1d --- /dev/null +++ b/sdk/tables/Azure.Data.Tables/src/swagger/RequestMetrics.cs @@ -0,0 +1,15 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +#nullable disable + +using Azure.Core; + +namespace Azure.Data.Tables.Models +{ + /// The RequestMetrics. + [CodeGenModel("Metrics")] + public partial class RequestMetrics + { + } +} diff --git a/sdk/tables/Azure.Data.Tables/src/swagger/TableInternalClient.cs b/sdk/tables/Azure.Data.Tables/src/swagger/TableInternalClient.cs new file mode 100644 index 000000000000..b24c42060d44 --- /dev/null +++ b/sdk/tables/Azure.Data.Tables/src/swagger/TableInternalClient.cs @@ -0,0 +1,12 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using Azure.Core; + +namespace Azure.Data.Tables +{ + [CodeGenClient("TableClient")] + internal partial class TableInternalClient + { + } +} diff --git a/sdk/tables/Azure.Data.Tables/tests/Azure.Data.Tables.Tests.csproj b/sdk/tables/Azure.Data.Tables/tests/Azure.Data.Tables.Tests.csproj new file mode 100644 index 000000000000..7a19effc2f82 --- /dev/null +++ b/sdk/tables/Azure.Data.Tables/tests/Azure.Data.Tables.Tests.csproj @@ -0,0 +1,19 @@ + + + $(RequiredTargetFrameworks) + false + + + + + + + + + + + + + + + diff --git a/sdk/tables/Azure.Data.Tables/tests/TableServiceClientTests.cs b/sdk/tables/Azure.Data.Tables/tests/TableServiceClientTests.cs new file mode 100644 index 000000000000..b906c38b70ad --- /dev/null +++ b/sdk/tables/Azure.Data.Tables/tests/TableServiceClientTests.cs @@ -0,0 +1,36 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.Threading.Tasks; +using Azure.Data.Tables; +using NUnit.Framework; + +namespace Microsoft.Azure.Storage.Tables.Tests +{ + public class TableServiceClientTests + { + /// + /// The table account name. + /// + private readonly string _accountName = "someaccount"; + + /// + /// The table endpoint. + /// + private readonly Uri _url = new Uri($"https://someaccount.table.core.windows.net"); + + /// + /// Validates the functionality of the TableServiceClient. + /// + [Test] + public void ConstructorValidatesArguments() + { + Assert.That(() => new TableServiceClient(null, new TablesSharedKeyCredential(_accountName, string.Empty)), Throws.InstanceOf(), "The constructor should validate the url."); + + Assert.That(() => new TableServiceClient(_url, null), Throws.InstanceOf(), "The constructor should validate the TablesSharedKeyCredential."); + + Assert.That(() => new TableServiceClient(_url, new TablesSharedKeyCredential(_accountName, string.Empty)), Throws.Nothing, "The constructor should validate the url."); + } + } +} diff --git a/sdk/tables/ci.yml b/sdk/tables/ci.yml new file mode 100644 index 000000000000..4f3b5bb907bd --- /dev/null +++ b/sdk/tables/ci.yml @@ -0,0 +1,42 @@ +# DO NOT EDIT THIS FILE +# This file is generated automatically and any changes will be lost. + +resources: + repositories: + - repository: azure-sdk-tools + type: github + name: Azure/azure-sdk-tools + endpoint: azure + - repository: azure-sdk-build-tools + type: git + name: internal/azure-sdk-build-tools + +trigger: + branches: + include: + - master + - hotfix/* + - release/* + paths: + include: + - sdk/tables/ + +pr: + branches: + include: + - master + - feature/* + - hotfix/* + - release/* + paths: + include: + - sdk/tables/ + +stages: +- template: ../../eng/pipelines/templates/stages/archetype-sdk-client.yml + parameters: + ServiceDirectory: tables + ArtifactName: packages + Artifacts: + - name: Azure.Data.Tables + safeName: AzureDataTables diff --git a/sdk/tables/tests.yml b/sdk/tables/tests.yml new file mode 100644 index 000000000000..edcb2d52a9e7 --- /dev/null +++ b/sdk/tables/tests.yml @@ -0,0 +1,13 @@ +trigger: none + +resources: + repositories: + - repository: azure-sdk-tools + type: github + name: Azure/azure-sdk-tools + endpoint: azure + +jobs: +- template: ../../eng/pipelines/templates/jobs/archetype-sdk-tests.yml + parameters: + ServiceDirectory: tables \ No newline at end of file