Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Key Vault] Linting updates for pylint 3.2.5 #37241

Merged
merged 6 commits into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
# ------------------------------------
# pylint:disable=missing-docstring
__path__ = __import__("pkgutil").extend_path(__path__, __name__) # type: ignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
# ------------------------------------
# pylint:disable=missing-docstring
__path__ = __import__("pkgutil").extend_path(__path__, __name__) # type: ignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# pylint:disable=too-many-lines,too-many-public-methods,bad-option-value,delete-operation-wrong-return-type
import base64
from functools import partial
from typing import Any, List, Optional, Union
from typing import Any, Dict, List, Optional, Union

from azure.core.polling import LROPoller
from azure.core.paging import ItemPaged
Expand All @@ -14,6 +14,7 @@
from ._shared import KeyVaultClientBase
from ._shared._polling import DeleteRecoverPollingMethod, KeyVaultOperationPoller
from ._models import (
AdministratorContact,
KeyVaultCertificate,
CertificateProperties,
CertificatePolicy,
Expand Down Expand Up @@ -57,7 +58,13 @@ class CertificateClient(KeyVaultClientBase):

@distributed_trace
def begin_create_certificate(
self, certificate_name: str, policy: CertificatePolicy, **kwargs: Any
self,
certificate_name: str,
policy: CertificatePolicy,
*,
enabled: Optional[bool] = None,
tags: Optional[Dict[str, str]] = None,
**kwargs: Any,
) -> LROPoller[Union[KeyVaultCertificate, CertificateOperation]]:
"""Creates a new certificate.

Expand Down Expand Up @@ -97,7 +104,6 @@ def begin_create_certificate(
polling_interval = kwargs.pop("_polling_interval", None)
if polling_interval is None:
polling_interval = 5
enabled = kwargs.pop("enabled", None)

if enabled is not None:
attributes = self._models.CertificateAttributes(enabled=enabled)
Expand All @@ -107,7 +113,7 @@ def begin_create_certificate(
parameters = self._models.CertificateCreateParameters(
certificate_policy=policy._to_certificate_policy_bundle(),
certificate_attributes=attributes,
tags=kwargs.pop("tags", None),
tags=tags
)

pipeline_response, cert_bundle = self._client.create_certificate(
Expand Down Expand Up @@ -341,7 +347,17 @@ def begin_recover_deleted_certificate(self, certificate_name: str, **kwargs: Any
return KeyVaultOperationPoller(polling_method)

@distributed_trace
def import_certificate(self, certificate_name: str, certificate_bytes: bytes, **kwargs: Any) -> KeyVaultCertificate:
def import_certificate(
self,
certificate_name: str,
certificate_bytes: bytes,
*,
enabled: Optional[bool] = None,
tags: Optional[Dict[str, str]] = None,
password: Optional[str] = None,
policy: Optional[CertificatePolicy] = None,
**kwargs: Any,
) -> KeyVaultCertificate:
"""Import a certificate created externally. Requires certificates/import permission.

Imports an existing valid certificate, containing a private key, into Azure Key Vault. The certificate to be
Expand Down Expand Up @@ -370,9 +386,6 @@ def import_certificate(self, certificate_name: str, certificate_bytes: bytes, **
:raises ~azure.core.exceptions.HttpResponseError:
"""

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

if enabled is not None:
attributes = self._models.CertificateAttributes(enabled=enabled)
else:
Expand All @@ -381,10 +394,10 @@ def import_certificate(self, certificate_name: str, certificate_bytes: bytes, **

parameters = self._models.CertificateImportParameters(
base64_encoded_certificate=base64_encoded_certificate,
password=kwargs.pop("password", None),
password=password,
certificate_policy=policy._to_certificate_policy_bundle() if policy else None,
certificate_attributes=attributes,
tags=kwargs.pop("tags", None),
tags=tags,
)

bundle = self._client.import_certificate(
Expand Down Expand Up @@ -437,7 +450,13 @@ def update_certificate_policy(

@distributed_trace
def update_certificate_properties(
self, certificate_name: str, version: "Optional[str]" = None, **kwargs: Any
self,
certificate_name: str,
version: Optional[str] = None,
*,
enabled: Optional[bool] = None,
tags: Optional[Dict[str, str]] = None,
**kwargs: Any,
) -> KeyVaultCertificate:
"""Change a certificate's properties. Requires certificates/update permission.

Expand All @@ -462,15 +481,13 @@ def update_certificate_properties(
:dedent: 8
"""

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

if enabled is not None:
attributes = self._models.CertificateAttributes(enabled=enabled)
else:
attributes = None

parameters = self._models.CertificateUpdateParameters(
certificate_attributes=attributes, tags=kwargs.pop("tags", None)
certificate_attributes=attributes, tags=tags
)

bundle = self._client.update_certificate(
Expand Down Expand Up @@ -789,7 +806,13 @@ def cancel_certificate_operation(self, certificate_name: str, **kwargs: Any) ->

@distributed_trace
def merge_certificate(
self, certificate_name: str, x509_certificates: "List[bytes]", **kwargs: Any
self,
certificate_name: str,
x509_certificates: List[bytes],
*,
enabled: Optional[bool] = None,
tags: Optional[Dict[str, str]] = None,
**kwargs: Any,
) -> KeyVaultCertificate:
"""Merges a certificate or a certificate chain with a key pair existing on the server.

Expand All @@ -813,15 +836,13 @@ def merge_certificate(
:raises ~azure.core.exceptions.HttpResponseError:
"""

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

if enabled is not None:
attributes = self._models.CertificateAttributes(enabled=enabled)
else:
attributes = None

parameters = self._models.CertificateMergeParameters(
x509_certificates=x509_certificates, certificate_attributes=attributes, tags=kwargs.pop("tags", None)
x509_certificates=x509_certificates, certificate_attributes=attributes, tags=tags
)

bundle = self._client.merge_certificate(
Expand Down Expand Up @@ -855,7 +876,18 @@ def get_issuer(self, issuer_name: str, **kwargs: Any) -> CertificateIssuer:
return CertificateIssuer._from_issuer_bundle(issuer_bundle=issuer_bundle)

@distributed_trace
def create_issuer(self, issuer_name: str, provider: str, **kwargs: Any) -> CertificateIssuer:
def create_issuer(
self,
issuer_name: str,
provider: str,
*,
enabled: Optional[bool] = None,
account_id: Optional[str] = None,
password: Optional[str] = None,
organization_id: Optional[str] = None,
admin_contacts: Optional[List[AdministratorContact]] = None,
**kwargs: Any,
) -> CertificateIssuer:
"""Sets the specified certificate issuer. Requires certificates/setissuers permission.

:param str issuer_name: The name of the issuer.
Expand Down Expand Up @@ -883,12 +915,6 @@ def create_issuer(self, issuer_name: str, provider: str, **kwargs: Any) -> Certi
:dedent: 8
"""

enabled = kwargs.pop("enabled", None)
account_id = kwargs.pop("account_id", None)
password = kwargs.pop("password", None)
organization_id = kwargs.pop("organization_id", None)
admin_contacts = kwargs.pop("admin_contacts", None)

if account_id or password:
issuer_credentials = self._models.IssuerCredentials(account_id=account_id, password=password)
else:
Expand Down Expand Up @@ -927,7 +953,18 @@ def create_issuer(self, issuer_name: str, provider: str, **kwargs: Any) -> Certi
return CertificateIssuer._from_issuer_bundle(issuer_bundle=issuer_bundle)

@distributed_trace
def update_issuer(self, issuer_name: str, **kwargs: Any) -> CertificateIssuer:
def update_issuer(
self,
issuer_name: str,
*,
enabled: Optional[bool] = None,
provider: Optional[str] = None,
account_id: Optional[str] = None,
password: Optional[str] = None,
organization_id: Optional[str] = None,
admin_contacts: Optional[List[AdministratorContact]] = None,
**kwargs: Any,
) -> CertificateIssuer:
"""Updates the specified certificate issuer. Requires certificates/setissuers permission.

:param str issuer_name: The name of the issuer.
Expand All @@ -946,12 +983,6 @@ def update_issuer(self, issuer_name: str, **kwargs: Any) -> CertificateIssuer:
:raises ~azure.core.exceptions.HttpResponseError:
"""

enabled = kwargs.pop("enabled", None)
account_id = kwargs.pop("account_id", None)
password = kwargs.pop("password", None)
organization_id = kwargs.pop("organization_id", None)
admin_contacts = kwargs.pop("admin_contacts", None)

if account_id or password:
issuer_credentials = self._models.IssuerCredentials(account_id=account_id, password=password)
else:
Expand All @@ -978,7 +1009,7 @@ def update_issuer(self, issuer_name: str, **kwargs: Any) -> CertificateIssuer:
issuer_attributes = None

parameters = self._models.CertificateIssuerUpdateParameters(
provider=kwargs.pop("provider", None),
provider=provider,
credentials=issuer_credentials,
organization_details=organization_details,
attributes=issuer_attributes,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -721,7 +721,6 @@ def _to_certificate_policy_bundle(self) -> models.CertificatePolicy:
else:
issuer_parameters = None

# pylint:disable=too-many-boolean-expressions
if (
self.enabled is not None
or self.created_on is not None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def __init__(
def parse_key_vault_id(source_id: str) -> KeyVaultResourceId:
try:
parsed_uri = parse.urlparse(source_id)
except Exception as exc: # pylint: disable=broad-except
except Exception as exc:
raise ValueError(f"'{source_id}' is not a valid ID") from exc
if not (parsed_uri.scheme and parsed_uri.hostname):
raise ValueError(f"'{source_id}' is not a valid ID")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ class KeyVaultOperationPoller(LROPoller):
:type polling_method: ~azure.core.polling.PollingMethod
"""

# pylint: disable=arguments-differ
def __init__(self, polling_method: PollingMethod) -> None:
super(KeyVaultOperationPoller, self).__init__(None, None, lambda *_: None, NoPolling())
self._polling_method = polling_method
Expand Down
Loading