diff --git a/sdk/identity/azure-identity/CHANGELOG.md b/sdk/identity/azure-identity/CHANGELOG.md index 399f2c761a08..442e17043e38 100644 --- a/sdk/identity/azure-identity/CHANGELOG.md +++ b/sdk/identity/azure-identity/CHANGELOG.md @@ -6,6 +6,10 @@ ### Breaking Changes +> These changes do not impact the API of stable versions such as 1.25.1. +> Only code written against beta version 1.26.0b1 is affected. +- Renamed `use_token_proxy` keyword argument to `enable_azure_proxy` in `WorkloadIdentityCredential` to better reflect its purpose. ([#44147](https://github.com/Azure/azure-sdk-for-python/pull/44147)) + ### Bugs Fixed ### Other Changes diff --git a/sdk/identity/azure-identity/azure/identity/_credentials/workload_identity.py b/sdk/identity/azure-identity/azure/identity/_credentials/workload_identity.py index ef2453e2079d..d1b49c6d2233 100644 --- a/sdk/identity/azure-identity/azure/identity/_credentials/workload_identity.py +++ b/sdk/identity/azure-identity/azure/identity/_credentials/workload_identity.py @@ -105,7 +105,7 @@ def __init__( self._token_file_path = token_file_path - if kwargs.pop("use_token_proxy", False) and not within_credential_chain.get(): + if kwargs.pop("enable_azure_proxy", False) and not within_credential_chain.get(): token_proxy_endpoint = os.environ.get(EnvironmentVariables.AZURE_KUBERNETES_TOKEN_PROXY) sni = os.environ.get(EnvironmentVariables.AZURE_KUBERNETES_SNI_NAME) ca_file = os.environ.get(EnvironmentVariables.AZURE_KUBERNETES_CA_FILE) diff --git a/sdk/identity/azure-identity/azure/identity/aio/_credentials/workload_identity.py b/sdk/identity/azure-identity/azure/identity/aio/_credentials/workload_identity.py index 47fe90a7d8fc..e33bacf5e974 100644 --- a/sdk/identity/azure-identity/azure/identity/aio/_credentials/workload_identity.py +++ b/sdk/identity/azure-identity/azure/identity/aio/_credentials/workload_identity.py @@ -81,7 +81,7 @@ def __init__( self._token_file_path = token_file_path - if kwargs.pop("use_token_proxy", False) and not within_credential_chain.get(): + if kwargs.pop("enable_azure_proxy", False) and not within_credential_chain.get(): token_proxy_endpoint = os.environ.get(EnvironmentVariables.AZURE_KUBERNETES_TOKEN_PROXY) sni = os.environ.get(EnvironmentVariables.AZURE_KUBERNETES_SNI_NAME) ca_file = os.environ.get(EnvironmentVariables.AZURE_KUBERNETES_CA_FILE) diff --git a/sdk/identity/azure-identity/tests/test_workload_identity_credential.py b/sdk/identity/azure-identity/tests/test_workload_identity_credential.py index 1bcdcefbe06d..f4d940300acb 100644 --- a/sdk/identity/azure-identity/tests/test_workload_identity_credential.py +++ b/sdk/identity/azure-identity/tests/test_workload_identity_credential.py @@ -65,10 +65,10 @@ def send(request, **kwargs): class TestWorkloadIdentityCredentialTokenProxy: - """Test cases for WorkloadIdentityCredential with use_token_proxy=True.""" + """Test cases for WorkloadIdentityCredential with enable_azure_proxy=True.""" - def test_use_token_proxy_creates_custom_transport(self): - """Test that use_token_proxy=True creates a custom transport with correct parameters.""" + def test_enable_azure_proxy_creates_custom_transport(self): + """Test that enable_azure_proxy=True creates a custom transport with correct parameters.""" tenant_id = "tenant-id" client_id = "client-id" token_file_path = "foo-path" @@ -91,7 +91,7 @@ def test_use_token_proxy_creates_custom_transport(self): tenant_id=tenant_id, client_id=client_id, token_file_path=token_file_path, - use_token_proxy=True, + enable_azure_proxy=True, ) mock_get_transport.assert_called_once_with( @@ -101,8 +101,8 @@ def test_use_token_proxy_creates_custom_transport(self): ca_data=None, ) - def test_use_token_proxy_with_ca_data(self): - """Test use_token_proxy with CA data instead of CA file.""" + def test_enable_azure_proxy_with_ca_data(self): + """Test enable_azure_proxy with CA data instead of CA file.""" tenant_id = "tenant-id" client_id = "client-id" token_file_path = "foo-path" @@ -123,7 +123,7 @@ def test_use_token_proxy_with_ca_data(self): tenant_id=tenant_id, client_id=client_id, token_file_path=token_file_path, - use_token_proxy=True, + enable_azure_proxy=True, ) mock_get_transport.assert_called_once_with( @@ -133,8 +133,8 @@ def test_use_token_proxy_with_ca_data(self): ca_data=ca_data, ) - def test_use_token_proxy_minimal_config(self): - """Test use_token_proxy with minimal configuration (only proxy endpoint).""" + def test_enable_azure_proxy_minimal_config(self): + """Test enable_azure_proxy with minimal configuration (only proxy endpoint).""" tenant_id = "tenant-id" client_id = "client-id" token_file_path = "foo-path" @@ -153,7 +153,7 @@ def test_use_token_proxy_minimal_config(self): tenant_id=tenant_id, client_id=client_id, token_file_path=token_file_path, - use_token_proxy=True, + enable_azure_proxy=True, ) mock_get_transport.assert_called_once_with( @@ -163,8 +163,8 @@ def test_use_token_proxy_minimal_config(self): ca_data=None, ) - def test_use_token_proxy_missing_proxy_endpoint(self): - """Test that use_token_proxy=True without proxy endpoint uses the normal transport.""" + def test_enable_azure_proxy_missing_proxy_endpoint(self): + """Test that enable_azure_proxy=True without proxy endpoint uses the normal transport.""" tenant_id = "tenant-id" client_id = "client-id" token_file_path = "foo-path" @@ -179,11 +179,11 @@ def test_use_token_proxy_missing_proxy_endpoint(self): tenant_id=tenant_id, client_id=client_id, token_file_path=token_file_path, - use_token_proxy=True, + enable_azure_proxy=True, ) mock_get_transport.assert_not_called() - def test_use_token_proxy_both_ca_file_and_data_raises_error(self): + def test_enable_azure_proxy_both_ca_file_and_data_raises_error(self): """Test that setting both CA file and CA data raises ValueError.""" tenant_id = "tenant-id" client_id = "client-id" @@ -204,11 +204,11 @@ def test_use_token_proxy_both_ca_file_and_data_raises_error(self): tenant_id=tenant_id, client_id=client_id, token_file_path=token_file_path, - use_token_proxy=True, + enable_azure_proxy=True, ) - def test_use_token_proxy_missing_endpoint_with_custom_env_vars_raises_error(self): - """Test that use_token_proxy=True without proxy endpoint but with other custom env vars raises ValueError.""" + def test_enable_azure_proxy_missing_endpoint_with_custom_env_vars_raises_error(self): + """Test that enable_azure_proxy=True without proxy endpoint but with other custom env vars raises ValueError.""" tenant_id = "tenant-id" client_id = "client-id" token_file_path = "foo-path" @@ -230,7 +230,7 @@ def test_use_token_proxy_missing_endpoint_with_custom_env_vars_raises_error(self tenant_id=tenant_id, client_id=client_id, token_file_path=token_file_path, - use_token_proxy=True, + enable_azure_proxy=True, ) # Test with CA file set but no proxy endpoint @@ -243,7 +243,7 @@ def test_use_token_proxy_missing_endpoint_with_custom_env_vars_raises_error(self tenant_id=tenant_id, client_id=client_id, token_file_path=token_file_path, - use_token_proxy=True, + enable_azure_proxy=True, ) # Test with CA data set but no proxy endpoint @@ -256,11 +256,11 @@ def test_use_token_proxy_missing_endpoint_with_custom_env_vars_raises_error(self tenant_id=tenant_id, client_id=client_id, token_file_path=token_file_path, - use_token_proxy=True, + enable_azure_proxy=True, ) - def test_use_token_proxy_false_does_not_create_transport(self): - """Test that use_token_proxy=False (default) does not create a custom transport.""" + def test_enable_azure_proxy_false_does_not_create_transport(self): + """Test that enable_azure_proxy=False (default) does not create a custom transport.""" tenant_id = "tenant-id" client_id = "client-id" token_file_path = "foo-path" @@ -270,7 +270,7 @@ def test_use_token_proxy_false_does_not_create_transport(self): tenant_id=tenant_id, client_id=client_id, token_file_path=token_file_path, - use_token_proxy=False, + enable_azure_proxy=False, ) mock_get_transport.assert_not_called() diff --git a/sdk/identity/azure-identity/tests/test_workload_identity_credential_async.py b/sdk/identity/azure-identity/tests/test_workload_identity_credential_async.py index 6580af09648b..b3b77c4bdde9 100644 --- a/sdk/identity/azure-identity/tests/test_workload_identity_credential_async.py +++ b/sdk/identity/azure-identity/tests/test_workload_identity_credential_async.py @@ -70,10 +70,10 @@ async def send(request, **kwargs): class TestWorkloadIdentityCredentialTokenProxyAsync: - """Async test cases for WorkloadIdentityCredential with use_token_proxy=True.""" + """Async test cases for WorkloadIdentityCredential with enable_azure_proxy=True.""" - def test_use_token_proxy_creates_custom_aiohttp_transport(self): - """Test that use_token_proxy=True creates a custom aiohttp transport with correct parameters.""" + def test_enable_azure_proxy_creates_custom_aiohttp_transport(self): + """Test that enable_azure_proxy=True creates a custom aiohttp transport with correct parameters.""" tenant_id = "tenant-id" client_id = "client-id" token_file_path = "foo-path" @@ -96,7 +96,7 @@ def test_use_token_proxy_creates_custom_aiohttp_transport(self): tenant_id=tenant_id, client_id=client_id, token_file_path=token_file_path, - use_token_proxy=True, + enable_azure_proxy=True, ) mock_get_transport.assert_called_once_with( @@ -106,8 +106,8 @@ def test_use_token_proxy_creates_custom_aiohttp_transport(self): ca_data=None, ) - def test_use_token_proxy_with_ca_data(self): - """Test use_token_proxy with CA data instead of CA file.""" + def test_enable_azure_proxy_with_ca_data(self): + """Test enable_azure_proxy with CA data instead of CA file.""" tenant_id = "tenant-id" client_id = "client-id" token_file_path = "foo-path" @@ -128,7 +128,7 @@ def test_use_token_proxy_with_ca_data(self): tenant_id=tenant_id, client_id=client_id, token_file_path=token_file_path, - use_token_proxy=True, + enable_azure_proxy=True, ) mock_get_transport.assert_called_once_with( sni=None, @@ -137,8 +137,8 @@ def test_use_token_proxy_with_ca_data(self): ca_data=ca_data, ) - def test_use_token_proxy_minimal_config(self): - """Test use_token_proxy with minimal configuration (only proxy endpoint).""" + def test_enable_azure_proxy_minimal_config(self): + """Test enable_azure_proxy with minimal configuration (only proxy endpoint).""" tenant_id = "tenant-id" client_id = "client-id" token_file_path = "foo-path" @@ -157,7 +157,7 @@ def test_use_token_proxy_minimal_config(self): tenant_id=tenant_id, client_id=client_id, token_file_path=token_file_path, - use_token_proxy=True, + enable_azure_proxy=True, ) mock_get_transport.assert_called_once_with( @@ -167,8 +167,8 @@ def test_use_token_proxy_minimal_config(self): ca_data=None, ) - def test_use_token_proxy_missing_proxy_endpoint(self): - """Test that use_token_proxy=True without proxy endpoint uses the normal transport.""" + def test_enable_azure_proxy_missing_proxy_endpoint(self): + """Test that enable_azure_proxy=True without proxy endpoint uses the normal transport.""" tenant_id = "tenant-id" client_id = "client-id" token_file_path = "foo-path" @@ -183,11 +183,11 @@ def test_use_token_proxy_missing_proxy_endpoint(self): tenant_id=tenant_id, client_id=client_id, token_file_path=token_file_path, - use_token_proxy=True, + enable_azure_proxy=True, ) mock_get_transport.assert_not_called() - def test_use_token_proxy_both_ca_file_and_data_raises_error(self): + def test_enable_azure_proxy_both_ca_file_and_data_raises_error(self): """Test that setting both CA file and CA data raises ValueError.""" tenant_id = "tenant-id" client_id = "client-id" @@ -208,11 +208,11 @@ def test_use_token_proxy_both_ca_file_and_data_raises_error(self): tenant_id=tenant_id, client_id=client_id, token_file_path=token_file_path, - use_token_proxy=True, + enable_azure_proxy=True, ) - def test_use_token_proxy_missing_endpoint_with_custom_env_vars_raises_error(self): - """Test that use_token_proxy=True without proxy endpoint but with other custom env vars raises ValueError.""" + def test_enable_azure_proxy_missing_endpoint_with_custom_env_vars_raises_error(self): + """Test that enable_azure_proxy=True without proxy endpoint but with other custom env vars raises ValueError.""" tenant_id = "tenant-id" client_id = "client-id" token_file_path = "foo-path" @@ -234,7 +234,7 @@ def test_use_token_proxy_missing_endpoint_with_custom_env_vars_raises_error(self tenant_id=tenant_id, client_id=client_id, token_file_path=token_file_path, - use_token_proxy=True, + enable_azure_proxy=True, ) # Test with CA file set but no proxy endpoint @@ -247,7 +247,7 @@ def test_use_token_proxy_missing_endpoint_with_custom_env_vars_raises_error(self tenant_id=tenant_id, client_id=client_id, token_file_path=token_file_path, - use_token_proxy=True, + enable_azure_proxy=True, ) # Test with CA data set but no proxy endpoint @@ -260,12 +260,12 @@ def test_use_token_proxy_missing_endpoint_with_custom_env_vars_raises_error(self tenant_id=tenant_id, client_id=client_id, token_file_path=token_file_path, - use_token_proxy=True, + enable_azure_proxy=True, ) @pytest.mark.asyncio @pytest.mark.parametrize("get_token_method", GET_TOKEN_METHODS) - async def test_use_token_proxy_get_token_success(self, get_token_method): + async def test_enable_azure_proxy_get_token_success(self, get_token_method): """Test successful token acquisition when using token proxy.""" tenant_id = "tenant-id" client_id = "client-id" @@ -294,7 +294,7 @@ async def send(request, **kwargs): tenant_id=tenant_id, client_id=client_id, token_file_path=token_file_path, - use_token_proxy=True, + enable_azure_proxy=True, ) open_mock = mock_open(read_data=assertion) @@ -304,8 +304,8 @@ async def send(request, **kwargs): open_mock.assert_called_once_with(token_file_path, encoding="utf-8") - def test_use_token_proxy_false_does_not_create_transport(self): - """Test that use_token_proxy=False (default) does not create a custom transport.""" + def test_enable_azure_proxy_false_does_not_create_transport(self): + """Test that enable_azure_proxy=False (default) does not create a custom transport.""" tenant_id = "tenant-id" client_id = "client-id" token_file_path = "foo-path" @@ -315,7 +315,7 @@ def test_use_token_proxy_false_does_not_create_transport(self): tenant_id=tenant_id, client_id=client_id, token_file_path=token_file_path, - use_token_proxy=False, + enable_azure_proxy=False, ) mock_get_transport.assert_not_called()