Skip to content

Removing SQL Legacy usage for FirewallRules#29465

Merged
VeryEarly merged 7 commits into
Azure:mainfrom
jeremyfrosti:dev/jeremyfrosti/remove_sql_legacy_usage
May 6, 2026
Merged

Removing SQL Legacy usage for FirewallRules#29465
VeryEarly merged 7 commits into
Azure:mainfrom
jeremyfrosti:dev/jeremyfrosti/remove_sql_legacy_usage

Conversation

@jeremyfrosti

@jeremyfrosti jeremyfrosti commented Apr 27, 2026

Copy link
Copy Markdown
Member

Description

Removing legacy usage of 2014 APIs from SQL

Mandatory Checklist

  • SHOULD update ChangeLog.md file(s) appropriately
    • Update src/{{SERVICE}}/{{SERVICE}}/ChangeLog.md.
      • A snippet outlining the change(s) made in the PR should be written under the ## Upcoming Release header in the past tense.
    • Should not change ChangeLog.md if no new release is required, such as fixing test case only.
  • SHOULD regenerate markdown help files if there is cmdlet API change. Instruction
  • SHOULD have proper test coverage for changes in pull request.
  • SHOULD NOT adjust version of module manually in pull request

Copilot AI review requested due to automatic review settings April 27, 2026 23:35
@azure-client-tools-bot-prd

Copy link
Copy Markdown
Thanks for your contribution! The pull request validation has started. Please revisit this comment for updated status.

@VeryEarly

Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines

Copy link
Copy Markdown
Contributor
Azure Pipelines successfully started running 3 pipeline(s).

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request removes legacy (2014-era) SQL Firewall Rule implementation usage by switching the cmdlets’ internal plumbing to the current Microsoft.Azure.Management.Sql SDK surface, and regenerating the Sql management SDK to include FirewallRules operations.

Changes:

  • Updated Firewall Rule communicator/adapter to use Microsoft.Azure.Management.Sql models/operations instead of LegacySdk.
  • Added paging-aware listing for server firewall rules using ListByServer + ListByServerNext.
  • Regenerated Sql.Management.Sdk to include IFirewallRulesOperations and related models/operations, and updated the generation README inputs.

Reviewed changes

Copilot reviewed 4 out of 12 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
src/Sql/Sql/FirewallRule/Services/AzureSqlServerFirewallRuleCommunicator.cs Swaps legacy client/model usage for new SDK operations; adds manual paging for list.
src/Sql/Sql/FirewallRule/Services/AzureSqlServerFirewallRuleAdapter.cs Updates adapter mapping and upsert payload to new SDK FirewallRule shape.
src/Sql/Sql/ChangeLog.md Adds release note entry for removal of legacy 2014 API usage in firewall rule cmdlets.
src/Sql/Sql.Management.Sdk/README.md Updates AutoRest input specs/commit and includes FirewallRules spec.
src/Sql/Sql.Management.Sdk/Generated/SqlManagementClient.cs Adds FirewallRules operations property initialization.
src/Sql/Sql.Management.Sdk/Generated/Models/ServerFirewallRuleProperties.cs New generated model type for firewall rule properties.
src/Sql/Sql.Management.Sdk/Generated/Models/FirewallRuleList.cs New generated list wrapper model.
src/Sql/Sql.Management.Sdk/Generated/Models/FirewallRule.cs New generated firewall rule resource model.
src/Sql/Sql.Management.Sdk/Generated/ISqlManagementClient.cs Exposes IFirewallRulesOperations on the client interface.
src/Sql/Sql.Management.Sdk/Generated/IFirewallRulesOperations.cs New generated operations interface for firewall rules.
src/Sql/Sql.Management.Sdk/Generated/FirewallRulesOperationsExtensions.cs New generated extension methods for firewall rules operations.
src/Sql/Sql.Management.Sdk/Generated/FirewallRulesOperations.cs New generated implementation for firewall rules REST operations.

Comment on lines +72 to +78

var pagedResponse = GetCurrentSqlClient().FirewallRules.ListByServer(resourceGroupName, serverName);
resultsList.AddRange(pagedResponse);

