示例#1
0
    async def restore_secret(self, backup: bytes,
                             **kwargs: Mapping[str, Any]) -> SecretAttributes:
        """Restores a backed up secret to a vault.

        Restores a backed up secret, and all its versions, to a vault. This
        operation requires the secrets/restore permission.

        :param bytes backup: The raw bytes of the secret backup
        :returns: The restored secret
        :rtype: ~azure.keyvault.secrets._models.SecretAttributes
        :raises: ~azure.core.exceptions.ResourceExistsError, if client failed to restore the secret

        Example:
            .. literalinclude:: ../tests/test_samples_secrets_async.py
                :start-after: [START restore_secret]
                :end-before: [END restore_secret]
                :language: python
                :caption: Restores a backed up secret to the vault
                :dedent: 8
        """
        bundle = await self._client.restore_secret(
            self.vault_url,
            backup,
            error_map={409: ResourceExistsError},
            **kwargs)
        return SecretAttributes._from_secret_bundle(bundle)
示例#2
0
    async def update_secret(self,
                            name: str,
                            version: Optional[str] = None,
                            content_type: Optional[str] = None,
                            enabled: Optional[bool] = None,
                            not_before: Optional[datetime] = None,
                            expires: Optional[datetime] = None,
                            tags: Optional[Dict[str, str]] = None,
                            **kwargs: Mapping[str, Any]) -> SecretAttributes:
        """Updates the attributes associated with a specified secret in the key vault.

        The UPDATE operation changes specified attributes of an existing stored secret.
        Attributes that are not specified in the request are left unchanged. The value
        of a secret itself cannot be changed. This operation requires the secrets/set permission.

        :param str name: The name of the secret
        :param str version: The version of the secret.
        :param str content_type: Type of the secret value such as a password
        :param enabled: Determines whether the object is enabled.
        :type enabled: bool
        :param not_before: Not before date of the secret  in UTC
        :type not_before: datetime.datetime
        :param expires: Expiry date  of the secret in UTC.
        :type expires: datetime.datetime
        :param tags: Application specific metadata in the form of key-value pairs.
        :type tags: dict(str, str)
        :returns: The created secret
        :rtype: ~azure.keyvault.secrets._models.SecretAttributes
        :raises: ~azure.core.exceptions.ResourceNotFoundError, if client failed to retrieve the secret

        Example:
            .. literalinclude:: ../tests/test_samples_secrets_async.py
                :start-after: [START update_secret]
                :end-before: [END update_secret]
                :language: python
                :caption: Updates the attributes associated with a specified secret in the key vault
                :dedent: 8
        """
        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_url,
            name,
            secret_version=version or "",
            content_type=content_type,
            tags=tags,
            secret_attributes=attributes,
            error_map={404: ResourceNotFoundError},
            **kwargs)
        return SecretAttributes._from_secret_bundle(bundle)  # pylint: disable=protected-access
示例#3
0
    async def recover_deleted_secret(
            self, name: str, **kwargs: Mapping[str, Any]) -> SecretAttributes:
        """Recovers the deleted secret to the latest version.

        Recovers the deleted secret in the specified vault.
        This operation can only be performed on a soft-delete enabled
        vault. This operation requires the secrets/recover permission.

        :param str name: The name of the secret
        :returns: The recovered deleted secret
        :rtype: ~azure.keyvault.secrets._models.SecretAttributes

        Example:
            .. literalinclude:: ../tests/test_samples_secrets_async.py
                :start-after: [START recover_deleted_secret]
                :end-before: [END recover_deleted_secret]
                :language: python
                :caption: Restores a backed up secret to the vault
                :dedent: 8
        """
        bundle = await self._client.recover_deleted_secret(
            self.vault_url, name, **kwargs)
        return SecretAttributes._from_secret_bundle(bundle)