Exemple #1
0
    async def get_secret(self,
                         name: str,
                         version: Optional[str] = None,
                         **kwargs: "**Any") -> Secret:
        """Get a secret. Requires the secrets/get permission.

        :param str name: The name of the secret
        :param str version: (optional) Version of the secret to get. If unspecified, gets the latest version.
        :rtype: ~azure.keyvault.secrets.models.Secret
        :raises:
            :class:`~azure.core.exceptions.ResourceNotFoundError` if the secret doesn't exist,
            :class:`~azure.core.exceptions.HttpResponseError` for other errors

        Example:
            .. literalinclude:: ../tests/test_samples_secrets_async.py
                :start-after: [START get_secret]
                :end-before: [END get_secret]
                :language: python
                :caption: Get a secret
                :dedent: 8
        """
        bundle = await self._client.get_secret(self.vault_endpoint,
                                               name,
                                               version or "",
                                               error_map=_error_map,
                                               **kwargs)
        return Secret._from_secret_bundle(bundle)
    async def set_secret(self, name: str, value: str, **kwargs: "Any") -> Secret:
        """Set a secret value. Create a new secret if ``name`` is not in use. If it is, create a new version of the
        secret.

        :param str name: The name of the secret
        :param str value: The value of the secret
        :rtype: ~azure.keyvault.secrets.models.Secret
        :raises: :class:`~azure.core.exceptions.HttpResponseError`

        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.
            - **content_type** (str): An arbitrary string indicating the type of the secret, e.g. 'password'
            - **not_before** (:class:`~datetime.datetime`): Not before date of the secret in UTC
            - **expires_on** (:class:`~datetime.datetime`): Expiry date of the secret in UTC

        Example:
            .. literalinclude:: ../tests/test_samples_secrets_async.py
                :start-after: [START set_secret]
                :end-before: [END set_secret]
                :language: python
                :caption: Set a secret's value
                :dedent: 8
        """
        enabled = kwargs.pop("enabled", None)
        not_before = kwargs.pop("not_before", None)
        expires_on = kwargs.pop("expires_on", None)
        if enabled is not None or not_before is not None or expires_on is not None:
            attributes = self._client.models.SecretAttributes(
                enabled=enabled, not_before=not_before, expires=expires_on
            )
        else:
            attributes = None
        bundle = await self._client.set_secret(self.vault_endpoint, name, value, secret_attributes=attributes, **kwargs)
        return Secret._from_secret_bundle(bundle)
    async def set_secret(self,
                         name: str,
                         value: str,
                         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: "**Any") -> Secret:
        """Set a secret value. Create a new secret if ``name`` is not in use. If it is, create a new version of the
        secret.

        :param str name: The name of the secret
        :param str value: The value of the secret
        :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 tags: (optional) Application specific metadata in the form of key-value pairs
        :rtype: ~azure.keyvault.secrets.models.Secret
        :raises: :class:`~azure.core.exceptions.HttpResponseError`

        Example:
            .. literalinclude:: ../tests/test_samples_secrets_async.py
                :start-after: [START set_secret]
                :end-before: [END set_secret]
                :language: python
                :caption: Set a secret's value
                :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.set_secret(self.vault_url,
                                               name,
                                               value,
                                               secret_attributes=attributes,
                                               content_type=content_type,
                                               tags=tags,
                                               **kwargs)
        return Secret._from_secret_bundle(bundle)