Ejemplo n.º 1
0
    async def create_certificate(
            self, name: str, policy: CertificatePolicy, **kwargs: "**Any"
    ) -> Union[KeyVaultCertificate, CertificateOperation]:
        """Creates a new certificate.

        If this is the first version, the certificate resource is created. This
        operation requires the certificates/create permission.

        :param str name: The name of the certificate.
        :param policy: The management policy for the certificate.
        :type policy:
         ~azure.keyvault.certificates.models.CertificatePolicy
        :returns: A coroutine for the creation of the certificate. Awaiting the coroutine
         returns the created KeyVaultCertificate if creation is successful, the CertificateOperation if not.
        :rtype: ~azure.keyvault.certificates.models.KeyVaultCertificate or
         ~azure.keyvault.certificates.models.CertificateOperation
        :raises: :class:`~azure.core.exceptions.HttpResponseError`

        Keyword arguments
            - *enabled (bool)* - Determines whether the object is enabled.
            - *tags (dict[str, str])* - Application specific metadata in the form of key-value pairs.

        Example:
            .. literalinclude:: ../tests/test_examples_certificates_async.py
                :start-after: [START create_certificate]
                :end-before: [END create_certificate]
                :language: python
                :caption: Create a certificate
                :dedent: 8
        """

        enabled = kwargs.pop("enabled", None)
        tags = kwargs.pop("tags", None)

        if enabled is not None:
            attributes = self._client.models.CertificateAttributes(
                enabled=enabled)
        else:
            attributes = None
        cert_bundle = await self._client.create_certificate(
            vault_base_url=self.vault_endpoint,
            certificate_name=name,
            certificate_policy=policy._to_certificate_policy_bundle(),
            certificate_attributes=attributes,
            tags=tags,
            **kwargs)

        create_certificate_operation = CertificateOperation._from_certificate_operation_bundle(
            cert_bundle)

        command = partial(self.get_certificate_operation, name=name, **kwargs)

        get_certificate_command = partial(self.get_certificate,
                                          name=name,
                                          **kwargs)

        create_certificate_polling = CreateCertificatePollerAsync(
            get_certificate_command=get_certificate_command)
        return await async_poller(command, create_certificate_operation, None,
                                  create_certificate_polling)
Ejemplo n.º 2
0
    async def cancel_certificate_operation(self, name: str, **kwargs: "**Any") -> CertificateOperation:
        """Cancels a certificate operation.

        Cancels a certificate creation operation that is already in progress.
        This operation requires the certificates/update permission.

        :param str name: The name of the certificate.
        :returns: The cancelled certificate operation
        :rtype: ~azure.keyvault.certificates.models.CertificateOperation
        :raises: :class:`~azure.core.exceptions.HttpResponseError`
        """
        bundle = await self._client.update_certificate_operation(
            vault_base_url=self.vault_url, certificate_name=name, cancellation_requested=True, **kwargs
        )
        return CertificateOperation._from_certificate_operation_bundle(certificate_operation_bundle=bundle)
Ejemplo n.º 3
0
    async def delete_certificate_operation(self, name: str, **kwargs: "**Any") -> CertificateOperation:
        """Deletes the creation operation for a specific certificate.

        Deletes the creation operation for a specified certificate that is in
        the process of being created. The certificate is no longer created.
        This operation requires the certificates/update permission.

        :param str name: The name of the certificate.
        :return: The deleted CertificateOperation
        :rtype: ~azure.keyvault.certificates.models.CertificateOperation
        :raises:
            :class:`~azure.core.exceptions.ResourceNotFoundError` if the operation doesn't exist,
            :class:`~azure.core.exceptions.HttpResponseError` for other errors
        """
        bundle = await self._client.delete_certificate_operation(
            vault_base_url=self.vault_url, certificate_name=name, error_map=_error_map, **kwargs
        )
        return CertificateOperation._from_certificate_operation_bundle(certificate_operation_bundle=bundle)
