async def restore_secret(self, backup: bytes,
                             **kwargs: "**Any") -> SecretProperties:
        """Restore a backed up secret. Requires the secrets/restore permission.

        :param bytes backup: The raw bytes of the secret backup
        :returns: The restored secret
        :rtype: ~azure.keyvault.secrets.models.SecretProperties
        :raises:
            :class:`~azure.core.exceptions.ResourceExistsError` if the secret's name is already in use,
            :class:`~azure.core.exceptions.HttpResponseError` for other errors

        Example:
            .. literalinclude:: ../tests/test_samples_secrets_async.py
                :start-after: [START restore_secret]
                :end-before: [END restore_secret]
                :language: python
                :caption: Restore a backed up secret
                :dedent: 8
        """
        bundle = await self._client.restore_secret(
            self.vault_url,
            backup,
            error_map={409: ResourceExistsError},
            **kwargs)
        return SecretProperties._from_secret_bundle(bundle)
Esempio n. 2
0
    async def update_secret_properties(self,
                                       name: str,
                                       version: Optional[str] = None,
                                       content_type: Optional[str] = None,
                                       not_before: Optional[datetime] = None,
                                       expires: Optional[datetime] = None,
                                       **kwargs: "**Any") -> SecretProperties:
        """Update a secret's attributes, such as its tags or whether it's enabled. Requires the secrets/set permission.

        **This method can't change a secret's value.** Use :func:`set_secret` to change values.

        :param str name: Name of the secret
        :param str version: (optional) Version of the secret to update. If unspecified, the latest version is updated.
        :param str content_type: (optional) An arbitrary string indicating the type of the secret, e.g. 'password'
        :param bool enabled: (optional) Whether the secret is enabled for use
        :param datetime.datetime not_before: (optional) Not before date of the secret in UTC
        :param datetime.datetime expires: (optional) Expiry date  of the secret in UTC.
        :param dict(str, str) tags: (optional) Application specific metadata in the form of key-value pairs.
        :rtype: ~azure.keyvault.secrets.models.SecretProperties
        :raises:
            :class:`~azure.core.exceptions.ResourceNotFoundError` if the secret doesn't exist,
            :class:`~azure.core.exceptions.HttpResponseError` for other errors

        Keyword arguments
            - *enabled (bool)* - Whether the secret is enabled for use.
            - *tags (dict[str, str])* - Application specific metadata in the form of key-value pairs.

        Example:
            .. literalinclude:: ../tests/test_samples_secrets_async.py
                :start-after: [START update_secret]
                :end-before: [END update_secret]
                :language: python
                :caption: Updates a secret's attributes
                :dedent: 8
        """
        enabled = kwargs.pop('enabled', None)
        if enabled is not None or not_before is not None or expires is not None:
            attributes = self._client.models.SecretAttributes(
                enabled=enabled, not_before=not_before, expires=expires)
        else:
            attributes = None
        bundle = await self._client.update_secret(self.vault_endpoint,
                                                  name,
                                                  secret_version=version or "",
                                                  content_type=content_type,
                                                  secret_attributes=attributes,
                                                  error_map=_error_map,
                                                  **kwargs)
        return SecretProperties._from_secret_bundle(bundle)  # pylint: disable=protected-access
    async def recover_deleted_secret(self, name: str, **kwargs: "**Any") -> SecretProperties:
        """Recover a deleted secret to its latest version. This is only possible in vaults with soft-delete enabled.
        Requires the secrets/recover permission.

        :param str name: Name of the secret
        :returns: The recovered secret
        :rtype: ~azure.keyvault.secrets.models.SecretProperties
        :raises: :class:`~azure.core.exceptions.HttpResponseError`

        Example:
            .. literalinclude:: ../tests/test_samples_secrets_async.py
                :start-after: [START recover_deleted_secret]
                :end-before: [END recover_deleted_secret]
                :language: python
                :caption: Recover a deleted secret
                :dedent: 8
        """
        bundle = await self._client.recover_deleted_secret(self.vault_endpoint, name, **kwargs)
        return SecretProperties._from_secret_bundle(bundle)