while (!string.IsNullOrEmpty(pagedResponse.NextPageLink))
{
pagedResponse = GetCurrentSqlClient().FirewallRules.ListByServerNext(pagedResponse.NextPageLink);

Copilot AI Apr 27, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

List() repeatedly calls GetCurrentSqlClient() (including inside the pagination loop), which creates a new SqlManagementClient each time. This adds avoidable overhead and could cause inconsistent per-invocation settings/headers. Consider creating the client once at the start of List() and reusing it for the initial call and subsequent ListByServerNext() calls.

Suggested change
var pagedResponse = GetCurrentSqlClient().FirewallRules.ListByServer(resourceGroupName, serverName);
resultsList.AddRange(pagedResponse);
while (!string.IsNullOrEmpty(pagedResponse.NextPageLink))
{
pagedResponse = GetCurrentSqlClient().FirewallRules.ListByServerNext(pagedResponse.NextPageLink);
var sqlClient = GetCurrentSqlClient();
var pagedResponse = sqlClient.FirewallRules.ListByServer(resourceGroupName, serverName);
resultsList.AddRange(pagedResponse);
while (!string.IsNullOrEmpty(pagedResponse.NextPageLink))
{
pagedResponse = sqlClient.FirewallRules.ListByServerNext(pagedResponse.NextPageLink);

Copilot uses AI. Check for mistakes.
Comment on lines +106 to +115
private SqlManagementClient GetCurrentSqlClient(string subscriptionId = null)
{
// Get the SQL management client for the current subscription
if (SqlClient == null)
// Note: client is not cached in static field because that causes ObjectDisposedException in functional tests.
var sqlClient = AzureSession.Instance.ClientFactory.CreateArmClient<Management.Sql.SqlManagementClient>(Context, AzureEnvironment.Endpoint.ResourceManager);
if (subscriptionId != null)
{
SqlClient = AzureSession.Instance.ClientFactory.CreateClient<SqlManagementClient>(Context, AzureEnvironment.Endpoint.ResourceManager);
sqlClient.SubscriptionId = subscriptionId;
}
return SqlClient;
return sqlClient;

Copilot AI Apr 27, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GetCurrentSqlClient no longer uses the static SqlClient cache, but the class still keeps SqlClient/Subscription static state and resets SqlClient in the constructor. This state is now unused and can mislead future changes; either remove the static fields/subscription-switch logic or reintroduce caching in a safe way.

Copilot uses AI. Check for mistakes.
Comment on lines +106 to 114
private SqlManagementClient GetCurrentSqlClient(string subscriptionId = null)
{
// Get the SQL management client for the current subscription
if (SqlClient == null)
// Note: client is not cached in static field because that causes ObjectDisposedException in functional tests.
var sqlClient = AzureSession.Instance.ClientFactory.CreateArmClient<Management.Sql.SqlManagementClient>(Context, AzureEnvironment.Endpoint.ResourceManager);
if (subscriptionId != null)
{
SqlClient = AzureSession.Instance.ClientFactory.CreateClient<SqlManagementClient>(Context, AzureEnvironment.Endpoint.ResourceManager);
sqlClient.SubscriptionId = subscriptionId;
}

Copilot AI Apr 27, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GetCurrentSqlClient takes an optional subscriptionId parameter, but the method is private and this class only calls it without arguments. If the parameter isn’t needed, remove it to reduce confusion; otherwise add a call site that passes the intended subscription id (or document why the override is required).

Copilot uses AI. Check for mistakes.
Comment on lines 107 to 114
/// Convert a Management.Sql.LegacySdk.Models.FirewallRule to AzureSqlServerFirewallRuleModel
/// </summary>
/// <param name="resourceGroup">The resource group the server is in</param>
/// <param name="serverName">The name of the server</param>
/// <param name="resp">The management client server response to convert</param>
/// <returns>The converted server model</returns>
private static AzureSqlServerFirewallRuleModel CreateFirewallRuleModelFromResponse(string resourceGroup, string serverName, Management.Sql.LegacySdk.Models.FirewallRule resp)
private static AzureSqlServerFirewallRuleModel CreateFirewallRuleModelFromResponse(string resourceGroup, string serverName, Management.Sql.Models.FirewallRule resp)
{

Copilot AI Apr 27, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The XML doc comment still says it converts a Management.Sql.LegacySdk.Models.FirewallRule, but the method now accepts Management.Sql.Models.FirewallRule. Please update the comment to match the new SDK type to avoid misleading documentation.

Copilot uses AI. Check for mistakes.
Comment on lines +69 to +80
public IList<Management.Sql.Models.FirewallRule> List(string resourceGroupName, string serverName)
{
return GetCurrentSqlClient().FirewallRules.List(resourceGroupName, serverName).FirewallRules;
List<Management.Sql.Models.FirewallRule> resultsList = new List<Management.Sql.Models.FirewallRule>();

var pagedResponse = GetCurrentSqlClient().FirewallRules.ListByServer(resourceGroupName, serverName);
resultsList.AddRange(pagedResponse);

while (!string.IsNullOrEmpty(pagedResponse.NextPageLink))
{
pagedResponse = GetCurrentSqlClient().FirewallRules.ListByServerNext(pagedResponse.NextPageLink);
resultsList.AddRange(pagedResponse);
}

Copilot AI Apr 27, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new paging logic in List() is currently untested in this module’s test suite. Since Get-AzSqlServerFirewallRule depends on List(), consider adding/expanding scenario coverage for firewall rule CRUD (including list pagination via NextPageLink) similar to the existing IPv6 firewall rule scenario tests.

Copilot uses AI. Check for mistakes.
@VeryEarly VeryEarly self-assigned this Apr 28, 2026
@VeryEarly

Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines

Copy link
Copy Markdown
Contributor
Azure Pipelines successfully started running 3 pipeline(s).

Copilot AI review requested due to automatic review settings April 29, 2026 21:39

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 12 out of 55 changed files in this pull request and generated 1 comment.

Comment on lines 15 to 18
using Hyak.Common;
using Microsoft.Azure.Management.Sql.Models;
using System.Collections.Generic;
using System.Linq;

Copilot AI Apr 29, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

using Hyak.Common; is now unused after switching the exception type to ErrorResponseException. With warnings treated as errors in this repo, the unused using can break the build; please remove it (or use CloudException again if intended).

Copilot uses AI. Check for mistakes.
@VeryEarly

Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines

Copy link
Copy Markdown
Contributor
Azure Pipelines successfully started running 3 pipeline(s).

@VeryEarly

Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines

Copy link
Copy Markdown
Contributor
Azure Pipelines successfully started running 3 pipeline(s).

Copilot AI review requested due to automatic review settings May 6, 2026 16:23
@VeryEarly

Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines

Copy link
Copy Markdown
Contributor
Azure Pipelines successfully started running 3 pipeline(s).

@VeryEarly

Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines

Copy link
Copy Markdown
Contributor
Azure Pipelines successfully started running 3 pipeline(s).

@VeryEarly VeryEarly merged commit 2c0d8bd into Azure:main May 6, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants