Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
f9e8092
move generated code out of shared folder
iscai-msft Jun 12, 2020
ec97071
generate with autorest v3
iscai-msft Jun 12, 2020
d0969ce
fix wiring with new generated code
iscai-msft Jun 17, 2020
c50b77d
regenerate with latest changes from swagger pr
iscai-msft Jun 17, 2020
b2e3544
only call and import AioHttpTransport if user did not supply a transport
iscai-msft Jun 18, 2020
7f327dd
correct user agent
iscai-msft Jun 18, 2020
2b597e1
fix duplicate platform info in user agent
iscai-msft Jun 18, 2020
42d3eb2
fix pylint
iscai-msft Jun 18, 2020
0977b6e
Merge branch 'master' of https://github.com/Azure/azure-sdk-for-pytho…
iscai-msft Jun 22, 2020
6219da6
switch references of user agent to sdk moniker in wrapped code
iscai-msft Jun 22, 2020
0f3e4cb
Revert "switch references of user agent to sdk moniker in wrapped code"
iscai-msft Jun 22, 2020
d7200de
generate with unflattened code
iscai-msft Jun 24, 2020
a4400ea
regenerate to get exposed http_logging_policy
iscai-msft Jun 30, 2020
ad41081
add allowed header names to http logging policy
iscai-msft Jun 30, 2020
f4c6243
added back user agent -> sdk moniker change
iscai-msft Jun 30, 2020
abfe3ee
add tests for http logging policy
iscai-msft Jun 30, 2020
d5634fc
update dependency on azure core
iscai-msft Jun 30, 2020
e564e8d
Merge branch 'master' of https://github.com/Azure/azure-sdk-for-pytho…
iscai-msft Jun 30, 2020
5e3bc44
remove 7.2-preview from generation
iscai-msft Jul 1, 2020
9328d85
add continuation token
iscai-msft Jul 2, 2020
b146a9f
add test
iscai-msft Jul 2, 2020
74b9569
improve code flow
iscai-msft Jul 2, 2020
e1396f9
remove passing of continuation token to poller
iscai-msft Jul 2, 2020
daa5534
add retrieval of recovered secret to test
iscai-msft Jul 2, 2020
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
2 changes: 2 additions & 0 deletions sdk/keyvault/azure-keyvault-secrets/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
- Values of `x-ms-keyvault-region` and `x-ms-keyvault-service-version` headers
are no longer redacted in logging output.
- Updated minimum `azure-core` version to 1.4.0
- All long running operation methods now accept a `continuation_token` keyword argument
to restart the poller from a saved state

## 4.2.0b1 (2020-03-10)
- Support for Key Vault API version 7.1-preview
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Licensed under the MIT License.
# ------------------------------------
from ._models import DeletedSecret, KeyVaultSecret, SecretProperties
from ._shared.multi_api import ApiVersion
from ._shared.client_base import ApiVersion
from ._client import SecretClient

