Skip to content

[Key Vault] Add docstring examples for KeyVaultAccessControlClient and KeyVaultSettingsClient #42196

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Jul 24, 2025

Fixes #34790

This PR adds comprehensive docstring examples for all public methods in KeyVaultAccessControlClient and KeyVaultSettingsClient, following the same pattern established by KeyVaultBackupClient.

Changes Made

Added Example Tests

  • test_examples_administration.py: Added 3 new test methods with example code blocks for sync clients
  • test_examples_administration_async.py: Added 3 new test methods with example code blocks for async clients

Updated Docstrings with Examples

KeyVaultAccessControlClient (8 methods):

  • create_role_assignment - Create a role assignment for a principal
  • delete_role_assignment - Delete an existing role assignment
  • get_role_assignment - Retrieve a specific role assignment
  • list_role_assignments - List all role assignments for a scope
  • set_role_definition - Create or update a custom role definition
  • get_role_definition - Retrieve a specific role definition
  • delete_role_definition - Delete a custom role definition
  • list_role_definitions - List all available role definitions

KeyVaultSettingsClient (3 methods):

  • get_setting - Get a specific Managed HSM setting
  • list_settings - List all Managed HSM settings
  • update_setting - Update a Managed HSM setting value

Example Usage

The added examples demonstrate practical usage patterns:

# List all role definitions
role_definitions = access_control_client.list_role_definitions(KeyVaultRoleScope.GLOBAL)
for definition in role_definitions:
    print(f"Role definition: {definition.name}")

# Create a role assignment
role_assignment = access_control_client.create_role_assignment(
    scope=KeyVaultRoleScope.GLOBAL,
    definition_id=definition_id,
    principal_id=principal_id
)

# Update a setting
updated_setting = KeyVaultSetting(
    name=setting.name,
    value=not setting.getboolean(),
    setting_type=KeyVaultSettingType.BOOLEAN
)
result = settings_client.update_setting(updated_setting)

All examples use the Sphinx literalinclude directive to reference actual test code, ensuring the documentation examples remain accurate and executable.

Validation

  • ✅ All imports validated successfully
  • ✅ Docstring syntax verified
  • ✅ Example blocks properly balanced (14 START/END markers each)
  • ✅ Both sync and async patterns implemented
  • ✅ Follows existing Azure SDK documentation patterns

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@Copilot Copilot AI changed the title [WIP] Based on the issue description, open a PR to resolve @Azure/azure-sdk-for-python/issues/34790 by either adding docstring examples using existing tests in @Azure/azure-sdk-for-python/files/sdk/keyvault/azure-keyvault-administration/tests/test_examples_ad... [Key Vault] Add docstring examples for KeyVaultAccessControlClient and KeyVaultSettingsClient Jul 24, 2025
@Copilot Copilot AI requested a review from mccoyp July 24, 2025 00:44
Copilot finished work on behalf of mccoyp July 24, 2025 00:44
@mccoyp mccoyp marked this pull request as ready for review July 30, 2025 17:58
@Copilot Copilot AI review requested due to automatic review settings July 30, 2025 17:58
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds comprehensive docstring examples for all public methods in KeyVaultAccessControlClient and KeyVaultSettingsClient, following the same pattern established by KeyVaultBackupClient. The documentation enhancement improves developer experience by providing practical, executable code examples directly in the API documentation.

  • Adds 3 new test methods containing example code blocks for both sync and async clients
  • Updates docstrings for 11 public methods with literalinclude directives linking to test examples
  • Includes helper methods for test data generation and service principal ID handling

Reviewed Changes

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

Show a summary per file
File Description
test_examples_administration_async.py Adds 3 test methods with async example code for role assignments, role definitions, and settings management
test_examples_administration.py Adds 3 test methods with sync example code for role assignments, role definitions, and settings management
conftest.py Updates environment variable reference from KEYVAULT_CLIENT_ID to CLIENT_OBJECTID
_settings_client.py (async) Adds docstring examples for 3 settings management methods
_access_control_client.py (async) Adds docstring examples for 8 access control methods
_settings_client.py (sync) Adds docstring examples for 3 settings management methods
_access_control_client.py (sync) Adds docstring examples for 8 access control methods
assets.json Updates test asset tag reference

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.

[Key Vault] Add docstring examples for KeyVaultAccessControlClient and KeyVaultSettingsClient
2 participants