Skip to content

Commit 873f0f6

Browse files
authored
foundry-cost-control 1.0.0b2: Override cognitiveservices account show in order to use api-version 2026-09-15-preview (#10403)
* Override `cognitiveservices account show` in order to use api-version 2026-09-15-preview * usage dash instead of dot in match strings * Update Code Owners
1 parent db42738 commit 873f0f6

10 files changed

Lines changed: 603 additions & 434 deletions

File tree

‎.github/CODEOWNERS‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,3 +349,5 @@
349349
/src/edgeoperator/ @kleyvaortega
350350

351351
/src/aro/ @kimorris27 @hlipsig @tsatam @rogbas @stevekuznetsov @mbarnes @twolff-gh
352+
353+
/src/foundry-cost-control @dargilco @M-Hietala @rhurey

‎src/foundry-cost-control/HISTORY.rst‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
Release History
44
===============
55

6+
1.0.0b2
7+
++++++
8+
* Override ``cognitiveservices account show`` to use API version ``2026-09-15-preview`` and return cost-control properties.
9+
610
1.0.0b1
711
++++++
812
* Initial release.

‎src/foundry-cost-control/azext_foundry_cost_control/commands.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ def load_command_table(self, _): # pylint: disable=unused-argument
1818
with self.command_group(
1919
"cognitiveservices account",
2020
client_factory=cf_accounts) as group:
21+
group.custom_show_command("show", "account_show")
2122
group.custom_command("update", "account_update")
2223

2324
with self.command_group(

‎src/foundry-cost-control/azext_foundry_cost_control/custom.py‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,22 @@ def _deployment_resource_id(cmd, resource_group_name, account_name, deployment_n
7474
)
7575

7676

77+
def account_show(cmd, resource_group_name, account_name):
78+
"""Get a Cognitive Services account using the preview cost-control API."""
79+
account_id = resource_id(
80+
subscription=get_subscription_id(cmd.cli_ctx),
81+
resource_group=resource_group_name,
82+
namespace="Microsoft.CognitiveServices",
83+
type="accounts",
84+
name=account_name,
85+
)
86+
return show_resource(
87+
cmd,
88+
resource_ids=[account_id],
89+
api_version=_API_VERSION,
90+
)
91+
92+
7793
def account_update(
7894
cmd,
7995
client,

‎src/foundry-cost-control/azext_foundry_cost_control/tests/latest/cost-control-rules-1.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"period": "month",
1212
"recurring": true,
1313
"match": {
14-
"foundryCallerAgentId": [
14+
"foundry-caller-agent-id": [
1515
"agent-123"
1616
]
1717
},

‎src/foundry-cost-control/azext_foundry_cost_control/tests/latest/cost-control-rules-2.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"period": "month",
1212
"recurring": true,
1313
"match": {
14-
"foundryProjectId": [
14+
"foundry-project-id": [
1515
"project-456"
1616
]
1717
},

‎src/foundry-cost-control/azext_foundry_cost_control/tests/latest/recordings/test_foundry_cost_control.yaml‎

Lines changed: 530 additions & 431 deletions
Large diffs are not rendered by default.

‎src/foundry-cost-control/azext_foundry_cost_control/tests/latest/test_foundry_cost_control.py‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,24 @@ def test_foundry_cost_control(self, resource_group):
130130
]
131131
)
132132

133+
# Verify account show returns the preview cost-control properties.
134+
self.cmd(
135+
'cognitiveservices account show '
136+
'--resource-group {resource_group} '
137+
'--name {account_name}',
138+
checks=[
139+
self.check(
140+
'properties.costControlConnections.appInsightsConnectionId',
141+
'{app_insights_connection_id}'
142+
),
143+
self.check(
144+
'properties.costControlConnections.eventGridConnectionId',
145+
'{event_grid_connection_id}'
146+
),
147+
self.check('properties.costControlIds[0]', '{cost_control_id_1}'),
148+
]
149+
)
150+
133151
# Create a deployment with the first cost control attached.
134152
self.cmd(
135153
'cognitiveservices account deployment create '

‎src/foundry-cost-control/azext_foundry_cost_control/tests/latest/test_foundry_cost_control_custom_code.py‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
_parse_cost_control_id,
1616
)
1717
from azext_foundry_cost_control.custom import (
18+
account_show,
1819
account_update,
1920
deployment_create,
2021
deployment_update,
@@ -53,6 +54,34 @@ def test_parse_cost_control_id_rejects_other_resource_type(self):
5354
with self.assertRaises(InvalidArgumentValueError):
5455
_parse_cost_control_id(ACCOUNT_ID)
5556

57+
@mock.patch("azext_foundry_cost_control.custom.show_resource")
58+
@mock.patch("azext_foundry_cost_control.custom.resource_id", return_value=ACCOUNT_ID)
59+
@mock.patch("azext_foundry_cost_control.custom.get_subscription_id", return_value="subscription-id")
60+
def test_account_show_uses_preview_api(
61+
self, get_subscription_id_mock, resource_id_mock, show_resource_mock):
62+
cmd = mock.Mock()
63+
64+
result = account_show(
65+
cmd=cmd,
66+
resource_group_name="test-rg",
67+
account_name="test-account",
68+
)
69+
70+
self.assertIs(result, show_resource_mock.return_value)
71+
get_subscription_id_mock.assert_called_once_with(cmd.cli_ctx)
72+
resource_id_mock.assert_called_once_with(
73+
subscription="subscription-id",
74+
resource_group="test-rg",
75+
namespace="Microsoft.CognitiveServices",
76+
type="accounts",
77+
name="test-account",
78+
)
79+
show_resource_mock.assert_called_once_with(
80+
cmd,
81+
resource_ids=[ACCOUNT_ID],
82+
api_version="2026-09-15-preview",
83+
)
84+
5685
@mock.patch("azext_foundry_cost_control.custom.patch_resource")
5786
@mock.patch("azext_foundry_cost_control.custom.resource_id", return_value=ACCOUNT_ID)
5887
@mock.patch("azext_foundry_cost_control.custom.get_subscription_id", return_value="subscription-id")

‎src/foundry-cost-control/setup.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010

1111
# HISTORY.rst entry.
12-
VERSION = '1.0.0b1'
12+
VERSION = '1.0.0b2'
1313

1414
# The full list of classifiers is available at
1515
# https://pypi.python.org/pypi?%3Aaction=list_classifiers

0 commit comments

Comments
 (0)