-
Notifications
You must be signed in to change notification settings - Fork 1.6k
[AI Manager] Add namespace access key commands #10219
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Ethan Yang (necusjz)
merged 3 commits into
Azure:main
from
gloriahxr:gloriahxr-aimanager-namespace-accesskeys
Aug 17, 2026
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| { | ||
| "azext.isPreview": true, | ||
| "azext.minCliCoreVersion": "2.61.0", | ||
| "version": "1.2.0" | ||
| "version": "1.2.1b1" | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
src/aimanager/azext_aimanager/tests/latest/test_namespace_accesskeys.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| # -------------------------------------------------------------------------------------------- | ||
| # Copyright (c) Microsoft Corporation. All rights reserved. | ||
| # Licensed under the MIT License. See License.txt in the project root for license information. | ||
| # -------------------------------------------------------------------------------------------- | ||
|
|
||
| import unittest | ||
| from unittest.mock import MagicMock | ||
|
|
||
| from azext_aimanager import custom | ||
|
|
||
|
|
||
| class MockCmd: | ||
| pass | ||
|
|
||
|
|
||
| class TestNamespaceAccessKeys(unittest.TestCase): | ||
|
|
||
| def setUp(self): | ||
| self.cmd = MockCmd() | ||
| self.client = MagicMock() | ||
|
|
||
| def test_list_accesskeys(self): | ||
| self.client.list_access_keys.return_value = "access-info" | ||
|
|
||
| result = custom.aimanager_namespace_list_accesskeys( | ||
| self.cmd, self.client, "rg", "manager", "namespace") | ||
|
|
||
| self.assertEqual(result, "access-info") | ||
| self.client.list_access_keys.assert_called_once_with( | ||
| "rg", "manager", "namespace", headers={}) | ||
|
|
||
| def test_rotate_accesskeys(self): | ||
| self.client.rotate_keys.return_value = "rotated" | ||
|
|
||
| result = custom.aimanager_namespace_rotate_accesskeys( | ||
| self.cmd, self.client, "rg", "manager", "namespace") | ||
|
|
||
| self.assertEqual(result, "rotated") | ||
| self.client.rotate_keys.assert_called_once_with( | ||
| "rg", "manager", "namespace", headers={}) | ||
|
|
||
| def test_custom_headers_are_forwarded(self): | ||
| custom.aimanager_namespace_list_accesskeys( | ||
| self.cmd, self.client, "rg", "manager", "namespace", | ||
| aks_custom_headers="a=1,b=2") | ||
|
|
||
| self.client.list_access_keys.assert_called_once_with( | ||
| "rg", "manager", "namespace", headers={"a": "1", "b": "2"}) | ||
|
|
||
|
|
||
| if __name__ == '__main__': | ||
| unittest.main() |
69 changes: 69 additions & 0 deletions
69
src/aimanager/azext_aimanager/tests/latest/test_namespace_accesskeys_scenario.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| # -------------------------------------------------------------------------------------------- | ||
| # Copyright (c) Microsoft Corporation. All rights reserved. | ||
| # Licensed under the MIT License. See License.txt in the project root for license information. | ||
| # -------------------------------------------------------------------------------------------- | ||
|
|
||
| from unittest.mock import MagicMock, patch | ||
|
|
||
| from azure.cli.testsdk import ScenarioTest | ||
|
|
||
| from azext_aimanager.vendored_sdks.v2026_05_02_preview import models | ||
|
|
||
|
|
||
| class NamespaceAccessKeysScenarioTest(ScenarioTest): | ||
|
|
||
| def test_namespace_accesskeys_commands(self): | ||
| access_info = models.NamespaceAccessInfo({ | ||
| 'endpoint': 'https://team-alpha.example.eastus2.aksapp.io/v1', | ||
| 'primaryKey': 'primary-key-value', | ||
| 'secondaryKey': 'secondary-key-value', | ||
| }) | ||
| rotated_info = models.NamespaceAccessInfo({ | ||
| 'endpoint': 'https://team-alpha.example.eastus2.aksapp.io/v1', | ||
| 'primaryKey': 'new-primary-key-value', | ||
| 'secondaryKey': 'primary-key-value', | ||
| 'lastRotatedAt': '2026-08-14T00:00:00Z', | ||
| }) | ||
|
|
||
| operations = MagicMock() | ||
| operations.list_access_keys.return_value = access_info | ||
| operations.rotate_keys.return_value = rotated_info | ||
| service_client = MagicMock() | ||
| service_client.ai_manager_namespaces = operations | ||
|
|
||
| command_prefix = 'aimanager namespace {} -g rg --aimanager-name manager -n namespace' | ||
|
|
||
| with patch('azext_aimanager._client_factory.get_aimanager_client', | ||
| return_value=service_client): | ||
| self.cmd( | ||
| command_prefix.format('list-accesskeys'), | ||
| checks=[ | ||
| self.check('endpoint', 'https://team-alpha.example.eastus2.aksapp.io/v1'), | ||
| self.check('primaryKey', 'primary-key-value'), | ||
| self.check('secondaryKey', 'secondary-key-value'), | ||
| ]) | ||
|
|
||
| # the previous primary key is demoted to the secondary key on rotation | ||
| self.cmd( | ||
| command_prefix.format('rotate-accesskeys') + ' --yes', | ||
| checks=[ | ||
| self.check('primaryKey', 'new-primary-key-value'), | ||
| self.check('secondaryKey', 'primary-key-value'), | ||
| ]) | ||
|
|
||
| # -m/--manager remains accepted for backwards compatibility | ||
| self.cmd( | ||
| 'aimanager namespace list-accesskeys -g rg -m manager -n namespace', | ||
| checks=[self.check('primaryKey', 'primary-key-value')]) | ||
|
|
||
| operations.list_access_keys.assert_called_with( | ||
| 'rg', 'manager', 'namespace', headers={}) | ||
|
|
||
| # --aks-custom-headers is parsed and forwarded to the request | ||
| self.cmd( | ||
| command_prefix.format('list-accesskeys') + ' --aks-custom-headers a=1,b=2', | ||
| checks=[self.check('primaryKey', 'primary-key-value')]) | ||
|
|
||
| operations.list_access_keys.assert_called_with( | ||
| 'rg', 'manager', 'namespace', headers={'a': '1', 'b': '2'}) | ||
| operations.rotate_keys.assert_called_once_with('rg', 'manager', 'namespace', headers={}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.