__all__ = ["ApiVersion", "SecretClient", "KeyVaultSecret", "SecretProperties", "DeletedSecret"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
# ------------------------------------
import pickle
import base64
from functools import partial
from azure.core.tracing.decorator import distributed_trace

Expand Down Expand Up @@ -103,17 +105,25 @@ def set_secret(self, name, value, **kwargs):
enabled = kwargs.pop("enabled", None)
not_before = kwargs.pop("not_before", None)
expires_on = kwargs.pop("expires_on", None)
content_type = kwargs.pop("content_type", None)
if enabled is not None or not_before is not None or expires_on is not None:
attributes = self._models.SecretAttributes(
enabled=enabled, not_before=not_before, expires=expires_on
)
else:
attributes = None

parameters = self._models.SecretSetParameters(
value=value,
tags=kwargs.pop("tags", None),
content_type=content_type,
secret_attributes=attributes
)

bundle = self._client.set_secret(
vault_base_url=self.vault_url,
secret_name=name,
value=value,
secret_attributes=attributes,
parameters=parameters,
error_map=_error_map,
**kwargs
)
Expand Down Expand Up @@ -152,17 +162,25 @@ def update_secret_properties(self, name, version=None, **kwargs):
enabled = kwargs.pop("enabled", None)
not_before = kwargs.pop("not_before", None)
expires_on = kwargs.pop("expires_on", None)
content_type = kwargs.pop("content_type", None)
if enabled is not None or not_before is not None or expires_on is not None:
attributes = self._models.SecretAttributes(
enabled=enabled, not_before=not_before, expires=expires_on
)
else:
attributes = None

parameters = self._models.SecretUpdateParameters(
content_type=content_type,
secret_attributes=attributes,
tags=kwargs.pop("tags", None)
)

bundle = self._client.update_secret(
self.vault_url,
name,
secret_version=version or "",
secret_attributes=attributes,
parameters=parameters,
error_map=_error_map,
**kwargs
)
Expand Down Expand Up @@ -268,7 +286,12 @@ def restore_secret_backup(self, backup, **kwargs):
:dedent: 8

"""
bundle = self._client.restore_secret(self.vault_url, backup, error_map=_error_map, **kwargs)
bundle = self._client.restore_secret(
self.vault_url,
parameters=self._models.SecretRestoreParameters(secret_bundle_backup=backup),
error_map=_error_map,
**kwargs
)
return SecretProperties._from_secret_bundle(bundle)

@distributed_trace
Expand All @@ -280,6 +303,7 @@ def begin_delete_secret(self, name, **kwargs):
with soft-delete enabled. This method therefore returns a poller enabling you to wait for deletion to complete.

:param str name: Name of the secret to delete.
:keyword str continuation_token: A continuation token to restart the poller from a saved state.
:returns: A poller for the delete operation. The poller's `result` method returns the
:class:`~azure.keyvault.secrets.DeletedSecret` without waiting for deletion to complete. If the vault has
soft-delete enabled and you want to permanently delete the secret with :func:`purge_deleted_secret`, call the
Expand All @@ -300,11 +324,16 @@ def begin_delete_secret(self, name, **kwargs):

"""
polling_interval = kwargs.pop("_polling_interval", None)
continuation_token = kwargs.pop("continuation_token", None)
if polling_interval is None:
polling_interval = 2
deleted_secret = DeletedSecret._from_deleted_secret_bundle(
self._client.delete_secret(self.vault_url, name, error_map=_error_map, **kwargs)
)

if continuation_token:
deleted_secret = pickle.loads(base64.b64decode(continuation_token))
else:
deleted_secret = DeletedSecret._from_deleted_secret_bundle(
self._client.delete_secret(self.vault_url, name, error_map=_error_map, **kwargs)
)

command = partial(self.get_deleted_secret, name=name, **kwargs)
polling_method = DeleteRecoverPollingMethod(
Expand All @@ -314,6 +343,12 @@ def begin_delete_secret(self, name, **kwargs):
final_resource=deleted_secret,
interval=polling_interval,
)

if continuation_token:
return KeyVaultOperationPoller.from_continuation_token(
polling_method=polling_method
)

return KeyVaultOperationPoller(polling_method)

@distributed_trace
Expand Down Expand Up @@ -408,6 +443,7 @@ def begin_recover_deleted_secret(self, name, **kwargs):
Requires the secrets/recover permission.

:param str name: Name of the deleted secret to recover
:keyword str continuation_token: A continuation token to restart the poller from a saved state.
:returns: A poller for the recovery operation. The poller's `result` method returns the recovered
:class:`~azure.keyvault.secrets.Secret` without waiting for recovery to complete. If you want to use the
recovered secret immediately, call the poller's `wait` method, which blocks until the secret is ready to use.
Expand All @@ -425,14 +461,25 @@ def begin_recover_deleted_secret(self, name, **kwargs):

"""
polling_interval = kwargs.pop("_polling_interval", None)
continuation_token = kwargs.pop("continuation_token", None)
if polling_interval is None:
polling_interval = 2
recovered_secret = SecretProperties._from_secret_bundle(
self._client.recover_deleted_secret(self.vault_url, name, error_map=_error_map, **kwargs)
)

if continuation_token:
recovered_secret = pickle.loads(base64.b64decode(continuation_token))
else:
recovered_secret = SecretProperties._from_secret_bundle(
self._client.recover_deleted_secret(self.vault_url, name, error_map=_error_map, **kwargs)
)

command = partial(self.get_secret, name=name, **kwargs)
polling_method = DeleteRecoverPollingMethod(
finished=False, command=command, final_resource=recovered_secret, interval=polling_interval,
)

if continuation_token:
return KeyVaultOperationPoller.from_continuation_token(
polling_method=polling_method
)

return KeyVaultOperationPoller(polling_method)
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
# coding=utf-8
# --------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for
# license information.
#
# Licensed under the MIT License. See License.txt in the project root for license information.
# Code generated by Microsoft (R) AutoRest Code Generator.
# Changes may cause incorrect behavior and will be lost if the code is
# regenerated.
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
# --------------------------------------------------------------------------

from ._key_vault_client import KeyVaultClient
__all__ = ['KeyVaultClient']

from .version import VERSION

__version__ = VERSION

try:
from ._patch import patch_sdk # type: ignore
patch_sdk()
except ImportError:
pass
Original file line number Diff line number Diff line change
Expand Up @@ -8,40 +8,42 @@
# Changes may cause incorrect behavior and will be lost if the code is
# regenerated.
# --------------------------------------------------------------------------
from typing import Any

from azure.core.configuration import Configuration
from azure.core.pipeline import policies

from .version import VERSION
from ._version import VERSION


class KeyVaultClientConfiguration(Configuration):
"""Configuration for KeyVaultClient
"""Configuration for KeyVaultClient.

Note that all parameters used to create this instance are saved as instance
attributes.

:param credentials: Credentials needed for the client to connect to Azure.
:type credentials: :mod:`A msrestazure Credentials
object<msrestazure.azure_active_directory>`
"""

def __init__(self, credentials, **kwargs):

if credentials is None:
raise ValueError("Parameter 'credentials' must not be None.")

def __init__(
self,
**kwargs # type: Any
):
# type: (...) -> None
super(KeyVaultClientConfiguration, self).__init__(**kwargs)
self._configure(**kwargs)

self.user_agent_policy.add_user_agent('azsdk-python-azure-keyvault/{}'.format(VERSION))
self.generate_client_request_id = True

self.credentials = credentials
kwargs.setdefault('sdk_moniker', 'azure-keyvault/{}'.format(VERSION))
self._configure(**kwargs)

def _configure(self, **kwargs):
def _configure(
self,
**kwargs # type: Any
):
# type: (...) -> None
self.user_agent_policy = kwargs.get('user_agent_policy') or policies.UserAgentPolicy(**kwargs)
self.headers_policy = kwargs.get('headers_policy') or policies.HeadersPolicy(**kwargs)
self.proxy_policy = kwargs.get('proxy_policy') or policies.ProxyPolicy(**kwargs)
self.logging_policy = kwargs.get('logging_policy') or policies.NetworkTraceLoggingPolicy(**kwargs)
self.http_logging_policy = kwargs.get('http_logging_policy') or policies.HttpLoggingPolicy(**kwargs)
self.retry_policy = kwargs.get('retry_policy') or policies.RetryPolicy(**kwargs)
self.custom_hook_policy = kwargs.get('custom_hook_policy') or policies.CustomHookPolicy(**kwargs)
self.redirect_policy = kwargs.get('redirect_policy') or policies.RedirectPolicy(**kwargs)
self.authentication_policy = kwargs.get('authentication_policy')
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
# coding=utf-8
# --------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for
# license information.
#
# Code generated by Microsoft (R) AutoRest Code Generator.
# Changes may cause incorrect behavior and will be lost if the code is
# regenerated.
# --------------------------------------------------------------------------

from azure.core import PipelineClient
from msrest import Serializer, Deserializer

from azure.profiles import KnownProfiles, ProfileDefinition
from azure.profiles.multiapiclient import MultiApiClientMixin
from ._configuration import KeyVaultClientConfiguration
from ._operations_mixin import KeyVaultClientOperationsMixin
class _SDKClient(object):
def __init__(self, *args, **kwargs):
"""This is a fake class to support current implemetation of MultiApiClientMixin."
Will be removed in final version of multiapi azure-core based client
"""
pass

class KeyVaultClient(KeyVaultClientOperationsMixin, MultiApiClientMixin, _SDKClient):
"""The key vault client performs cryptographic key operations and vault operations against the Key Vault service.

This ready contains multiple API versions, to help you deal with all of the Azure clouds
(Azure Stack, Azure Government, Azure China, etc.).
By default, it uses the latest API version available on public Azure.
For production, you should stick to a particular api-version and/or profile.
The profile sets a mapping between an operation group and its API version.
The api-version parameter sets the default API version if the operation
group is not described in the profile.
:param str api_version: API version to use if no profile is provided, or if
missing in profile.
:param profile: A profile definition, from KnownProfiles to dict.
:type profile: azure.profiles.KnownProfiles
:keyword int polling_interval: Default waiting time between two polls for LRO operations if no Retry-After header is present.
"""

DEFAULT_API_VERSION = '7.0'
_PROFILE_TAG = "azure.keyvault.KeyVaultClient"
LATEST_PROFILE = ProfileDefinition({
_PROFILE_TAG: {
None: DEFAULT_API_VERSION,
}},
_PROFILE_TAG + " latest"
)

def __init__(
self,
api_version=None,
base_url=None,
profile=KnownProfiles.default,
**kwargs # type: Any
):
base_url = '{vaultBaseUrl}'
self._config = KeyVaultClientConfiguration(**kwargs)
self._client = PipelineClient(base_url=base_url, config=self._config, **kwargs)
super(KeyVaultClient, self).__init__(
api_version=api_version,
profile=profile
)

@classmethod
def _models_dict(cls, api_version):
return {k: v for k, v in cls.models(api_version).__dict__.items() if isinstance(v, type)}

@classmethod
def models(cls, api_version=DEFAULT_API_VERSION):
"""Module depends on the API version:

* 2016-10-01: :mod:`v2016_10_01.models<azure.keyvault.v2016_10_01.models>`
* 7.0: :mod:`v7_0.models<azure.keyvault.v7_0.models>`
* 7.1-preview: :mod:`v7_1_preview.models<azure.keyvault.v7_1_preview.models>`
"""
if api_version == '2016-10-01':
from .v2016_10_01 import models
return models
elif api_version == '7.0':
from .v7_0 import models
return models
elif api_version == '7.1-preview':
from .v7_1_preview import models
return models
raise NotImplementedError("APIVersion {} is not available".format(api_version))

def close(self):
self._client.close()
def __enter__(self):
self._client.__enter__()
return self
def __exit__(self, *exc_details):
self._client.__exit__(*exc_details)
Loading