Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,19 @@
# Licensed under the MIT License.
# ------------------------------------
from collections import namedtuple
import platform
from .._version import VERSION

try:
import urllib.parse as parse
except ImportError:
# pylint:disable=import-error
import urlparse as parse # type: ignore

USER_AGENT = "azsdk-python-keyvault-keys/{} Python/{} ({})".format(
VERSION, platform.python_version(), platform.platform()
)

from .challenge_auth_policy import ChallengeAuthPolicy, ChallengeAuthPolicyBase
from .client_base import KeyVaultClientBase
from .http_challenge import HttpChallenge
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@
# Licensed under the MIT License.
# ------------------------------------
from typing import Any, Callable, Mapping, AsyncIterator, TYPE_CHECKING

from azure.core.configuration import Configuration
from azure.core.pipeline import AsyncPipeline
from azure.core.pipeline.policies import UserAgentPolicy
from azure.core.pipeline.policies.distributed_tracing import DistributedTracingPolicy
from azure.core.pipeline.transport import AsyncHttpTransport
from msrest.serialization import Model

from ._generated import KeyVaultClient
from . import AsyncChallengeAuthPolicy
from . import AsyncChallengeAuthPolicy, USER_AGENT


if TYPE_CHECKING:
Expand All @@ -22,14 +24,7 @@


class AsyncKeyVaultClientBase:
"""
:param credential: A credential or credential provider which can be used to authenticate to the vault,
a ValueError will be raised if the entity is not provided
:type credential: azure.authentication.Credential or azure.authentication.CredentialProvider
:param str vault_url: The url of the vault to which the client will connect,
a ValueError will be raised if the entity is not provided
:param ~azure.core.configuration.Configuration config: The configuration for the SecretClient
"""
"""Base class for async Key Vault clients"""

@staticmethod
def _create_config(
Expand All @@ -39,6 +34,11 @@ def _create_config(
api_version = KeyVaultClient.DEFAULT_API_VERSION
config = KeyVaultClient.get_configuration_class(api_version, aio=True)(credential, **kwargs)
config.authentication_policy = AsyncChallengeAuthPolicy(credential)

# replace the autorest-generated UserAgentPolicy and its hard-coded user agent
# https://github.com/Azure/azure-sdk-for-python/issues/6637
config.user_agent_policy = UserAgentPolicy(base_user_agent=USER_AGENT, **kwargs)

return config

def __init__(
Expand Down Expand Up @@ -86,6 +86,7 @@ def _build_pipeline(config: Configuration, transport: AsyncHttpTransport, **kwar

if transport is None:
from azure.core.pipeline.transport import AioHttpTransport

transport = AioHttpTransport(**kwargs)

return AsyncPipeline(transport, policies=policies)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
# Licensed under the MIT License.
# ------------------------------------
from typing import TYPE_CHECKING

from azure.core import Configuration
from azure.core.pipeline import Pipeline
from azure.core.pipeline.policies import UserAgentPolicy
from azure.core.pipeline.transport import RequestsTransport
from azure.core.pipeline.policies.distributed_tracing import DistributedTracingPolicy
from ._generated import KeyVaultClient
Expand All @@ -16,20 +18,14 @@
from azure.core.pipeline.transport import HttpTransport

from .challenge_auth_policy import ChallengeAuthPolicy
from . import USER_AGENT


KEY_VAULT_SCOPE = "https://vault.azure.net/.default"


class KeyVaultClientBase(object):
"""
:param credential: A credential or credential provider which can be used to authenticate to the vault,
a ValueError will be raised if the entity is not provided
:type credential: azure.core.credentials.TokenCredential
:param str vault_url: The url of the vault to which the client will connect,
a ValueError will be raised if the entity is not provided
:param ~azure.core.configuration.Configuration config: The configuration for the KeyClient
"""
"""Base class for Key Vault clients"""

@staticmethod
def _create_config(credential, api_version=None, **kwargs):
Expand All @@ -38,6 +34,11 @@ def _create_config(credential, api_version=None, **kwargs):
api_version = KeyVaultClient.DEFAULT_API_VERSION
config = KeyVaultClient.get_configuration_class(api_version, aio=False)(credential, **kwargs)
config.authentication_policy = ChallengeAuthPolicy(credential)

# replace the autorest-generated UserAgentPolicy and its hard-coded user agent
# https://github.com/Azure/azure-sdk-for-python/issues/6637
config.user_agent_policy = UserAgentPolicy(base_user_agent=USER_AGENT, **kwargs)

return config

def __init__(self, vault_url, credential, transport=None, api_version=None, **kwargs):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@


class KeyClient(AsyncKeyVaultClientBase):
"""A high-level interface for managing a vault's keys.
"""A high-level asynchronous interface for managing a vault's keys.

:param credential: An object which can provide an access token for the vault, such as a credential from
:mod:`azure.identity.aio`
:param str vault_url: URL of the vault the client will access

Example:
.. literalinclude:: ../tests/test_samples_keys_async.py
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
class KeyClient(KeyVaultClientBase):
"""A high-level interface for managing a vault's keys.

:param credential: An object which can provide an access token for the vault, such as a credential from
:mod:`azure.identity`
:param str vault_url: URL of the vault the client will access

Example:
.. literalinclude:: ../tests/test_samples_keys.py
:start-after: [START create_key_client]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@


class SecretClient(AsyncKeyVaultClientBase):
"""A high-level interface for managing a vault's secrets.
"""A high-level asynchronous interface for managing a vault's secrets.

:param credential: An object which can provide an access token for the vault, such as a credential from
:mod:`azure.identity.aio`
:param str vault_url: URL of the vault the client will access

Example:
.. literalinclude:: ../tests/test_samples_secrets_async.py
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
class SecretClient(KeyVaultClientBase):
"""A high-level interface for managing a vault's secrets.

:param credential: An object which can provide an access token for the vault, such as a credential from
:mod:`azure.identity`
:param str vault_url: URL of the vault the client will access

Example:
.. literalinclude:: ../tests/test_samples_secrets.py
:start-after: [START create_secret_client]
Expand Down