From f8a58a6fbec75b2d7491d595fd20911025f52ca7 Mon Sep 17 00:00:00 2001 From: YalinLi0312 Date: Wed, 1 Sep 2021 13:23:49 -0700 Subject: [PATCH 1/8] Fix mypy errors in keyvault certificates --- .../azure/keyvault/certificates/_client.py | 12 +- .../azure/keyvault/certificates/_models.py | 246 +++++++++--------- .../azure/keyvault/certificates/_polling.py | 10 + .../keyvault/certificates/_shared/_polling.py | 4 +- .../keyvault/certificates/aio/_client.py | 8 +- .../azure-keyvault-certificates/mypy.ini | 7 + 6 files changed, 157 insertions(+), 130 deletions(-) create mode 100644 sdk/keyvault/azure-keyvault-certificates/mypy.ini diff --git a/sdk/keyvault/azure-keyvault-certificates/azure/keyvault/certificates/_client.py b/sdk/keyvault/azure-keyvault-certificates/azure/keyvault/certificates/_client.py index 0ba57e214bbb..bc741d035501 100644 --- a/sdk/keyvault/azure-keyvault-certificates/azure/keyvault/certificates/_client.py +++ b/sdk/keyvault/azure-keyvault-certificates/azure/keyvault/certificates/_client.py @@ -134,7 +134,7 @@ def begin_create_certificate(self, certificate_name, policy, **kwargs): create_certificate_polling = CreateCertificatePoller( get_certificate_command=get_certificate_command, interval=polling_interval ) - return LROPoller(command, create_certificate_operation, None, create_certificate_polling) + return LROPoller(command, create_certificate_operation, lambda *_: None, create_certificate_polling) @distributed_trace def get_certificate(self, certificate_name, **kwargs): @@ -668,13 +668,15 @@ def set_contacts(self, contacts, **kwargs): :caption: Create contacts :dedent: 8 """ - contacts = self._client.set_certificate_contacts( + new_contacts = self._client.set_certificate_contacts( vault_base_url=self.vault_url, contacts=self._models.Contacts(contact_list=[c._to_certificate_contacts_item() for c in contacts]), error_map=_error_map, **kwargs ) - return [CertificateContact._from_certificate_contacts_item(contact_item=item) for item in contacts.contact_list] + return [ + CertificateContact._from_certificate_contacts_item(contact_item=item) for item in new_contacts.contact_list + ] @distributed_trace def get_contacts(self, **kwargs): @@ -885,7 +887,7 @@ def create_issuer(self, issuer_name, provider, **kwargs): phone=contact.phone, ) for contact in admin_contacts - ] + ] # type: Optional[List[Any]] else: admin_details = None if organization_id or admin_details: @@ -946,7 +948,7 @@ def update_issuer(self, issuer_name, **kwargs): phone=contact.phone, ) for contact in admin_contacts - ] + ] # type: Optional[List[Any]] else: admin_details = None if organization_id or admin_details: diff --git a/sdk/keyvault/azure-keyvault-certificates/azure/keyvault/certificates/_models.py b/sdk/keyvault/azure-keyvault-certificates/azure/keyvault/certificates/_models.py index 3747fe89be14..fa93bb3920f0 100644 --- a/sdk/keyvault/azure-keyvault-certificates/azure/keyvault/certificates/_models.py +++ b/sdk/keyvault/azure-keyvault-certificates/azure/keyvault/certificates/_models.py @@ -60,26 +60,26 @@ def _from_admin_detail(cls, admin_detail): @property def email(self): - # type: () -> str - """:rtype: str""" + # type: () -> Optional[str] + """:rtype: optional[str]""" return self._email @property def first_name(self): - # type: () -> str - """:rtype: str""" + # type: () -> Optional[str] + """:rtype: optional[str]""" return self._first_name @property def last_name(self): - # type: () -> str - """:rtype: str""" + # type: () -> Optional[str] + """:rtype: optional[str]""" return self._last_name @property def phone(self): - # type: () -> str - """:rtype: str""" + # type: () -> Optional[str] + """:rtype: optional[str]""" return self._phone @@ -157,7 +157,7 @@ def __repr__(self): @classmethod def _from_certificate_item(cls, certificate_item): - # type: (models.CertificateItem) -> CertificateProperties + # type: (Union[models.CertificateItem, models.CertificateBundle]) -> CertificateProperties """Construct a CertificateProperties from an autorest-generated CertificateItem""" return cls( attributes=certificate_item.attributes, @@ -279,10 +279,10 @@ def tags(self): @property def version(self): - # type: () -> str + # type: () -> Optional[str] """The version of the certificate - :rtype: str + :rtype: optional[str] """ return self._vault_id.version @@ -336,28 +336,28 @@ def _from_certificate_bundle(cls, certificate_bundle): @property def id(self): - # type: () -> str + # type: () -> Optional[str] """Certificate identifier. - :rtype: str + :rtype: optional[str] """ - return self._properties.id + return self._properties.id if self._properties else None @property def name(self): - # type: () -> str + # type: () -> Optional[str] """The name of the certificate. - :rtype: str + :rtype: optional[str] """ - return self._properties.name + return self._properties.name if self._properties else None @property def properties(self): - # type: () -> CertificateProperties + # type: () -> Optional[CertificateProperties] """The certificate's properties - :rtype: ~azure.keyvault.certificates.CertificateProperties + :rtype: optional[~azure.keyvault.certificates.CertificateProperties] """ return self._properties @@ -369,25 +369,25 @@ def key_id(self): @property def secret_id(self): - # type: () -> str - """:rtype: str""" + # type: () -> Optional[Any] + """:rtype: optional[Any]""" return self._secret_id @property def policy(self): - # type: () -> CertificatePolicy + # type: () -> Optional[CertificatePolicy] """The management policy of the certificate. - :rtype: ~azure.keyvault.certificates.CertificatePolicy + :rtype: optional[~azure.keyvault.certificates.CertificatePolicy] """ return self._policy @property def cer(self): - # type: () -> bytes + # type: () -> Optional[bytes] """The CER contents of the certificate. - :rtype: bytes + :rtype: optional[bytes] """ return self._cer @@ -469,7 +469,7 @@ def __init__( ): # type: (...) -> None self._id = cert_operation_id - self._vault_id = parse_key_vault_id(cert_operation_id) + self._vault_id = parse_key_vault_id(cert_operation_id) if cert_operation_id else None self._issuer_name = issuer_name self._certificate_type = certificate_type self._certificate_transparency = certificate_transparency @@ -493,7 +493,7 @@ def _from_certificate_operation_bundle(cls, certificate_operation_bundle): issuer_parameters = certificate_operation_bundle.issuer_parameters return cls( cert_operation_id=certificate_operation_bundle.id, - issuer_name=issuer_parameters.name, + issuer_name=issuer_parameters.name if issuer_parameters else None, certificate_type=( certificate_operation_bundle.issuer_parameters.certificate_type if certificate_operation_bundle.issuer_parameters @@ -513,104 +513,104 @@ def _from_certificate_operation_bundle(cls, certificate_operation_bundle): @property def id(self): - # type: () -> str - """:rtype: str""" + # type: () -> Optional[str] + """:rtype: optional[str]""" return self._id @property def name(self): - # type: () -> str - """:rtype: str""" - return self._vault_id.name + # type: () -> Optional[str] + """:rtype: optional[str]""" + return self._vault_id.name if self._vault_id else None @property def vault_url(self): - # type: () -> str + # type: () -> Optional[str] """URL of the vault containing the CertificateOperation - :rtype: str + :rtype: optional[str] """ - return self._vault_id.vault_url + return self._vault_id.vault_url if self._vault_id else None @property def issuer_name(self): - # type: () -> str + # type: () -> Union[str, WellKnownIssuerNames, None] """The name of the issuer of the certificate. - :rtype: str + :rtype: union[str, WellKnownIssuerNames, None] """ return self._issuer_name @property def certificate_type(self): - # type: () -> str + # type: () -> Optional[str] """Type of certificate to be requested from the issuer provider. - :rtype: str + :rtype: optional[str] """ return self._certificate_type @property def certificate_transparency(self): - # type: () -> bool + # type: () -> Optional[bool] """Whether certificates generated under this policy should be published to certificate transparency logs. - :rtype: bool + :rtype: optional[bool] """ return self._certificate_transparency @property def csr(self): - # type: () -> bytes + # type: () -> Optional[bytes] """The certificate signing request that is being used in this certificate operation. - :rtype: bytes + :rtype: optional[bytes] """ return self._csr @property def cancellation_requested(self): - # type: () -> bool + # type: () -> Optional[bool] """Whether cancellation was requested on the certificate operation. - :rtype: bool + :rtype: optional[bool] """ return self._cancellation_requested @property def status(self): - # type: () -> str - """:rtype: str""" + # type: () -> Optional[str] + """:rtype: optional[str]""" return self._status @property def status_details(self): - # type: () -> str - """:rtype: str""" + # type: () -> Optional[str] + """:rtype: optional[str]""" return self._status_details @property def error(self): - # type: () -> CertificateOperationError - """:rtype: ~azure.keyvault.certificates.CertificateOperationError""" + # type: () -> Optional[CertificateOperationError] + """:rtype: optional[~azure.keyvault.certificates.CertificateOperationError]""" return self._error @property def target(self): - # type: () -> str + # type: () -> Optional[str] """Location which contains the result of the certificate operation. - :rtype: str + :rtype: optional[str] """ return self._target @property def request_id(self): - # type: () -> str + # type: () -> Optional[str] """Identifier for the certificate operation. - :rtype: str + :rtype: optional[str] """ return self._request_id @@ -701,7 +701,7 @@ def _to_certificate_policy_bundle(self): name=self.issuer_name, certificate_type=self.certificate_type, certificate_transparency=self.certificate_transparency, # 2016-10-01 model will ignore this - ) + ) # type: Optional[models.IssuerParameters] else: issuer_parameters = None @@ -732,7 +732,7 @@ def _to_certificate_policy_bundle(self): ) ) else: - lifetime_actions = None + lifetime_actions = None # type: ignore # pylint:disable=too-many-boolean-expressions if ( @@ -745,7 +745,9 @@ def _to_certificate_policy_bundle(self): or self.validity_in_months ): if self.key_usage: - key_usage = [k.value if not isinstance(k, str) else k for k in self.key_usage] + key_usage = [ + k.value if not isinstance(k, str) else k for k in self.key_usage + ] # type: Optional[List[Union[str, KeyUsageType]]] else: key_usage = None @@ -757,7 +759,7 @@ def _to_certificate_policy_bundle(self): ), key_usage=key_usage, validity_in_months=self.validity_in_months, - ) + ) # type: Optional[models.X509CertificateProperties] else: x509_certificate_properties = None @@ -768,12 +770,13 @@ def _to_certificate_policy_bundle(self): key_size=self.key_size, reuse_key=self.reuse_key, curve=self.key_curve_name, - ) + ) # type: Optional[models.KeyProperties] else: key_properties = None if self.content_type: - secret_properties = models.SecretProperties(content_type=self.content_type) + secret_properties = models.SecretProperties( + content_type=self.content_type) # type: Optional[models.SecretProperties] else: secret_properties = None @@ -789,34 +792,38 @@ def _to_certificate_policy_bundle(self): @classmethod def _from_certificate_policy_bundle(cls, certificate_policy_bundle): - # type: (models.CertificatePolicy) -> CertificatePolicy + # type: (Optional[models.CertificatePolicy]) -> CertificatePolicy """Construct a CertificatePolicy from an autorest-generated CertificatePolicy""" - if certificate_policy_bundle.lifetime_actions: + if certificate_policy_bundle and certificate_policy_bundle.lifetime_actions: lifetime_actions = [ LifetimeAction( - action=(CertificatePolicyAction(item.action.action_type) if item.action.action_type else None), - lifetime_percentage=item.trigger.lifetime_percentage, - days_before_expiry=item.trigger.days_before_expiry, + action=CertificatePolicyAction(item.action.action_type) if item.action else None, + lifetime_percentage=item.trigger.lifetime_percentage if item.trigger else None, + days_before_expiry=item.trigger.days_before_expiry if item.trigger else None, ) for item in certificate_policy_bundle.lifetime_actions - ] + ] # type: Optional[List[LifetimeAction]] else: lifetime_actions = None - x509_certificate_properties = certificate_policy_bundle.x509_certificate_properties + x509_certificate_properties = ( + certificate_policy_bundle.x509_certificate_properties if certificate_policy_bundle else None + ) if x509_certificate_properties and x509_certificate_properties.key_usage: - key_usage = [KeyUsageType(k) for k in x509_certificate_properties.key_usage] + key_usage = [ + KeyUsageType(k) for k in x509_certificate_properties.key_usage + ] # type: Optional[List[KeyUsageType]] else: key_usage = None - key_properties = certificate_policy_bundle.key_properties + key_properties = certificate_policy_bundle.key_properties if certificate_policy_bundle else None curve_name = getattr(key_properties, "curve", None) # missing from 2016-10-01 KeyProperties if curve_name: curve_name = KeyCurveName(curve_name) - issuer_parameters = certificate_policy_bundle.issuer_parameters + issuer_parameters = certificate_policy_bundle.issuer_parameters if certificate_policy_bundle else None return cls( - issuer_name=issuer_parameters.name, + issuer_name=issuer_parameters.name if issuer_parameters else None, subject=(x509_certificate_properties.subject if x509_certificate_properties else None), - certificate_type=issuer_parameters.certificate_type, + certificate_type=issuer_parameters.certificate_type if issuer_parameters else None, # 2016-10-01 IssuerParameters doesn't have certificate_transparency certificate_transparency=getattr(issuer_parameters, "certificate_transparency", None), lifetime_actions=lifetime_actions, @@ -829,11 +836,12 @@ def _from_certificate_policy_bundle(cls, certificate_policy_bundle): key_usage=key_usage, content_type=( CertificateContentType(certificate_policy_bundle.secret_properties.content_type) - if certificate_policy_bundle.secret_properties and + if certificate_policy_bundle and + certificate_policy_bundle.secret_properties and certificate_policy_bundle.secret_properties.content_type else None ), - attributes=certificate_policy_bundle.attributes, + attributes=certificate_policy_bundle.attributes if certificate_policy_bundle else None, san_emails=( x509_certificate_properties.subject_alternative_names.emails if x509_certificate_properties and x509_certificate_properties.subject_alternative_names @@ -937,28 +945,28 @@ def subject(self): @property def san_emails(self): - # type: () -> List[str] + # type: () -> Optional[Any] """The subject alternative email addresses. - :rtype: list[str] + :rtype: optional[Any] """ return self._san_emails @property def san_dns_names(self): - # type: () -> List[str] + # type: () -> Optional[Any] """The subject alternative domain names. - :rtype: list[str] + :rtype: optional[Any] """ return self._san_dns_names @property def san_user_principal_names(self): - # type: () -> List[str] + # type: () -> Optional[Any] """The subject alternative user principal names. - :rtype: list[str] + :rtype: optional[Any] """ return self._san_user_principal_names @@ -1068,20 +1076,20 @@ def _from_certificate_contacts_item(cls, contact_item): @property def email(self): - # type: () -> str - """:rtype: str""" + # type: () -> Optional[str] + """:rtype: optional[str]""" return self._email @property def name(self): - # type: () -> str - """:rtype: str""" + # type: () -> Optional[str] + """:rtype: optional[str]""" return self._name @property def phone(self): - # type: () -> str - """:rtype: str""" + # type: () -> Optional[str] + """:rtype: optional[str]""" return self._phone @@ -1103,7 +1111,7 @@ def __repr__(self): @classmethod def _from_issuer_item(cls, issuer_item): - # type: (models.CertificateIssuerItem) -> IssuerProperties + # type: (Union[models.CertificateIssuerItem, models.IssuerBundle]) -> IssuerProperties """Construct a IssuerProperties from an autorest-generated CertificateIssuerItem""" return cls(issuer_id=issuer_item.id, provider=issuer_item.provider) @@ -1115,15 +1123,15 @@ def id(self): @property def name(self): - # type: () -> str + # type: () -> Optional[str] # Issuer name is listed under version under vault_id - """:rtype: str""" + """:rtype: optional[str]""" return self._vault_id.version @property def provider(self): - # type: () -> str - """:rtype: str""" + # type: () -> Optional[str] + """:rtype: optional[str]""" return self._provider @@ -1140,7 +1148,7 @@ class CertificateIssuer(object): def __init__( self, - provider, # type: str + provider, # type: Optional[str] attributes=None, # type: Optional[models.IssuerAttributes] account_id=None, # type: Optional[str] password=None, # type: Optional[str] @@ -1192,80 +1200,80 @@ def id(self): @property def name(self): - # type: () -> str + # type: () -> Optional[str] # Issuer name is listed under version under vault_id. # This is because the id we pass to parse_key_vault_id has an extra segment, so where most cases the version of # the general pattern is certificates/name/version, but here we have certificates/issuers/name/version. # Issuers are not versioned. - """:rtype: str""" + """:rtype: optional[str]""" return self._vault_id.version @property def provider(self): - # type: () -> str + # type: () -> Optional[str] """The issuer provider. - :rtype: str + :rtype: optional[str] """ return self._provider @property def enabled(self): - # type: () -> bool + # type: () -> Optional[bool] """Whether the certificate is enabled or not. - :rtype: bool + :rtype: optional[bool] """ return self._attributes.enabled if self._attributes else None @property def created_on(self): - # type: () -> datetime + # type: () -> Optional[datetime] """The datetime when the certificate is created. - :rtype: ~datetime.datetime + :rtype: optional[~datetime.datetime] """ return self._attributes.created if self._attributes else None @property def updated_on(self): - # type: () -> datetime + # type: () -> Optional[datetime] """The datetime when the certificate was last updated. - :rtype: ~datetime.datetime + :rtype: optional[~datetime.datetime] """ return self._attributes.updated if self._attributes else None @property def account_id(self): - # type: () -> str + # type: () -> Optional[str] """The username/ account name/ account id. - :rtype: str + :rtype: optional[str] """ return self._account_id @property def password(self): - # type: () -> str + # type: () -> Optional[str] """The password / secret / account key. - :rtype: str + :rtype: optional[str] """ return self._password @property def organization_id(self): - # type: () -> str - """:rtype: str""" + # type: () -> Optional[str] + """:rtype: optional[str]""" return self._organization_id @property def admin_contacts(self): - # type: () -> List[AdministratorContact] + # type: () -> Optional[List[AdministratorContact]] """Contact details of the organization administrator of this issuer. - :rtype: list[~azure.keyvault.certificates.AdministratorContact] + :rtype: optional[list[~azure.keyvault.certificates.AdministratorContact]] """ return self._admin_contacts @@ -1283,8 +1291,8 @@ class LifetimeAction(object): should be between 1 and 972 (36 * 27). """ - def __init__(self, action, lifetime_percentage=None, days_before_expiry=None): - # type: (CertificatePolicyAction, Optional[int], Optional[int]) -> None + def __init__(self, action=None, lifetime_percentage=None, days_before_expiry=None): + # type: (Optional[CertificatePolicyAction], Optional[int], Optional[int]) -> None self._lifetime_percentage = lifetime_percentage self._days_before_expiry = days_before_expiry self._action = action @@ -1297,29 +1305,29 @@ def __repr__(self): @property def lifetime_percentage(self): - # type: () -> int + # type: () -> Optional[int] """Percentage of lifetime at which to trigger. - :rtype: int + :rtype: optional[int] """ return self._lifetime_percentage @property def days_before_expiry(self): - # type: () -> int + # type: () -> Optional[int] """Days before expiry to attempt renewal. - :rtype: int + :rtype: optional[int] """ return self._days_before_expiry @property def action(self): - # type: () -> CertificatePolicyAction + # type: () -> Optional[CertificatePolicyAction] """The type of the action that will be executed. Valid values are "EmailContacts" and "AutoRenew" - :rtype: ~azure.keyvault.certificates.CertificatePolicyAction + :rtype: optional[~azure.keyvault.certificates.CertificatePolicyAction] """ return self._action diff --git a/sdk/keyvault/azure-keyvault-certificates/azure/keyvault/certificates/_polling.py b/sdk/keyvault/azure-keyvault-certificates/azure/keyvault/certificates/_polling.py index a846c356cac0..bf659c9456ef 100644 --- a/sdk/keyvault/azure-keyvault-certificates/azure/keyvault/certificates/_polling.py +++ b/sdk/keyvault/azure-keyvault-certificates/azure/keyvault/certificates/_polling.py @@ -6,6 +6,16 @@ import time from azure.core.polling import PollingMethod +from azure.keyvault.certificates import KeyVaultCertificate, CertificateOperation + +try: + from typing import TYPE_CHECKING +except ImportError: + TYPE_CHECKING = False + +if TYPE_CHECKING: + # pylint: disable=ungrouped-imports + from typing import Any, Callable, Union logger = logging.getLogger(__name__) diff --git a/sdk/keyvault/azure-keyvault-certificates/azure/keyvault/certificates/_shared/_polling.py b/sdk/keyvault/azure-keyvault-certificates/azure/keyvault/certificates/_shared/_polling.py index df63ad0a70ec..ec1898453d81 100644 --- a/sdk/keyvault/azure-keyvault-certificates/azure/keyvault/certificates/_shared/_polling.py +++ b/sdk/keyvault/azure-keyvault-certificates/azure/keyvault/certificates/_shared/_polling.py @@ -33,11 +33,11 @@ class KeyVaultOperationPoller(LROPoller): # pylint: disable=arguments-differ def __init__(self, polling_method): # type: (PollingMethod) -> None - super(KeyVaultOperationPoller, self).__init__(None, None, None, NoPolling()) + super(KeyVaultOperationPoller, self).__init__(None, None, lambda *_: None, NoPolling()) self._polling_method = polling_method # pylint: disable=arguments-differ - def result(self): + def result(self): # type: ignore # type: () -> Any """Returns a representation of the final resource without waiting for the operation to complete. diff --git a/sdk/keyvault/azure-keyvault-certificates/azure/keyvault/certificates/aio/_client.py b/sdk/keyvault/azure-keyvault-certificates/azure/keyvault/certificates/aio/_client.py index ebe294092d39..d4812d802010 100644 --- a/sdk/keyvault/azure-keyvault-certificates/azure/keyvault/certificates/aio/_client.py +++ b/sdk/keyvault/azure-keyvault-certificates/azure/keyvault/certificates/aio/_client.py @@ -638,13 +638,13 @@ async def set_contacts(self, contacts: Iterable[CertificateContact], **kwargs: " :caption: Create contacts :dedent: 8 """ - contacts = await self._client.set_certificate_contacts( + new_contacts = await self._client.set_certificate_contacts( vault_base_url=self.vault_url, contacts=self._models.Contacts(contact_list=[c._to_certificate_contacts_item() for c in contacts]), error_map=_error_map, **kwargs ) - return [CertificateContact._from_certificate_contacts_item(contact_item=item) for item in contacts.contact_list] + return [CertificateContact._from_certificate_contacts_item(contact_item=item) for item in new_contacts.contact_list] @distributed_trace_async async def get_contacts(self, **kwargs: "Any") -> List[CertificateContact]: @@ -861,7 +861,7 @@ async def create_issuer(self, issuer_name: str, provider: str, **kwargs: "Any") phone=contact.phone, ) for contact in admin_contacts - ] + ] # type: Optional[List[Any]] else: admin_details = None if organization_id or admin_details: @@ -922,7 +922,7 @@ async def update_issuer(self, issuer_name: str, **kwargs: "Any") -> CertificateI phone=contact.phone, ) for contact in admin_contacts - ) + ) # type: Optional[List[Any]] else: admin_details = None if organization_id or admin_details: diff --git a/sdk/keyvault/azure-keyvault-certificates/mypy.ini b/sdk/keyvault/azure-keyvault-certificates/mypy.ini new file mode 100644 index 000000000000..18b37b44c426 --- /dev/null +++ b/sdk/keyvault/azure-keyvault-certificates/mypy.ini @@ -0,0 +1,7 @@ +[mypy] +python_version = 3.6 +warn_unused_configs = True +ignore_missing_imports = True + +[mypy-azure.keyvault.*._generated.*] +ignore_errors = True From 9b0003fba4888a56a595c76a02ae2d66ae93d7d8 Mon Sep 17 00:00:00 2001 From: YalinLi0312 Date: Thu, 2 Sep 2021 16:19:45 -0700 Subject: [PATCH 2/8] Update mypy_hard_failure_package.py --- eng/tox/mypy_hard_failure_packages.py | 1 + 1 file changed, 1 insertion(+) diff --git a/eng/tox/mypy_hard_failure_packages.py b/eng/tox/mypy_hard_failure_packages.py index b85c70560081..7619732b13b4 100644 --- a/eng/tox/mypy_hard_failure_packages.py +++ b/eng/tox/mypy_hard_failure_packages.py @@ -10,6 +10,7 @@ "azure-eventhub", "azure-identity", "azure-keyvault-administration", + "azure-keyvault-certificates", "azure-servicebus", "azure-ai-textanalytics", "azure-ai-formrecognizer", From f7a1716ac478a351a50e840961a5f3fbdf688314 Mon Sep 17 00:00:00 2001 From: YalinLi0312 Date: Thu, 2 Sep 2021 19:25:03 -0700 Subject: [PATCH 3/8] Address comments --- .../azure/keyvault/certificates/_models.py | 88 +++++++++---------- .../azure/keyvault/certificates/_polling.py | 2 +- 2 files changed, 45 insertions(+), 45 deletions(-) diff --git a/sdk/keyvault/azure-keyvault-certificates/azure/keyvault/certificates/_models.py b/sdk/keyvault/azure-keyvault-certificates/azure/keyvault/certificates/_models.py index fa93bb3920f0..273eebf69cfa 100644 --- a/sdk/keyvault/azure-keyvault-certificates/azure/keyvault/certificates/_models.py +++ b/sdk/keyvault/azure-keyvault-certificates/azure/keyvault/certificates/_models.py @@ -61,25 +61,25 @@ def _from_admin_detail(cls, admin_detail): @property def email(self): # type: () -> Optional[str] - """:rtype: optional[str]""" + """:rtype: str or None""" return self._email @property def first_name(self): # type: () -> Optional[str] - """:rtype: optional[str]""" + """:rtype: str or None""" return self._first_name @property def last_name(self): # type: () -> Optional[str] - """:rtype: optional[str]""" + """:rtype: str or None""" return self._last_name @property def phone(self): # type: () -> Optional[str] - """:rtype: optional[str]""" + """:rtype: str or None""" return self._phone @@ -282,7 +282,7 @@ def version(self): # type: () -> Optional[str] """The version of the certificate - :rtype: optional[str] + :rtype: str or None """ return self._vault_id.version @@ -339,7 +339,7 @@ def id(self): # type: () -> Optional[str] """Certificate identifier. - :rtype: optional[str] + :rtype: str or None """ return self._properties.id if self._properties else None @@ -348,7 +348,7 @@ def name(self): # type: () -> Optional[str] """The name of the certificate. - :rtype: optional[str] + :rtype: str or None """ return self._properties.name if self._properties else None @@ -357,7 +357,7 @@ def properties(self): # type: () -> Optional[CertificateProperties] """The certificate's properties - :rtype: optional[~azure.keyvault.certificates.CertificateProperties] + :rtype: ~azure.keyvault.certificates.CertificateProperties or None """ return self._properties @@ -370,7 +370,7 @@ def key_id(self): @property def secret_id(self): # type: () -> Optional[Any] - """:rtype: optional[Any]""" + """:rtype: Any or None""" return self._secret_id @property @@ -378,7 +378,7 @@ def policy(self): # type: () -> Optional[CertificatePolicy] """The management policy of the certificate. - :rtype: optional[~azure.keyvault.certificates.CertificatePolicy] + :rtype: ~azure.keyvault.certificates.CertificatePolicy or None """ return self._policy @@ -387,7 +387,7 @@ def cer(self): # type: () -> Optional[bytes] """The CER contents of the certificate. - :rtype: optional[bytes] + :rtype: bytes or None """ return self._cer @@ -514,13 +514,13 @@ def _from_certificate_operation_bundle(cls, certificate_operation_bundle): @property def id(self): # type: () -> Optional[str] - """:rtype: optional[str]""" + """:rtype: str or None""" return self._id @property def name(self): # type: () -> Optional[str] - """:rtype: optional[str]""" + """:rtype: str or None""" return self._vault_id.name if self._vault_id else None @property @@ -528,7 +528,7 @@ def vault_url(self): # type: () -> Optional[str] """URL of the vault containing the CertificateOperation - :rtype: optional[str] + :rtype: str or None """ return self._vault_id.vault_url if self._vault_id else None @@ -537,7 +537,7 @@ def issuer_name(self): # type: () -> Union[str, WellKnownIssuerNames, None] """The name of the issuer of the certificate. - :rtype: union[str, WellKnownIssuerNames, None] + :rtype: str or WellKnownIssuerNames or None """ return self._issuer_name @@ -546,7 +546,7 @@ def certificate_type(self): # type: () -> Optional[str] """Type of certificate to be requested from the issuer provider. - :rtype: optional[str] + :rtype: str or None """ return self._certificate_type @@ -556,7 +556,7 @@ def certificate_transparency(self): """Whether certificates generated under this policy should be published to certificate transparency logs. - :rtype: optional[bool] + :rtype: bool or None """ return self._certificate_transparency @@ -565,7 +565,7 @@ def csr(self): # type: () -> Optional[bytes] """The certificate signing request that is being used in this certificate operation. - :rtype: optional[bytes] + :rtype: bytes or None """ return self._csr @@ -574,26 +574,26 @@ def cancellation_requested(self): # type: () -> Optional[bool] """Whether cancellation was requested on the certificate operation. - :rtype: optional[bool] + :rtype: bool or None """ return self._cancellation_requested @property def status(self): # type: () -> Optional[str] - """:rtype: optional[str]""" + """:rtype: str or None""" return self._status @property def status_details(self): # type: () -> Optional[str] - """:rtype: optional[str]""" + """:rtype: str or None""" return self._status_details @property def error(self): # type: () -> Optional[CertificateOperationError] - """:rtype: optional[~azure.keyvault.certificates.CertificateOperationError]""" + """:rtype: ~azure.keyvault.certificates.CertificateOperationError or None""" return self._error @property @@ -601,7 +601,7 @@ def target(self): # type: () -> Optional[str] """Location which contains the result of the certificate operation. - :rtype: optional[str] + :rtype: str or None """ return self._target @@ -610,7 +610,7 @@ def request_id(self): # type: () -> Optional[str] """Identifier for the certificate operation. - :rtype: optional[str] + :rtype: str or None """ return self._request_id @@ -948,7 +948,7 @@ def san_emails(self): # type: () -> Optional[Any] """The subject alternative email addresses. - :rtype: optional[Any] + :rtype: Any or None """ return self._san_emails @@ -957,7 +957,7 @@ def san_dns_names(self): # type: () -> Optional[Any] """The subject alternative domain names. - :rtype: optional[Any] + :rtype: Any or None """ return self._san_dns_names @@ -966,7 +966,7 @@ def san_user_principal_names(self): # type: () -> Optional[Any] """The subject alternative user principal names. - :rtype: optional[Any] + :rtype: Any or None """ return self._san_user_principal_names @@ -1077,19 +1077,19 @@ def _from_certificate_contacts_item(cls, contact_item): @property def email(self): # type: () -> Optional[str] - """:rtype: optional[str]""" + """:rtype: str or None""" return self._email @property def name(self): # type: () -> Optional[str] - """:rtype: optional[str]""" + """:rtype: str or None""" return self._name @property def phone(self): # type: () -> Optional[str] - """:rtype: optional[str]""" + """:rtype: str or None""" return self._phone @@ -1125,13 +1125,13 @@ def id(self): def name(self): # type: () -> Optional[str] # Issuer name is listed under version under vault_id - """:rtype: optional[str]""" + """:rtype: str or None""" return self._vault_id.version @property def provider(self): # type: () -> Optional[str] - """:rtype: optional[str]""" + """:rtype: str or None""" return self._provider @@ -1205,7 +1205,7 @@ def name(self): # This is because the id we pass to parse_key_vault_id has an extra segment, so where most cases the version of # the general pattern is certificates/name/version, but here we have certificates/issuers/name/version. # Issuers are not versioned. - """:rtype: optional[str]""" + """:rtype: str or None""" return self._vault_id.version @property @@ -1213,7 +1213,7 @@ def provider(self): # type: () -> Optional[str] """The issuer provider. - :rtype: optional[str] + :rtype: str or None """ return self._provider @@ -1222,7 +1222,7 @@ def enabled(self): # type: () -> Optional[bool] """Whether the certificate is enabled or not. - :rtype: optional[bool] + :rtype: bool or None """ return self._attributes.enabled if self._attributes else None @@ -1231,7 +1231,7 @@ def created_on(self): # type: () -> Optional[datetime] """The datetime when the certificate is created. - :rtype: optional[~datetime.datetime] + :rtype: ~datetime.datetime or None """ return self._attributes.created if self._attributes else None @@ -1240,7 +1240,7 @@ def updated_on(self): # type: () -> Optional[datetime] """The datetime when the certificate was last updated. - :rtype: optional[~datetime.datetime] + :rtype: ~datetime.datetime or None """ return self._attributes.updated if self._attributes else None @@ -1249,7 +1249,7 @@ def account_id(self): # type: () -> Optional[str] """The username/ account name/ account id. - :rtype: optional[str] + :rtype: str or None """ return self._account_id @@ -1258,14 +1258,14 @@ def password(self): # type: () -> Optional[str] """The password / secret / account key. - :rtype: optional[str] + :rtype: str or None """ return self._password @property def organization_id(self): # type: () -> Optional[str] - """:rtype: optional[str]""" + """:rtype: str or None""" return self._organization_id @property @@ -1273,7 +1273,7 @@ def admin_contacts(self): # type: () -> Optional[List[AdministratorContact]] """Contact details of the organization administrator of this issuer. - :rtype: optional[list[~azure.keyvault.certificates.AdministratorContact]] + :rtype: list[~azure.keyvault.certificates.AdministratorContact] or None """ return self._admin_contacts @@ -1308,7 +1308,7 @@ def lifetime_percentage(self): # type: () -> Optional[int] """Percentage of lifetime at which to trigger. - :rtype: optional[int] + :rtype: int or None """ return self._lifetime_percentage @@ -1317,7 +1317,7 @@ def days_before_expiry(self): # type: () -> Optional[int] """Days before expiry to attempt renewal. - :rtype: optional[int] + :rtype: int or None """ return self._days_before_expiry @@ -1327,7 +1327,7 @@ def action(self): """The type of the action that will be executed. Valid values are "EmailContacts" and "AutoRenew" - :rtype: optional[~azure.keyvault.certificates.CertificatePolicyAction] + :rtype: ~azure.keyvault.certificates.CertificatePolicyAction or None """ return self._action diff --git a/sdk/keyvault/azure-keyvault-certificates/azure/keyvault/certificates/_polling.py b/sdk/keyvault/azure-keyvault-certificates/azure/keyvault/certificates/_polling.py index bf659c9456ef..1a0946d20a54 100644 --- a/sdk/keyvault/azure-keyvault-certificates/azure/keyvault/certificates/_polling.py +++ b/sdk/keyvault/azure-keyvault-certificates/azure/keyvault/certificates/_polling.py @@ -6,7 +6,6 @@ import time from azure.core.polling import PollingMethod -from azure.keyvault.certificates import KeyVaultCertificate, CertificateOperation try: from typing import TYPE_CHECKING @@ -16,6 +15,7 @@ if TYPE_CHECKING: # pylint: disable=ungrouped-imports from typing import Any, Callable, Union + from azure.keyvault.certificates import KeyVaultCertificate, CertificateOperation logger = logging.getLogger(__name__) From 813d86a4e38835584d0b4480a89a3cebf81e8084 Mon Sep 17 00:00:00 2001 From: YalinLi0312 Date: Thu, 2 Sep 2021 19:34:50 -0700 Subject: [PATCH 4/8] Fix lint errors --- .../azure/keyvault/certificates/aio/_client.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/sdk/keyvault/azure-keyvault-certificates/azure/keyvault/certificates/aio/_client.py b/sdk/keyvault/azure-keyvault-certificates/azure/keyvault/certificates/aio/_client.py index d4812d802010..1fe6569bfe0f 100644 --- a/sdk/keyvault/azure-keyvault-certificates/azure/keyvault/certificates/aio/_client.py +++ b/sdk/keyvault/azure-keyvault-certificates/azure/keyvault/certificates/aio/_client.py @@ -644,7 +644,9 @@ async def set_contacts(self, contacts: Iterable[CertificateContact], **kwargs: " error_map=_error_map, **kwargs ) - return [CertificateContact._from_certificate_contacts_item(contact_item=item) for item in new_contacts.contact_list] + return [ + CertificateContact._from_certificate_contacts_item(contact_item=item) for item in new_contacts.contact_list + ] @distributed_trace_async async def get_contacts(self, **kwargs: "Any") -> List[CertificateContact]: From a03a2be510e0b921ed926b2c3d0c5fad994fa784 Mon Sep 17 00:00:00 2001 From: YalinLi0312 Date: Thu, 2 Sep 2021 19:34:50 -0700 Subject: [PATCH 5/8] WIP --- .../azure/keyvault/certificates/_models.py | 7 ++++--- .../azure/keyvault/certificates/aio/_client.py | 4 +++- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/sdk/keyvault/azure-keyvault-certificates/azure/keyvault/certificates/_models.py b/sdk/keyvault/azure-keyvault-certificates/azure/keyvault/certificates/_models.py index 273eebf69cfa..1bc6a9cb466e 100644 --- a/sdk/keyvault/azure-keyvault-certificates/azure/keyvault/certificates/_models.py +++ b/sdk/keyvault/azure-keyvault-certificates/azure/keyvault/certificates/_models.py @@ -369,7 +369,7 @@ def key_id(self): @property def secret_id(self): - # type: () -> Optional[Any] + # type: () -> Optional[str] """:rtype: Any or None""" return self._secret_id @@ -537,7 +537,7 @@ def issuer_name(self): # type: () -> Union[str, WellKnownIssuerNames, None] """The name of the issuer of the certificate. - :rtype: str or WellKnownIssuerNames or None + :rtype: str or ~azure.keyvault.certificates.WellKnownIssuerNames or None """ return self._issuer_name @@ -776,7 +776,8 @@ def _to_certificate_policy_bundle(self): if self.content_type: secret_properties = models.SecretProperties( - content_type=self.content_type) # type: Optional[models.SecretProperties] + content_type=self.content_type + ) # type: Optional[models.SecretProperties] else: secret_properties = None diff --git a/sdk/keyvault/azure-keyvault-certificates/azure/keyvault/certificates/aio/_client.py b/sdk/keyvault/azure-keyvault-certificates/azure/keyvault/certificates/aio/_client.py index d4812d802010..1fe6569bfe0f 100644 --- a/sdk/keyvault/azure-keyvault-certificates/azure/keyvault/certificates/aio/_client.py +++ b/sdk/keyvault/azure-keyvault-certificates/azure/keyvault/certificates/aio/_client.py @@ -644,7 +644,9 @@ async def set_contacts(self, contacts: Iterable[CertificateContact], **kwargs: " error_map=_error_map, **kwargs ) - return [CertificateContact._from_certificate_contacts_item(contact_item=item) for item in new_contacts.contact_list] + return [ + CertificateContact._from_certificate_contacts_item(contact_item=item) for item in new_contacts.contact_list + ] @distributed_trace_async async def get_contacts(self, **kwargs: "Any") -> List[CertificateContact]: From 3e5eb12136ea31fea9156c065f441c9769c259cf Mon Sep 17 00:00:00 2001 From: YalinLi0312 Date: Fri, 3 Sep 2021 17:28:47 -0700 Subject: [PATCH 6/8] Address comments --- .../azure/keyvault/certificates/_models.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/sdk/keyvault/azure-keyvault-certificates/azure/keyvault/certificates/_models.py b/sdk/keyvault/azure-keyvault-certificates/azure/keyvault/certificates/_models.py index 1bc6a9cb466e..86a6dbbdd516 100644 --- a/sdk/keyvault/azure-keyvault-certificates/azure/keyvault/certificates/_models.py +++ b/sdk/keyvault/azure-keyvault-certificates/azure/keyvault/certificates/_models.py @@ -795,7 +795,10 @@ def _to_certificate_policy_bundle(self): def _from_certificate_policy_bundle(cls, certificate_policy_bundle): # type: (Optional[models.CertificatePolicy]) -> CertificatePolicy """Construct a CertificatePolicy from an autorest-generated CertificatePolicy""" - if certificate_policy_bundle and certificate_policy_bundle.lifetime_actions: + if certificate_policy_bundle is None: + return cls() + + if certificate_policy_bundle.lifetime_actions: lifetime_actions = [ LifetimeAction( action=CertificatePolicyAction(item.action.action_type) if item.action else None, @@ -806,21 +809,19 @@ def _from_certificate_policy_bundle(cls, certificate_policy_bundle): ] # type: Optional[List[LifetimeAction]] else: lifetime_actions = None - x509_certificate_properties = ( - certificate_policy_bundle.x509_certificate_properties if certificate_policy_bundle else None - ) + x509_certificate_properties = certificate_policy_bundle.x509_certificate_properties if x509_certificate_properties and x509_certificate_properties.key_usage: key_usage = [ KeyUsageType(k) for k in x509_certificate_properties.key_usage ] # type: Optional[List[KeyUsageType]] else: key_usage = None - key_properties = certificate_policy_bundle.key_properties if certificate_policy_bundle else None + key_properties = certificate_policy_bundle.key_properties curve_name = getattr(key_properties, "curve", None) # missing from 2016-10-01 KeyProperties if curve_name: curve_name = KeyCurveName(curve_name) - issuer_parameters = certificate_policy_bundle.issuer_parameters if certificate_policy_bundle else None + issuer_parameters = certificate_policy_bundle.issuer_parameters return cls( issuer_name=issuer_parameters.name if issuer_parameters else None, subject=(x509_certificate_properties.subject if x509_certificate_properties else None), @@ -837,12 +838,11 @@ def _from_certificate_policy_bundle(cls, certificate_policy_bundle): key_usage=key_usage, content_type=( CertificateContentType(certificate_policy_bundle.secret_properties.content_type) - if certificate_policy_bundle and - certificate_policy_bundle.secret_properties and + if certificate_policy_bundle.secret_properties and certificate_policy_bundle.secret_properties.content_type else None ), - attributes=certificate_policy_bundle.attributes if certificate_policy_bundle else None, + attributes=certificate_policy_bundle.attributes, san_emails=( x509_certificate_properties.subject_alternative_names.emails if x509_certificate_properties and x509_certificate_properties.subject_alternative_names From 09b88b72bcba19aa206a2bb633c8f18daf69ef9b Mon Sep 17 00:00:00 2001 From: YalinLi0312 Date: Fri, 3 Sep 2021 17:33:21 -0700 Subject: [PATCH 7/8] Fix a lint error --- .../azure/keyvault/certificates/_models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/keyvault/azure-keyvault-certificates/azure/keyvault/certificates/_models.py b/sdk/keyvault/azure-keyvault-certificates/azure/keyvault/certificates/_models.py index 86a6dbbdd516..21c61d83cd92 100644 --- a/sdk/keyvault/azure-keyvault-certificates/azure/keyvault/certificates/_models.py +++ b/sdk/keyvault/azure-keyvault-certificates/azure/keyvault/certificates/_models.py @@ -777,7 +777,7 @@ def _to_certificate_policy_bundle(self): if self.content_type: secret_properties = models.SecretProperties( content_type=self.content_type - ) # type: Optional[models.SecretProperties] + ) # type: Optional[models.SecretProperties] else: secret_properties = None From 5770eba333919718f798e3d0bf5f99e4875b4ce9 Mon Sep 17 00:00:00 2001 From: YalinLi0312 Date: Tue, 7 Sep 2021 17:30:38 -0700 Subject: [PATCH 8/8] Address comments --- .../azure/keyvault/certificates/_models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/keyvault/azure-keyvault-certificates/azure/keyvault/certificates/_models.py b/sdk/keyvault/azure-keyvault-certificates/azure/keyvault/certificates/_models.py index 21c61d83cd92..2f5df7b122ce 100644 --- a/sdk/keyvault/azure-keyvault-certificates/azure/keyvault/certificates/_models.py +++ b/sdk/keyvault/azure-keyvault-certificates/azure/keyvault/certificates/_models.py @@ -1292,7 +1292,7 @@ class LifetimeAction(object): should be between 1 and 972 (36 * 27). """ - def __init__(self, action=None, lifetime_percentage=None, days_before_expiry=None): + def __init__(self, action, lifetime_percentage=None, days_before_expiry=None): # type: (Optional[CertificatePolicyAction], Optional[int], Optional[int]) -> None self._lifetime_percentage = lifetime_percentage self._days_before_expiry = days_before_expiry