Ejemplo n.º 4
0
    async def get_certificate_operation(self, name: str, **kwargs: "**Any") -> CertificateOperation:
        """Gets the creation operation of a certificate.

        Gets the creation operation associated with a specified certificate.
        This operation requires the certificates/get permission.

        :param str name: The name of the certificate.
        :returns: The created CertificateOperation
        :rtype: ~azure.keyvault.certificates.models.CertificateOperation
        :raises:
            :class:`~azure.core.exceptions.ResourceNotFoundError` if the certificate doesn't exist,
            :class:`~azure.core.exceptions.HttpResponseError` for other errors
        """

        bundle = await self._client.get_certificate_operation(
            vault_base_url=self.vault_url, certificate_name=name, error_map=_error_map, **kwargs
        )
        return CertificateOperation._from_certificate_operation_bundle(certificate_operation_bundle=bundle)
Ejemplo n.º 5
0
    async def create_certificate(
        self,
        name: str,
        policy: Optional[CertificatePolicy] = None,
        enabled: Optional[bool] = None,
        tags: Optional[Dict[str, str]] = None,
        **kwargs: "**Any"
    ) -> Coroutine:
        """Creates a new certificate.

        If this is the first version, the certificate resource is created. This
        operation requires the certificates/create permission.

        :param str name: The name of the certificate.
        :param policy: The management policy for the certificate.
        :type policy:
         ~azure.keyvault.certificates.models.CertificatePolicy
        :param bool enabled: Determines whether the object is enabled.
        :param tags: Application specific metadata in the form of key-value pairs.
        :type tags: dict(str, str)
        :returns: A coroutine for the creation of the certificate. Awaiting the coroutine
         returns the created Certificate if creation is successful, the CertificateOperation if not.
        :rtype: coroutine[~azure.keyvault.certificates.models.Certificate or
         ~azure.keyvault.certificates.models.CertificateOperation]
        :raises: :class:`~azure.core.exceptions.HttpResponseError`

        Example:
            .. literalinclude:: ../tests/test_examples_certificates_async.py
                :start-after: [START create_certificate]
                :end-before: [END create_certificate]
                :language: python
                :caption: Create a certificate
                :dedent: 8
        """
        if enabled is not None:
            attributes = self._client.models.CertificateAttributes(
                enabled=enabled
            )
        else:
            attributes = None

        if not policy:
            lifetime_actions = [LifetimeAction(
                days_before_expiry=90,
                action_type="AutoRenew"
            )]
            policy = CertificatePolicy(key_properties=KeyProperties(exportable=True,
                                                                    key_type='RSA',
                                                                    key_size=2048,
                                                                    reuse_key=True,
                                                                    key_usage=[
                                                                        KeyUsageType.crl_sign,
                                                                        KeyUsageType.data_encipherment,
                                                                        KeyUsageType.digital_signature,
                                                                        KeyUsageType.key_agreement,
                                                                        KeyUsageType.key_cert_sign,
                                                                        KeyUsageType.key_encipherment
                                                                    ]),
                                       issuer_name="Self",
                                       lifetime_actions=lifetime_actions,
                                       content_type=SecretContentType.PKCS12,
                                       subject_name="CN=DefaultPolicy",
                                       validity_in_months=12)
        cert_bundle = await self._client.create_certificate(
            vault_base_url=self.vault_url,
            certificate_name=name,
            certificate_policy=policy._to_certificate_policy_bundle(),
            certificate_attributes=attributes,
            tags=tags,
            **kwargs
        )
        create_certificate_operation = CertificateOperation._from_certificate_operation_bundle(cert_bundle)

        command = partial(
            self.get_certificate_operation,
            name=name,
            **kwargs
        )

        get_certificate_command = partial(
            self.get_certificate_with_policy,
            name=name,
            **kwargs
        )

        create_certificate_polling = CreateCertificatePollerAsync(get_certificate_command=get_certificate_command)
        return async_poller(
            command,
            create_certificate_operation,
            None,
            create_certificate_polling
        )