public async Task <Response <DataMaskingPolicy> > CreateOrUpdateAsync(string resourceGroupName, string serverName, string databaseName, DataMaskingPolicy parameters, CancellationToken cancellationToken = default)
        {
            if (resourceGroupName == null)
            {
                throw new ArgumentNullException(nameof(resourceGroupName));
            }
            if (serverName == null)
            {
                throw new ArgumentNullException(nameof(serverName));
            }
            if (databaseName == null)
            {
                throw new ArgumentNullException(nameof(databaseName));
            }
            if (parameters == null)
            {
                throw new ArgumentNullException(nameof(parameters));
            }

            using var message = CreateCreateOrUpdateRequest(resourceGroupName, serverName, databaseName, parameters);
            await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);

            switch (message.Response.Status)
            {
            case 200:
            {
                DataMaskingPolicy value = default;
                using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, cancellationToken).ConfigureAwait(false);

                value = DataMaskingPolicy.DeserializeDataMaskingPolicy(document.RootElement);
                return(Response.FromValue(value, message.Response));
            }
        internal HttpMessage CreateCreateOrUpdateRequest(string resourceGroupName, string serverName, string databaseName, DataMaskingPolicy parameters)
        {
            var message = _pipeline.CreateMessage();
            var request = message.Request;

            request.Method = RequestMethod.Put;
            var uri = new RawRequestUriBuilder();

            uri.Reset(endpoint);
            uri.AppendPath("/subscriptions/", false);
            uri.AppendPath(subscriptionId, true);
            uri.AppendPath("/resourceGroups/", false);
            uri.AppendPath(resourceGroupName, true);
            uri.AppendPath("/providers/Microsoft.Sql/servers/", false);
            uri.AppendPath(serverName, true);
            uri.AppendPath("/databases/", false);
            uri.AppendPath(databaseName, true);
            uri.AppendPath("/dataMaskingPolicies/", false);
            uri.AppendPath("Default", true);
            uri.AppendQuery("api-version", "2014-04-01", true);
            request.Uri = uri;
            request.Headers.Add("Content-Type", "application/json");
            request.Headers.Add("Accept", "application/json");
            var content = new Utf8JsonRequestContent();

            content.JsonWriter.WriteObjectValue(parameters);
            request.Content = content;
            return(message);
        }
Exemplo n.º 3
0
 public virtual Response <DataMaskingPolicy> CreateOrUpdate(string resourceGroupName, string serverName, string databaseName, DataMaskingPolicy parameters, CancellationToken cancellationToken = default)
 {
     using var scope = _clientDiagnostics.CreateScope("DataMaskingPoliciesOperations.CreateOrUpdate");
     scope.Start();
     try
     {
         return(RestClient.CreateOrUpdate(resourceGroupName, serverName, databaseName, parameters, cancellationToken));
     }
     catch (Exception e)
     {
         scope.Failed(e);
         throw;
     }
 }