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,6 +3,5 @@
# Licensed under the MIT License.
# -------------------------------------
from ._client import KeyClient
from ._models import Key, KeyBase, DeletedKey, KeyOperationResult

__all__ = ["KeyClient"]
13 changes: 10 additions & 3 deletions sdk/keyvault/azure-keyvault-keys/azure/keyvault/keys/_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,23 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
# ------------------------------------
from typing import Any, Dict, Generator, Mapping, Optional, List
from datetime import datetime

try:
from typing import TYPE_CHECKING
except ImportError:
TYPE_CHECKING = False

if TYPE_CHECKING:
from typing import Any, Dict, Generator, Mapping, Optional

from azure.core.exceptions import ResourceExistsError, ResourceNotFoundError

from ._internal import _KeyVaultClientBase
from ._shared import KeyVaultClientBase
from ._models import Key, KeyBase, DeletedKey, KeyOperationResult


class KeyClient(_KeyVaultClientBase):
class KeyClient(KeyVaultClientBase):
"""KeyClient is a high-level interface for managing a vault's keys.

Example:
Expand Down
17 changes: 12 additions & 5 deletions sdk/keyvault/azure-keyvault-keys/azure/keyvault/keys/_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,19 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
# -------------------------------------

import datetime
from typing import Any, Dict, Mapping, Optional

try:
from typing import TYPE_CHECKING
except ImportError:
TYPE_CHECKING = False

if TYPE_CHECKING:
from typing import Any, Dict, Generator, Mapping, Optional

from collections import namedtuple
from ._internal import _parse_vault_id
from ._generated.v7_0 import models
from ._shared import parse_vault_id
from ._shared._generated.v7_0 import models

KeyOperationResult = namedtuple("KeyOperationResult", ["id", "value"])

Expand All @@ -19,7 +26,7 @@ def __init__(self, attributes, vault_id, **kwargs):
# type: (models.KeyAttributes, str, Mapping[str, Any]) -> None
self._attributes = attributes
self._id = vault_id
self._vault_id = _parse_vault_id(vault_id)
self._vault_id = parse_vault_id(vault_id)
self._managed = kwargs.get("managed", None)
self._tags = kwargs.get("tags", None)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,55 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
# ------------------------------------
from collections import namedtuple

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

from .challenge_auth_policy import ChallengeAuthPolicy, ChallengeAuthPolicyBase
from .client_base import KeyVaultClientBase
from .http_challenge import HttpChallenge
from . import http_challenge_cache as HttpChallengeCache

__all__ = ["ChallengeAuthPolicy", "ChallengeAuthPolicyBase", "HttpChallenge", "HttpChallengeCache"]
__all__ = [
"ChallengeAuthPolicy",
"ChallengeAuthPolicyBase",
"HttpChallenge",
"HttpChallengeCache",
"KeyVaultClientBase",
]

_VaultId = namedtuple("VaultId", ["vault_url", "collection", "name", "version"])


def parse_vault_id(url):
try:
parsed_uri = parse.urlparse(url)
except Exception: # pylint: disable=broad-except
raise ValueError("'{}' is not not a valid url".format(url))
if not (parsed_uri.scheme and parsed_uri.hostname):
raise ValueError("'{}' is not not a valid url".format(url))

path = list(filter(None, parsed_uri.path.split("/")))

if len(path) < 2 or len(path) > 3:
raise ValueError("'{}' is not not a valid vault url".format(url))

return _VaultId(
vault_url="{}://{}".format(parsed_uri.scheme, parsed_uri.hostname),
collection=path[0],
name=path[1],
version=path[2] if len(path) == 3 else None,
)


try:
from .async_challenge_auth_policy import AsyncChallengeAuthPolicy
from .async_client_base import AsyncKeyVaultClientBase, AsyncPagingAdapter

__all__.append("AsyncChallengeAuthPolicy")
__all__.extend(["AsyncChallengeAuthPolicy", "AsyncKeyVaultClientBase", "AsyncPagingAdapter"])
except (SyntaxError, ImportError):
pass
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
from azure.core.pipeline.transport import AsyncioRequestsTransport, HttpTransport
from msrest.serialization import Model

from azure.keyvault.keys._generated import KeyVaultClient
from azure.keyvault.keys._shared import AsyncChallengeAuthPolicy
from ._generated import KeyVaultClient
from . import AsyncChallengeAuthPolicy


if TYPE_CHECKING:
Expand Down Expand Up @@ -40,7 +40,7 @@ async def __anext__(self) -> Any:
# TODO: expected type Model got Coroutine instead?


class _AsyncKeyVaultClientBase:
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
# ------------------------------------
from collections import namedtuple
from typing import TYPE_CHECKING
from azure.core import Configuration
from azure.core.pipeline import Pipeline
Expand All @@ -15,41 +14,13 @@
from azure.core.credentials import TokenCredential
from azure.core.pipeline.transport import HttpTransport

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

from ._shared.challenge_auth_policy import ChallengeAuthPolicy

_VaultId = namedtuple("VaultId", ["vault_url", "collection", "name", "version"])
from .challenge_auth_policy import ChallengeAuthPolicy


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


def _parse_vault_id(url):
try:
parsed_uri = parse.urlparse(url)
except Exception: # pylint: disable=broad-except
raise ValueError("'{}' is not not a valid url".format(url))
if not (parsed_uri.scheme and parsed_uri.hostname):
raise ValueError("'{}' is not not a valid url".format(url))

path = list(filter(None, parsed_uri.path.split("/")))

if len(path) < 2 or len(path) > 3:
raise ValueError("'{}' is not not a valid vault url".format(url))

return _VaultId(
vault_url="{}://{}".format(parsed_uri.scheme, parsed_uri.hostname),
collection=path[0],
name=path[1],
version=path[2] if len(path) == 3 else None,
)


class _KeyVaultClientBase(object):
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,5 @@
# Licensed under the MIT License.
# ------------------------------------
from ._client import KeyClient
from .._models import Key, KeyBase, DeletedKey, KeyOperationResult

__all__ = ["KeyClient"]
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
from azure.core.exceptions import ResourceExistsError, ResourceNotFoundError

from azure.keyvault.keys._models import Key, DeletedKey, KeyBase, KeyOperationResult
from ._internal import _AsyncKeyVaultClientBase, AsyncPagingAdapter
from azure.keyvault.keys._shared import AsyncKeyVaultClientBase, AsyncPagingAdapter


class KeyClient(_AsyncKeyVaultClientBase):
class KeyClient(AsyncKeyVaultClientBase):
"""The KeyClient class defines a high level interface for managing keys in the specified vault.

