From 1cbb0fa561a132cdffa0c737348b0a812f08a15c Mon Sep 17 00:00:00 2001 From: SDKAuto Date: Tue, 9 Nov 2021 17:45:23 +0000 Subject: [PATCH] CodeGen from PR 16716 in Azure/azure-rest-api-specs Merge 9893aa5afa2b4b04b4ca6f5945d9ff543719470b into aa023775478d1d141b456f9831685188ce6d13ab --- .../IServerConnectionPoliciesOperations.cs | 87 +++- .../src/Generated/ISqlManagementClient.cs | 10 +- .../Models/ServerConnectionPolicy.cs | 30 +- .../Generated/Models/ServerConnectionType.cs | 51 +- .../Generated/SdkInfo_SqlManagementClient.cs | 13 +- .../ServerConnectionPoliciesOperations.cs | 460 ++++++++++++++++-- ...rConnectionPoliciesOperationsExtensions.cs | 144 +++++- .../src/Generated/SqlManagementClient.cs | 12 +- 8 files changed, 668 insertions(+), 139 deletions(-) diff --git a/sdk/sqlmanagement/Microsoft.Azure.Management.Sql/src/Generated/IServerConnectionPoliciesOperations.cs b/sdk/sqlmanagement/Microsoft.Azure.Management.Sql/src/Generated/IServerConnectionPoliciesOperations.cs index 83d40613d8a89..cf1023e6228a4 100644 --- a/sdk/sqlmanagement/Microsoft.Azure.Management.Sql/src/Generated/IServerConnectionPoliciesOperations.cs +++ b/sdk/sqlmanagement/Microsoft.Azure.Management.Sql/src/Generated/IServerConnectionPoliciesOperations.cs @@ -24,7 +24,34 @@ namespace Microsoft.Azure.Management.Sql public partial interface IServerConnectionPoliciesOperations { /// - /// Creates or updates the server's connection policy. + /// Gets a server connection policy + /// + /// + /// The name of the resource group that contains the resource. You can + /// obtain this value from the Azure Resource Manager API or the + /// portal. + /// + /// + /// The name of the server. + /// + /// + /// The headers that will be added to request. + /// + /// + /// The cancellation token. + /// + /// + /// Thrown when the operation returned an invalid status code + /// + /// + /// Thrown when unable to deserialize the response + /// + /// + /// Thrown when a required parameter is null + /// + Task> GetWithHttpMessagesAsync(string resourceGroupName, string serverName, Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken)); + /// + /// Updates a server connection policy /// /// /// The name of the resource group that contains the resource. You can @@ -35,7 +62,7 @@ public partial interface IServerConnectionPoliciesOperations /// The name of the server. /// /// - /// The required parameters for updating a secure connection policy. + /// The required parameters for updating a server connection policy. /// /// /// The headers that will be added to request. @@ -54,7 +81,7 @@ public partial interface IServerConnectionPoliciesOperations /// Task> CreateOrUpdateWithHttpMessagesAsync(string resourceGroupName, string serverName, ServerConnectionPolicy parameters, Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken)); /// - /// Gets the server's secure connection policy. + /// Lists connection policy /// /// /// The name of the resource group that contains the resource. You can @@ -79,6 +106,58 @@ public partial interface IServerConnectionPoliciesOperations /// /// Thrown when a required parameter is null /// - Task> GetWithHttpMessagesAsync(string resourceGroupName, string serverName, Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken)); + Task>> ListByServerWithHttpMessagesAsync(string resourceGroupName, string serverName, Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken)); + /// + /// Updates a server connection policy + /// + /// + /// The name of the resource group that contains the resource. You can + /// obtain this value from the Azure Resource Manager API or the + /// portal. + /// + /// + /// The name of the server. + /// + /// + /// The required parameters for updating a server connection policy. + /// + /// + /// The headers that will be added to request. + /// + /// + /// The cancellation token. + /// + /// + /// Thrown when the operation returned an invalid status code + /// + /// + /// Thrown when unable to deserialize the response + /// + /// + /// Thrown when a required parameter is null + /// + Task> BeginCreateOrUpdateWithHttpMessagesAsync(string resourceGroupName, string serverName, ServerConnectionPolicy parameters, Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken)); + /// + /// Lists connection policy + /// + /// + /// The NextLink from the previous successful call to List operation. + /// + /// + /// The headers that will be added to request. + /// + /// + /// The cancellation token. + /// + /// + /// Thrown when the operation returned an invalid status code + /// + /// + /// Thrown when unable to deserialize the response + /// + /// + /// Thrown when a required parameter is null + /// + Task>> ListByServerNextWithHttpMessagesAsync(string nextPageLink, Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken)); } } diff --git a/sdk/sqlmanagement/Microsoft.Azure.Management.Sql/src/Generated/ISqlManagementClient.cs b/sdk/sqlmanagement/Microsoft.Azure.Management.Sql/src/Generated/ISqlManagementClient.cs index d0a8ca5969cd0..30f6236eec99c 100644 --- a/sdk/sqlmanagement/Microsoft.Azure.Management.Sql/src/Generated/ISqlManagementClient.cs +++ b/sdk/sqlmanagement/Microsoft.Azure.Management.Sql/src/Generated/ISqlManagementClient.cs @@ -72,11 +72,6 @@ public partial interface ISqlManagementClient : System.IDisposable /// IRecoverableDatabasesOperations RecoverableDatabases { get; } - /// - /// Gets the IServerConnectionPoliciesOperations. - /// - IServerConnectionPoliciesOperations ServerConnectionPolicies { get; } - /// /// Gets the IDataMaskingPoliciesOperations. /// @@ -662,5 +657,10 @@ public partial interface ISqlManagementClient : System.IDisposable /// IUsagesOperations Usages { get; } + /// + /// Gets the IServerConnectionPoliciesOperations. + /// + IServerConnectionPoliciesOperations ServerConnectionPolicies { get; } + } } diff --git a/sdk/sqlmanagement/Microsoft.Azure.Management.Sql/src/Generated/Models/ServerConnectionPolicy.cs b/sdk/sqlmanagement/Microsoft.Azure.Management.Sql/src/Generated/Models/ServerConnectionPolicy.cs index 3e71ad3d28b3e..05a5667a31df8 100644 --- a/sdk/sqlmanagement/Microsoft.Azure.Management.Sql/src/Generated/Models/ServerConnectionPolicy.cs +++ b/sdk/sqlmanagement/Microsoft.Azure.Management.Sql/src/Generated/Models/ServerConnectionPolicy.cs @@ -16,7 +16,7 @@ namespace Microsoft.Azure.Management.Sql.Models using System.Linq; /// - /// A server secure connection policy. + /// A server connection policy /// [Rest.Serialization.JsonTransformation] public partial class ServerConnectionPolicy : ProxyResource @@ -33,18 +33,18 @@ public ServerConnectionPolicy() /// Initializes a new instance of the ServerConnectionPolicy class. /// /// The server connection type. Possible - /// values include: 'Default', 'Proxy', 'Redirect' + /// values include: 'Default', 'Redirect', 'Proxy' /// Resource ID. /// Resource name. /// Resource type. + /// Resource location. /// Metadata used for the Azure portal /// experience. - /// Resource location. - public ServerConnectionPolicy(ServerConnectionType connectionType, string id = default(string), string name = default(string), string type = default(string), string kind = default(string), string location = default(string)) + public ServerConnectionPolicy(string connectionType, string id = default(string), string name = default(string), string type = default(string), string location = default(string), string kind = default(string)) : base(id, name, type) { - Kind = kind; Location = location; + Kind = kind; ConnectionType = connectionType; CustomInit(); } @@ -54,24 +54,24 @@ public ServerConnectionPolicy() /// partial void CustomInit(); - /// - /// Gets metadata used for the Azure portal experience. - /// - [JsonProperty(PropertyName = "kind")] - public string Kind { get; private set; } - /// /// Gets resource location. /// [JsonProperty(PropertyName = "location")] public string Location { get; private set; } + /// + /// Gets metadata used for the Azure portal experience. + /// + [JsonProperty(PropertyName = "kind")] + public string Kind { get; private set; } + /// /// Gets or sets the server connection type. Possible values include: - /// 'Default', 'Proxy', 'Redirect' + /// 'Default', 'Redirect', 'Proxy' /// [JsonProperty(PropertyName = "properties.connectionType")] - public ServerConnectionType ConnectionType { get; set; } + public string ConnectionType { get; set; } /// /// Validate the object. @@ -81,6 +81,10 @@ public ServerConnectionPolicy() /// public virtual void Validate() { + if (ConnectionType == null) + { + throw new ValidationException(ValidationRules.CannotBeNull, "ConnectionType"); + } } } } diff --git a/sdk/sqlmanagement/Microsoft.Azure.Management.Sql/src/Generated/Models/ServerConnectionType.cs b/sdk/sqlmanagement/Microsoft.Azure.Management.Sql/src/Generated/Models/ServerConnectionType.cs index ad0ffc408e10a..ee0c78faea964 100644 --- a/sdk/sqlmanagement/Microsoft.Azure.Management.Sql/src/Generated/Models/ServerConnectionType.cs +++ b/sdk/sqlmanagement/Microsoft.Azure.Management.Sql/src/Generated/Models/ServerConnectionType.cs @@ -10,57 +10,14 @@ namespace Microsoft.Azure.Management.Sql.Models { - using Newtonsoft.Json; - using Newtonsoft.Json.Converters; - using System.Runtime; - using System.Runtime.Serialization; /// /// Defines values for ServerConnectionType. /// - [JsonConverter(typeof(StringEnumConverter))] - public enum ServerConnectionType + public static class ServerConnectionType { - [EnumMember(Value = "Default")] - Default, - [EnumMember(Value = "Proxy")] - Proxy, - [EnumMember(Value = "Redirect")] - Redirect - } - internal static class ServerConnectionTypeEnumExtension - { - internal static string ToSerializedValue(this ServerConnectionType? value) - { - return value == null ? null : ((ServerConnectionType)value).ToSerializedValue(); - } - - internal static string ToSerializedValue(this ServerConnectionType value) - { - switch( value ) - { - case ServerConnectionType.Default: - return "Default"; - case ServerConnectionType.Proxy: - return "Proxy"; - case ServerConnectionType.Redirect: - return "Redirect"; - } - return null; - } - - internal static ServerConnectionType? ParseServerConnectionType(this string value) - { - switch( value ) - { - case "Default": - return ServerConnectionType.Default; - case "Proxy": - return ServerConnectionType.Proxy; - case "Redirect": - return ServerConnectionType.Redirect; - } - return null; - } + public const string Default = "Default"; + public const string Redirect = "Redirect"; + public const string Proxy = "Proxy"; } } diff --git a/sdk/sqlmanagement/Microsoft.Azure.Management.Sql/src/Generated/SdkInfo_SqlManagementClient.cs b/sdk/sqlmanagement/Microsoft.Azure.Management.Sql/src/Generated/SdkInfo_SqlManagementClient.cs index 7887aab164be0..f87a57d6c33ec 100644 --- a/sdk/sqlmanagement/Microsoft.Azure.Management.Sql/src/Generated/SdkInfo_SqlManagementClient.cs +++ b/sdk/sqlmanagement/Microsoft.Azure.Management.Sql/src/Generated/SdkInfo_SqlManagementClient.cs @@ -117,7 +117,7 @@ public static IEnumerable> ApiInfo_SqlManagementCl new Tuple("Sql", "ServerAzureADOnlyAuthentications", "2020-11-01-preview"), new Tuple("Sql", "ServerBlobAuditingPolicies", "2020-11-01-preview"), new Tuple("Sql", "ServerCommunicationLinks", "2014-04-01"), - new Tuple("Sql", "ServerConnectionPolicies", "2014-04-01"), + new Tuple("Sql", "ServerConnectionPolicies", "2021-05-01-preview"), new Tuple("Sql", "ServerDevOpsAuditSettings", "2020-11-01-preview"), new Tuple("Sql", "ServerDnsAliases", "2020-11-01-preview"), new Tuple("Sql", "ServerKeys", "2020-11-01-preview"), @@ -144,16 +144,5 @@ public static IEnumerable> ApiInfo_SqlManagementCl }.AsEnumerable(); } } - // BEGIN: Code Generation Metadata Section - public static readonly String AutoRestVersion = "v2"; - public static readonly String AutoRestBootStrapperVersion = "autorest@2.0.4413"; - public static readonly String AutoRestCmdExecuted = "cmd.exe /c autorest.cmd https://github.com/Azure/azure-rest-api-specs/blob/main/specification/sql/resource-manager/readme.md --csharp --version=v2 --reflect-api-versions --csharp-sdks-folder=F:\\sdk\\azure-sdk-for-net\\sdk"; - public static readonly String GithubForkName = "Azure"; - public static readonly String GithubBranchName = "main"; - public static readonly String GithubCommidId = "5f32b50e18ed0a91eefe39287078bf66c4d6c3a8"; - public static readonly String CodeGenerationErrors = ""; - public static readonly String GithubRepoName = "azure-rest-api-specs"; - // END: Code Generation Metadata Section } } - diff --git a/sdk/sqlmanagement/Microsoft.Azure.Management.Sql/src/Generated/ServerConnectionPoliciesOperations.cs b/sdk/sqlmanagement/Microsoft.Azure.Management.Sql/src/Generated/ServerConnectionPoliciesOperations.cs index 4f9dd45213eb3..b520a06bb6a83 100644 --- a/sdk/sqlmanagement/Microsoft.Azure.Management.Sql/src/Generated/ServerConnectionPoliciesOperations.cs +++ b/sdk/sqlmanagement/Microsoft.Azure.Management.Sql/src/Generated/ServerConnectionPoliciesOperations.cs @@ -51,7 +51,7 @@ internal ServerConnectionPoliciesOperations(SqlManagementClient client) public SqlManagementClient Client { get; private set; } /// - /// Creates or updates the server's connection policy. + /// Gets a server connection policy /// /// /// The name of the resource group that contains the resource. You can obtain @@ -60,9 +60,6 @@ internal ServerConnectionPoliciesOperations(SqlManagementClient client) /// /// The name of the server. /// - /// - /// The required parameters for updating a secure connection policy. - /// /// /// Headers that will be added to request. /// @@ -84,12 +81,8 @@ internal ServerConnectionPoliciesOperations(SqlManagementClient client) /// /// A response object containing the response body and response headers. /// - public async Task> CreateOrUpdateWithHttpMessagesAsync(string resourceGroupName, string serverName, ServerConnectionPolicy parameters, Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken)) + public async Task> GetWithHttpMessagesAsync(string resourceGroupName, string serverName, Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken)) { - if (Client.SubscriptionId == null) - { - throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.SubscriptionId"); - } if (resourceGroupName == null) { throw new ValidationException(ValidationRules.CannotBeNull, "resourceGroupName"); @@ -98,16 +91,12 @@ internal ServerConnectionPoliciesOperations(SqlManagementClient client) { throw new ValidationException(ValidationRules.CannotBeNull, "serverName"); } - if (parameters == null) - { - throw new ValidationException(ValidationRules.CannotBeNull, "parameters"); - } - if (parameters != null) + if (Client.SubscriptionId == null) { - parameters.Validate(); + throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.SubscriptionId"); } - string apiVersion = "2014-04-01"; string connectionPolicyName = "default"; + string apiVersion = "2021-05-01-preview"; // Tracing bool _shouldTrace = ServiceClientTracing.IsEnabled; string _invocationId = null; @@ -115,21 +104,20 @@ internal ServerConnectionPoliciesOperations(SqlManagementClient client) { _invocationId = ServiceClientTracing.NextInvocationId.ToString(); Dictionary tracingParameters = new Dictionary(); - tracingParameters.Add("apiVersion", apiVersion); tracingParameters.Add("resourceGroupName", resourceGroupName); tracingParameters.Add("serverName", serverName); tracingParameters.Add("connectionPolicyName", connectionPolicyName); - tracingParameters.Add("parameters", parameters); + tracingParameters.Add("apiVersion", apiVersion); tracingParameters.Add("cancellationToken", cancellationToken); - ServiceClientTracing.Enter(_invocationId, this, "CreateOrUpdate", tracingParameters); + ServiceClientTracing.Enter(_invocationId, this, "Get", tracingParameters); } // Construct URL var _baseUrl = Client.BaseUri.AbsoluteUri; var _url = new System.Uri(new System.Uri(_baseUrl + (_baseUrl.EndsWith("/") ? "" : "/")), "subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/connectionPolicies/{connectionPolicyName}").ToString(); - _url = _url.Replace("{subscriptionId}", System.Uri.EscapeDataString(Client.SubscriptionId)); _url = _url.Replace("{resourceGroupName}", System.Uri.EscapeDataString(resourceGroupName)); _url = _url.Replace("{serverName}", System.Uri.EscapeDataString(serverName)); _url = _url.Replace("{connectionPolicyName}", System.Uri.EscapeDataString(connectionPolicyName)); + _url = _url.Replace("{subscriptionId}", System.Uri.EscapeDataString(Client.SubscriptionId)); List _queryParameters = new List(); if (apiVersion != null) { @@ -142,7 +130,7 @@ internal ServerConnectionPoliciesOperations(SqlManagementClient client) // Create HTTP transport objects var _httpRequest = new HttpRequestMessage(); HttpResponseMessage _httpResponse = null; - _httpRequest.Method = new HttpMethod("PUT"); + _httpRequest.Method = new HttpMethod("GET"); _httpRequest.RequestUri = new System.Uri(_url); // Set Headers if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value) @@ -173,12 +161,6 @@ internal ServerConnectionPoliciesOperations(SqlManagementClient client) // Serialize Request string _requestContent = null; - if(parameters != null) - { - _requestContent = Rest.Serialization.SafeJsonConvert.SerializeObject(parameters, Client.SerializationSettings); - _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8); - _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json; charset=utf-8"); - } // Set Credentials if (Client.Credentials != null) { @@ -199,7 +181,7 @@ internal ServerConnectionPoliciesOperations(SqlManagementClient client) HttpStatusCode _statusCode = _httpResponse.StatusCode; cancellationToken.ThrowIfCancellationRequested(); string _responseContent = null; - if ((int)_statusCode != 200 && (int)_statusCode != 201) + if ((int)_statusCode != 200) { var ex = new CloudException(string.Format("Operation returned an invalid status code '{0}'", _statusCode)); try @@ -259,13 +241,216 @@ internal ServerConnectionPoliciesOperations(SqlManagementClient client) throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); } } + if (_shouldTrace) + { + ServiceClientTracing.Exit(_invocationId, _result); + } + return _result; + } + + /// + /// Updates a server connection policy + /// + /// + /// The name of the resource group that contains the resource. You can obtain + /// this value from the Azure Resource Manager API or the portal. + /// + /// + /// The name of the server. + /// + /// + /// The required parameters for updating a server connection policy. + /// + /// + /// The headers that will be added to request. + /// + /// + /// The cancellation token. + /// + public async Task> CreateOrUpdateWithHttpMessagesAsync(string resourceGroupName, string serverName, ServerConnectionPolicy parameters, Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken)) + { + // Send Request + AzureOperationResponse _response = await BeginCreateOrUpdateWithHttpMessagesAsync(resourceGroupName, serverName, parameters, customHeaders, cancellationToken).ConfigureAwait(false); + return await Client.GetPutOrPatchOperationResultAsync(_response, customHeaders, cancellationToken).ConfigureAwait(false); + } + + /// + /// Lists connection policy + /// + /// + /// The name of the resource group that contains the resource. You can obtain + /// this value from the Azure Resource Manager API or the portal. + /// + /// + /// The name of the server. + /// + /// + /// Headers that will be added to request. + /// + /// + /// The cancellation token. + /// + /// + /// Thrown when the operation returned an invalid status code + /// + /// + /// Thrown when unable to deserialize the response + /// + /// + /// Thrown when a required parameter is null + /// + /// + /// Thrown when a required parameter is null + /// + /// + /// A response object containing the response body and response headers. + /// + public async Task>> ListByServerWithHttpMessagesAsync(string resourceGroupName, string serverName, Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken)) + { + if (resourceGroupName == null) + { + throw new ValidationException(ValidationRules.CannotBeNull, "resourceGroupName"); + } + if (serverName == null) + { + throw new ValidationException(ValidationRules.CannotBeNull, "serverName"); + } + if (Client.SubscriptionId == null) + { + throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.SubscriptionId"); + } + string apiVersion = "2021-05-01-preview"; + // Tracing + bool _shouldTrace = ServiceClientTracing.IsEnabled; + string _invocationId = null; + if (_shouldTrace) + { + _invocationId = ServiceClientTracing.NextInvocationId.ToString(); + Dictionary tracingParameters = new Dictionary(); + tracingParameters.Add("resourceGroupName", resourceGroupName); + tracingParameters.Add("serverName", serverName); + tracingParameters.Add("apiVersion", apiVersion); + tracingParameters.Add("cancellationToken", cancellationToken); + ServiceClientTracing.Enter(_invocationId, this, "ListByServer", tracingParameters); + } + // Construct URL + var _baseUrl = Client.BaseUri.AbsoluteUri; + var _url = new System.Uri(new System.Uri(_baseUrl + (_baseUrl.EndsWith("/") ? "" : "/")), "subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/connectionPolicies").ToString(); + _url = _url.Replace("{resourceGroupName}", System.Uri.EscapeDataString(resourceGroupName)); + _url = _url.Replace("{serverName}", System.Uri.EscapeDataString(serverName)); + _url = _url.Replace("{subscriptionId}", System.Uri.EscapeDataString(Client.SubscriptionId)); + List _queryParameters = new List(); + if (apiVersion != null) + { + _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(apiVersion))); + } + if (_queryParameters.Count > 0) + { + _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters); + } + // Create HTTP transport objects + var _httpRequest = new HttpRequestMessage(); + HttpResponseMessage _httpResponse = null; + _httpRequest.Method = new HttpMethod("GET"); + _httpRequest.RequestUri = new System.Uri(_url); + // Set Headers + if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value) + { + _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString()); + } + if (Client.AcceptLanguage != null) + { + if (_httpRequest.Headers.Contains("accept-language")) + { + _httpRequest.Headers.Remove("accept-language"); + } + _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage); + } + + + if (customHeaders != null) + { + foreach(var _header in customHeaders) + { + if (_httpRequest.Headers.Contains(_header.Key)) + { + _httpRequest.Headers.Remove(_header.Key); + } + _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); + } + } + + // Serialize Request + string _requestContent = null; + // Set Credentials + if (Client.Credentials != null) + { + cancellationToken.ThrowIfCancellationRequested(); + await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); + } + // Send Request + if (_shouldTrace) + { + ServiceClientTracing.SendRequest(_invocationId, _httpRequest); + } + cancellationToken.ThrowIfCancellationRequested(); + _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); + if (_shouldTrace) + { + ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); + } + HttpStatusCode _statusCode = _httpResponse.StatusCode; + cancellationToken.ThrowIfCancellationRequested(); + string _responseContent = null; + if ((int)_statusCode != 200) + { + var ex = new CloudException(string.Format("Operation returned an invalid status code '{0}'", _statusCode)); + try + { + _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); + CloudError _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject(_responseContent, Client.DeserializationSettings); + if (_errorBody != null) + { + ex = new CloudException(_errorBody.Message); + ex.Body = _errorBody; + } + } + catch (JsonException) + { + // Ignore the exception + } + ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); + ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); + if (_httpResponse.Headers.Contains("x-ms-request-id")) + { + ex.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); + } + if (_shouldTrace) + { + ServiceClientTracing.Error(_invocationId, ex); + } + _httpRequest.Dispose(); + if (_httpResponse != null) + { + _httpResponse.Dispose(); + } + throw ex; + } + // Create Result + var _result = new AzureOperationResponse>(); + _result.Request = _httpRequest; + _result.Response = _httpResponse; + if (_httpResponse.Headers.Contains("x-ms-request-id")) + { + _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); + } // Deserialize Response - if ((int)_statusCode == 201) + if ((int)_statusCode == 200) { _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); try { - _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject(_responseContent, Client.DeserializationSettings); + _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject>(_responseContent, Client.DeserializationSettings); } catch (JsonException ex) { @@ -285,7 +470,7 @@ internal ServerConnectionPoliciesOperations(SqlManagementClient client) } /// - /// Gets the server's secure connection policy. + /// Updates a server connection policy /// /// /// The name of the resource group that contains the resource. You can obtain @@ -294,6 +479,9 @@ internal ServerConnectionPoliciesOperations(SqlManagementClient client) /// /// The name of the server. /// + /// + /// The required parameters for updating a server connection policy. + /// /// /// Headers that will be added to request. /// @@ -315,12 +503,8 @@ internal ServerConnectionPoliciesOperations(SqlManagementClient client) /// /// A response object containing the response body and response headers. /// - public async Task> GetWithHttpMessagesAsync(string resourceGroupName, string serverName, Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken)) + public async Task> BeginCreateOrUpdateWithHttpMessagesAsync(string resourceGroupName, string serverName, ServerConnectionPolicy parameters, Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken)) { - if (Client.SubscriptionId == null) - { - throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.SubscriptionId"); - } if (resourceGroupName == null) { throw new ValidationException(ValidationRules.CannotBeNull, "resourceGroupName"); @@ -329,8 +513,20 @@ internal ServerConnectionPoliciesOperations(SqlManagementClient client) { throw new ValidationException(ValidationRules.CannotBeNull, "serverName"); } - string apiVersion = "2014-04-01"; + if (parameters == null) + { + throw new ValidationException(ValidationRules.CannotBeNull, "parameters"); + } + if (parameters != null) + { + parameters.Validate(); + } + if (Client.SubscriptionId == null) + { + throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.SubscriptionId"); + } string connectionPolicyName = "default"; + string apiVersion = "2021-05-01-preview"; // Tracing bool _shouldTrace = ServiceClientTracing.IsEnabled; string _invocationId = null; @@ -338,20 +534,21 @@ internal ServerConnectionPoliciesOperations(SqlManagementClient client) { _invocationId = ServiceClientTracing.NextInvocationId.ToString(); Dictionary tracingParameters = new Dictionary(); - tracingParameters.Add("apiVersion", apiVersion); tracingParameters.Add("resourceGroupName", resourceGroupName); tracingParameters.Add("serverName", serverName); tracingParameters.Add("connectionPolicyName", connectionPolicyName); + tracingParameters.Add("parameters", parameters); + tracingParameters.Add("apiVersion", apiVersion); tracingParameters.Add("cancellationToken", cancellationToken); - ServiceClientTracing.Enter(_invocationId, this, "Get", tracingParameters); + ServiceClientTracing.Enter(_invocationId, this, "BeginCreateOrUpdate", tracingParameters); } // Construct URL var _baseUrl = Client.BaseUri.AbsoluteUri; var _url = new System.Uri(new System.Uri(_baseUrl + (_baseUrl.EndsWith("/") ? "" : "/")), "subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/connectionPolicies/{connectionPolicyName}").ToString(); - _url = _url.Replace("{subscriptionId}", System.Uri.EscapeDataString(Client.SubscriptionId)); _url = _url.Replace("{resourceGroupName}", System.Uri.EscapeDataString(resourceGroupName)); _url = _url.Replace("{serverName}", System.Uri.EscapeDataString(serverName)); _url = _url.Replace("{connectionPolicyName}", System.Uri.EscapeDataString(connectionPolicyName)); + _url = _url.Replace("{subscriptionId}", System.Uri.EscapeDataString(Client.SubscriptionId)); List _queryParameters = new List(); if (apiVersion != null) { @@ -364,7 +561,7 @@ internal ServerConnectionPoliciesOperations(SqlManagementClient client) // Create HTTP transport objects var _httpRequest = new HttpRequestMessage(); HttpResponseMessage _httpResponse = null; - _httpRequest.Method = new HttpMethod("GET"); + _httpRequest.Method = new HttpMethod("PUT"); _httpRequest.RequestUri = new System.Uri(_url); // Set Headers if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value) @@ -395,6 +592,12 @@ internal ServerConnectionPoliciesOperations(SqlManagementClient client) // Serialize Request string _requestContent = null; + if(parameters != null) + { + _requestContent = Rest.Serialization.SafeJsonConvert.SerializeObject(parameters, Client.SerializationSettings); + _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8); + _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json; charset=utf-8"); + } // Set Credentials if (Client.Credentials != null) { @@ -415,7 +618,7 @@ internal ServerConnectionPoliciesOperations(SqlManagementClient client) HttpStatusCode _statusCode = _httpResponse.StatusCode; cancellationToken.ThrowIfCancellationRequested(); string _responseContent = null; - if ((int)_statusCode != 200) + if ((int)_statusCode != 200 && (int)_statusCode != 202) { var ex = new CloudException(string.Format("Operation returned an invalid status code '{0}'", _statusCode)); try @@ -482,5 +685,178 @@ internal ServerConnectionPoliciesOperations(SqlManagementClient client) return _result; } + /// + /// Lists connection policy + /// + /// + /// The NextLink from the previous successful call to List operation. + /// + /// + /// Headers that will be added to request. + /// + /// + /// The cancellation token. + /// + /// + /// Thrown when the operation returned an invalid status code + /// + /// + /// Thrown when unable to deserialize the response + /// + /// + /// Thrown when a required parameter is null + /// + /// + /// Thrown when a required parameter is null + /// + /// + /// A response object containing the response body and response headers. + /// + public async Task>> ListByServerNextWithHttpMessagesAsync(string nextPageLink, Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken)) + { + if (nextPageLink == null) + { + throw new ValidationException(ValidationRules.CannotBeNull, "nextPageLink"); + } + // Tracing + bool _shouldTrace = ServiceClientTracing.IsEnabled; + string _invocationId = null; + if (_shouldTrace) + { + _invocationId = ServiceClientTracing.NextInvocationId.ToString(); + Dictionary tracingParameters = new Dictionary(); + tracingParameters.Add("nextPageLink", nextPageLink); + tracingParameters.Add("cancellationToken", cancellationToken); + ServiceClientTracing.Enter(_invocationId, this, "ListByServerNext", tracingParameters); + } + // Construct URL + string _url = "{nextLink}"; + _url = _url.Replace("{nextLink}", nextPageLink); + List _queryParameters = new List(); + if (_queryParameters.Count > 0) + { + _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters); + } + // Create HTTP transport objects + var _httpRequest = new HttpRequestMessage(); + HttpResponseMessage _httpResponse = null; + _httpRequest.Method = new HttpMethod("GET"); + _httpRequest.RequestUri = new System.Uri(_url); + // Set Headers + if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value) + { + _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString()); + } + if (Client.AcceptLanguage != null) + { + if (_httpRequest.Headers.Contains("accept-language")) + { + _httpRequest.Headers.Remove("accept-language"); + } + _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage); + } + + + if (customHeaders != null) + { + foreach(var _header in customHeaders) + { + if (_httpRequest.Headers.Contains(_header.Key)) + { + _httpRequest.Headers.Remove(_header.Key); + } + _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); + } + } + + // Serialize Request + string _requestContent = null; + // Set Credentials + if (Client.Credentials != null) + { + cancellationToken.ThrowIfCancellationRequested(); + await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); + } + // Send Request + if (_shouldTrace) + { + ServiceClientTracing.SendRequest(_invocationId, _httpRequest); + } + cancellationToken.ThrowIfCancellationRequested(); + _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); + if (_shouldTrace) + { + ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); + } + HttpStatusCode _statusCode = _httpResponse.StatusCode; + cancellationToken.ThrowIfCancellationRequested(); + string _responseContent = null; + if ((int)_statusCode != 200) + { + var ex = new CloudException(string.Format("Operation returned an invalid status code '{0}'", _statusCode)); + try + { + _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); + CloudError _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject(_responseContent, Client.DeserializationSettings); + if (_errorBody != null) + { + ex = new CloudException(_errorBody.Message); + ex.Body = _errorBody; + } + } + catch (JsonException) + { + // Ignore the exception + } + ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); + ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); + if (_httpResponse.Headers.Contains("x-ms-request-id")) + { + ex.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); + } + if (_shouldTrace) + { + ServiceClientTracing.Error(_invocationId, ex); + } + _httpRequest.Dispose(); + if (_httpResponse != null) + { + _httpResponse.Dispose(); + } + throw ex; + } + // Create Result + var _result = new AzureOperationResponse>(); + _result.Request = _httpRequest; + _result.Response = _httpResponse; + if (_httpResponse.Headers.Contains("x-ms-request-id")) + { + _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); + } + // Deserialize Response + if ((int)_statusCode == 200) + { + _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); + try + { + _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject>(_responseContent, Client.DeserializationSettings); + } + catch (JsonException ex) + { + _httpRequest.Dispose(); + if (_httpResponse != null) + { + _httpResponse.Dispose(); + } + throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); + } + } + if (_shouldTrace) + { + ServiceClientTracing.Exit(_invocationId, _result); + } + return _result; + } + } } diff --git a/sdk/sqlmanagement/Microsoft.Azure.Management.Sql/src/Generated/ServerConnectionPoliciesOperationsExtensions.cs b/sdk/sqlmanagement/Microsoft.Azure.Management.Sql/src/Generated/ServerConnectionPoliciesOperationsExtensions.cs index 35a89c25ce429..f115f50c3fd89 100644 --- a/sdk/sqlmanagement/Microsoft.Azure.Management.Sql/src/Generated/ServerConnectionPoliciesOperationsExtensions.cs +++ b/sdk/sqlmanagement/Microsoft.Azure.Management.Sql/src/Generated/ServerConnectionPoliciesOperationsExtensions.cs @@ -22,7 +22,49 @@ namespace Microsoft.Azure.Management.Sql public static partial class ServerConnectionPoliciesOperationsExtensions { /// - /// Creates or updates the server's connection policy. + /// Gets a server connection policy + /// + /// + /// The operations group for this extension method. + /// + /// + /// The name of the resource group that contains the resource. You can obtain + /// this value from the Azure Resource Manager API or the portal. + /// + /// + /// The name of the server. + /// + public static ServerConnectionPolicy Get(this IServerConnectionPoliciesOperations operations, string resourceGroupName, string serverName) + { + return operations.GetAsync(resourceGroupName, serverName).GetAwaiter().GetResult(); + } + + /// + /// Gets a server connection policy + /// + /// + /// The operations group for this extension method. + /// + /// + /// The name of the resource group that contains the resource. You can obtain + /// this value from the Azure Resource Manager API or the portal. + /// + /// + /// The name of the server. + /// + /// + /// The cancellation token. + /// + public static async Task GetAsync(this IServerConnectionPoliciesOperations operations, string resourceGroupName, string serverName, CancellationToken cancellationToken = default(CancellationToken)) + { + using (var _result = await operations.GetWithHttpMessagesAsync(resourceGroupName, serverName, null, cancellationToken).ConfigureAwait(false)) + { + return _result.Body; + } + } + + /// + /// Updates a server connection policy /// /// /// The operations group for this extension method. @@ -35,7 +77,7 @@ public static partial class ServerConnectionPoliciesOperationsExtensions /// The name of the server. /// /// - /// The required parameters for updating a secure connection policy. + /// The required parameters for updating a server connection policy. /// public static ServerConnectionPolicy CreateOrUpdate(this IServerConnectionPoliciesOperations operations, string resourceGroupName, string serverName, ServerConnectionPolicy parameters) { @@ -43,7 +85,7 @@ public static ServerConnectionPolicy CreateOrUpdate(this IServerConnectionPolici } /// - /// Creates or updates the server's connection policy. + /// Updates a server connection policy /// /// /// The operations group for this extension method. @@ -56,7 +98,7 @@ public static ServerConnectionPolicy CreateOrUpdate(this IServerConnectionPolici /// The name of the server. /// /// - /// The required parameters for updating a secure connection policy. + /// The required parameters for updating a server connection policy. /// /// /// The cancellation token. @@ -70,7 +112,7 @@ public static ServerConnectionPolicy CreateOrUpdate(this IServerConnectionPolici } /// - /// Gets the server's secure connection policy. + /// Lists connection policy /// /// /// The operations group for this extension method. @@ -82,13 +124,13 @@ public static ServerConnectionPolicy CreateOrUpdate(this IServerConnectionPolici /// /// The name of the server. /// - public static ServerConnectionPolicy Get(this IServerConnectionPoliciesOperations operations, string resourceGroupName, string serverName) + public static IPage ListByServer(this IServerConnectionPoliciesOperations operations, string resourceGroupName, string serverName) { - return operations.GetAsync(resourceGroupName, serverName).GetAwaiter().GetResult(); + return operations.ListByServerAsync(resourceGroupName, serverName).GetAwaiter().GetResult(); } /// - /// Gets the server's secure connection policy. + /// Lists connection policy /// /// /// The operations group for this extension method. @@ -103,9 +145,91 @@ public static ServerConnectionPolicy Get(this IServerConnectionPoliciesOperation /// /// The cancellation token. /// - public static async Task GetAsync(this IServerConnectionPoliciesOperations operations, string resourceGroupName, string serverName, CancellationToken cancellationToken = default(CancellationToken)) + public static async Task> ListByServerAsync(this IServerConnectionPoliciesOperations operations, string resourceGroupName, string serverName, CancellationToken cancellationToken = default(CancellationToken)) { - using (var _result = await operations.GetWithHttpMessagesAsync(resourceGroupName, serverName, null, cancellationToken).ConfigureAwait(false)) + using (var _result = await operations.ListByServerWithHttpMessagesAsync(resourceGroupName, serverName, null, cancellationToken).ConfigureAwait(false)) + { + return _result.Body; + } + } + + /// + /// Updates a server connection policy + /// + /// + /// The operations group for this extension method. + /// + /// + /// The name of the resource group that contains the resource. You can obtain + /// this value from the Azure Resource Manager API or the portal. + /// + /// + /// The name of the server. + /// + /// + /// The required parameters for updating a server connection policy. + /// + public static ServerConnectionPolicy BeginCreateOrUpdate(this IServerConnectionPoliciesOperations operations, string resourceGroupName, string serverName, ServerConnectionPolicy parameters) + { + return operations.BeginCreateOrUpdateAsync(resourceGroupName, serverName, parameters).GetAwaiter().GetResult(); + } + + /// + /// Updates a server connection policy + /// + /// + /// The operations group for this extension method. + /// + /// + /// The name of the resource group that contains the resource. You can obtain + /// this value from the Azure Resource Manager API or the portal. + /// + /// + /// The name of the server. + /// + /// + /// The required parameters for updating a server connection policy. + /// + /// + /// The cancellation token. + /// + public static async Task BeginCreateOrUpdateAsync(this IServerConnectionPoliciesOperations operations, string resourceGroupName, string serverName, ServerConnectionPolicy parameters, CancellationToken cancellationToken = default(CancellationToken)) + { + using (var _result = await operations.BeginCreateOrUpdateWithHttpMessagesAsync(resourceGroupName, serverName, parameters, null, cancellationToken).ConfigureAwait(false)) + { + return _result.Body; + } + } + + /// + /// Lists connection policy + /// + /// + /// The operations group for this extension method. + /// + /// + /// The NextLink from the previous successful call to List operation. + /// + public static IPage ListByServerNext(this IServerConnectionPoliciesOperations operations, string nextPageLink) + { + return operations.ListByServerNextAsync(nextPageLink).GetAwaiter().GetResult(); + } + + /// + /// Lists connection policy + /// + /// + /// The operations group for this extension method. + /// + /// + /// The NextLink from the previous successful call to List operation. + /// + /// + /// The cancellation token. + /// + public static async Task> ListByServerNextAsync(this IServerConnectionPoliciesOperations operations, string nextPageLink, CancellationToken cancellationToken = default(CancellationToken)) + { + using (var _result = await operations.ListByServerNextWithHttpMessagesAsync(nextPageLink, null, cancellationToken).ConfigureAwait(false)) { return _result.Body; } diff --git a/sdk/sqlmanagement/Microsoft.Azure.Management.Sql/src/Generated/SqlManagementClient.cs b/sdk/sqlmanagement/Microsoft.Azure.Management.Sql/src/Generated/SqlManagementClient.cs index a7f264e84dd9b..69ebd9ee37ec1 100644 --- a/sdk/sqlmanagement/Microsoft.Azure.Management.Sql/src/Generated/SqlManagementClient.cs +++ b/sdk/sqlmanagement/Microsoft.Azure.Management.Sql/src/Generated/SqlManagementClient.cs @@ -77,11 +77,6 @@ public partial class SqlManagementClient : ServiceClient, I /// public virtual IRecoverableDatabasesOperations RecoverableDatabases { get; private set; } - /// - /// Gets the IServerConnectionPoliciesOperations. - /// - public virtual IServerConnectionPoliciesOperations ServerConnectionPolicies { get; private set; } - /// /// Gets the IDataMaskingPoliciesOperations. /// @@ -667,6 +662,11 @@ public partial class SqlManagementClient : ServiceClient, I /// public virtual IUsagesOperations Usages { get; private set; } + /// + /// Gets the IServerConnectionPoliciesOperations. + /// + public virtual IServerConnectionPoliciesOperations ServerConnectionPolicies { get; private set; } + /// /// Initializes a new instance of the SqlManagementClient class. /// @@ -909,7 +909,6 @@ public SqlManagementClient(System.Uri baseUri, ServiceClientCredentials credenti private void Initialize() { RecoverableDatabases = new RecoverableDatabasesOperations(this); - ServerConnectionPolicies = new ServerConnectionPoliciesOperations(this); DataMaskingPolicies = new DataMaskingPoliciesOperations(this); DataMaskingRules = new DataMaskingRulesOperations(this); GeoBackupPolicies = new GeoBackupPoliciesOperations(this); @@ -1027,6 +1026,7 @@ private void Initialize() RestorableDroppedManagedDatabases = new RestorableDroppedManagedDatabasesOperations(this); Servers = new ServersOperations(this); Usages = new UsagesOperations(this); + ServerConnectionPolicies = new ServerConnectionPoliciesOperations(this); BaseUri = new System.Uri("https://management.azure.com"); AcceptLanguage = "en-US"; LongRunningOperationRetryTimeout = 30;