Example:
Expand Down
4 changes: 2 additions & 2 deletions sdk/keyvault/azure-keyvault-keys/tests/keys_vault_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
except ImportError:
TYPE_CHECKING = False

from azure.keyvault.keys._internal import _KeyVaultClientBase
from azure.keyvault.keys._shared import KeyVaultClientBase
from azure.keyvault.keys import KeyClient

if TYPE_CHECKING:
Expand All @@ -18,7 +18,7 @@
from typing import Any, Optional


class VaultClient(_KeyVaultClientBase):
class VaultClient(KeyVaultClientBase):
def __init__(self, vault_url, credential, config=None, transport=None, api_version=None, **kwargs):
# type: (str, TokenCredential, Configuration, Optional[HttpTransport], Optional[str], **Any) -> None
super(VaultClient, self).__init__(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@
from azure.core.pipeline.transport import AsyncioRequestsTransport, HttpTransport
from msrest.serialization import Model

from azure.keyvault.keys._generated import KeyVaultClient
from azure.keyvault.keys.aio import KeyClient
from azure.keyvault.keys.aio._internal import _AsyncKeyVaultClientBase
from azure.keyvault.keys._shared import AsyncKeyVaultClientBase

if TYPE_CHECKING:
try:
Expand All @@ -24,7 +23,7 @@
KEY_VAULT_SCOPE = "https://vault.azure.net/.default"


class VaultClient(_AsyncKeyVaultClientBase):
class VaultClient(AsyncKeyVaultClientBase):
def __init__(
self,
vault_url: str,
Expand Down
2 changes: 1 addition & 1 deletion sdk/keyvault/azure-keyvault-keys/tests/test_key_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import time

from azure.core.exceptions import ResourceNotFoundError
from azure.keyvault.keys._generated.v7_0.models import JsonWebKey
from azure.keyvault.keys._shared._generated.v7_0.models import JsonWebKey
from keys_preparer import VaultClientPreparer
from keys_test_case import KeyVaultTestCase
from devtools_testutils import ResourceGroupPreparer
Expand Down
2 changes: 1 addition & 1 deletion sdk/keyvault/azure-keyvault-keys/tests/test_keys_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from keys_async_preparer import AsyncVaultClientPreparer
from keys_async_test_case import AsyncKeyVaultTestCase

from azure.keyvault.keys._generated.v7_0.models import JsonWebKey
from azure.keyvault.keys._shared._generated.v7_0.models import JsonWebKey

from dateutil import parser as date_parse

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,5 @@
# Licensed under the MIT License.
# ------------------------------------
from ._client import SecretClient
from ._models import Secret, SecretAttributes, DeletedSecret

__all__ = ["SecretClient"]
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,23 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
# ------------------------------------
from typing import Any, Dict, Generator, Mapping, Optional
from datetime import datetime

try:
from typing import TYPE_CHECKING
except ImportError:
TYPE_CHECKING = False

if TYPE_CHECKING:
from typing import Any, Dict, Generator, Mapping, Optional

from azure.core.exceptions import ResourceExistsError, ResourceNotFoundError

from ._internal import _KeyVaultClientBase
from ._shared import KeyVaultClientBase
from ._models import Secret, DeletedSecret, SecretAttributes


class SecretClient(_KeyVaultClientBase):
class SecretClient(KeyVaultClientBase):
"""SecretClient is a high-level interface for managing a vault's secrets.

Example:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,18 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
# ------------------------------------

import datetime
from typing import Any, Dict, Mapping, Optional
from ._generated.v7_0 import models
from ._internal import _parse_vault_id

try:
from typing import TYPE_CHECKING
except ImportError:
TYPE_CHECKING = False

if TYPE_CHECKING:
from typing import Any, Dict, Mapping, Optional

from ._shared import parse_vault_id
from ._shared._generated.v7_0 import models


class SecretAttributes(object):
Expand All @@ -16,7 +23,7 @@ def __init__(self, attributes, vault_id, **kwargs):
# type: (models.SecretAttributes, str, Mapping[str, Any]) -> None
self._attributes = attributes
self._id = vault_id
self._vault_id = _parse_vault_id(vault_id)
self._vault_id = parse_vault_id(vault_id)
self._content_type = kwargs.get("content_type", None)
self._key_id = kwargs.get("key_id", None)
self._managed = kwargs.get("managed", None)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# ------------------------------------
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
# ------------------------------------
from collections import namedtuple

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

from .challenge_auth_policy import ChallengeAuthPolicy, ChallengeAuthPolicyBase
from .client_base import KeyVaultClientBase
from .http_challenge import HttpChallenge
from . import http_challenge_cache as HttpChallengeCache

__all__ = [
"ChallengeAuthPolicy",
"ChallengeAuthPolicyBase",
"HttpChallenge",
"HttpChallengeCache",
"KeyVaultClientBase",
]

_VaultId = namedtuple("VaultId", ["vault_url", "collection", "name", "version"])


def parse_vault_id(url):
try:
parsed_uri = parse.urlparse(url)
except Exception: # pylint: disable=broad-except
raise ValueError("'{}' is not not a valid url".format(url))
if not (parsed_uri.scheme and parsed_uri.hostname):
raise ValueError("'{}' is not not a valid url".format(url))

path = list(filter(None, parsed_uri.path.split("/")))

if len(path) < 2 or len(path) > 3:
raise ValueError("'{}' is not not a valid vault url".format(url))

return _VaultId(
vault_url="{}://{}".format(parsed_uri.scheme, parsed_uri.hostname),
collection=path[0],
name=path[1],
version=path[2] if len(path) == 3 else None,
)


try:
from .async_challenge_auth_policy import AsyncChallengeAuthPolicy
from .async_client_base import AsyncKeyVaultClientBase, AsyncPagingAdapter

__all__.extend(["AsyncChallengeAuthPolicy", "AsyncKeyVaultClientBase", "AsyncPagingAdapter"])
except (SyntaxError, ImportError):
pass
Loading