Skip to content

Commit

Permalink
chore(python): use black==22.3.0 (#204)
Browse files Browse the repository at this point in the history
Source-Link: googleapis/synthtool@6fab84a
Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-python:latest@sha256:7cffbc10910c3ab1b852c05114a08d374c195a81cdec1d4a67a1d129331d0bfe
  • Loading branch information
gcf-owl-bot[bot] authored Mar 28, 2022
1 parent 8f7813a commit 42384bf
Show file tree
Hide file tree
Showing 18 changed files with 102 additions and 36 deletions.
4 changes: 3 additions & 1 deletion privateca/snippets/create_ca_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ def create_ca_pool(project_id: str, location: str, ca_pool_name: str) -> None:

# Create the pool request.
request = privateca_v1.CreateCaPoolRequest(
parent=location_path, ca_pool_id=ca_pool_name, ca_pool=ca_pool,
parent=location_path,
ca_pool_id=ca_pool_name,
ca_pool=ca_pool,
)

# Create the CA pool.
Expand Down
9 changes: 6 additions & 3 deletions privateca/snippets/create_certificate.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ def create_certificate(

# Set the Public Key and its format.
public_key = privateca_v1.PublicKey(
key=public_key_bytes, format_=privateca_v1.PublicKey.KeyFormat.PEM,
key=public_key_bytes,
format_=privateca_v1.PublicKey.KeyFormat.PEM,
)

subject_config = privateca_v1.CertificateConfig.SubjectConfig(
Expand All @@ -66,10 +67,12 @@ def create_certificate(
x509_parameters = privateca_v1.X509Parameters(
key_usage=privateca_v1.KeyUsage(
base_key_usage=privateca_v1.KeyUsage.KeyUsageOptions(
digital_signature=True, key_encipherment=True,
digital_signature=True,
key_encipherment=True,
),
extended_key_usage=privateca_v1.KeyUsage.ExtendedKeyUsageOptions(
server_auth=True, client_auth=True,
server_auth=True,
client_auth=True,
),
),
)
Expand Down
10 changes: 7 additions & 3 deletions privateca/snippets/create_certificate_authority.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,13 @@ def create_certificate_authority(
x509_parameters = privateca_v1.X509Parameters(
key_usage=privateca_v1.KeyUsage(
base_key_usage=privateca_v1.KeyUsage.KeyUsageOptions(
crl_sign=True, cert_sign=True,
crl_sign=True,
cert_sign=True,
)
),
ca_options=privateca_v1.X509Parameters.CaOptions(is_ca=True,),
ca_options=privateca_v1.X509Parameters.CaOptions(
is_ca=True,
),
)

# Set certificate authority settings.
Expand All @@ -70,7 +73,8 @@ def create_certificate_authority(
type_=privateca_v1.CertificateAuthority.Type.SELF_SIGNED,
key_spec=key_version_spec,
config=privateca_v1.CertificateConfig(
subject_config=subject_config, x509_config=x509_parameters,
subject_config=subject_config,
x509_config=x509_parameters,
),
lifetime=duration_pb2.Duration(seconds=ca_duration),
)
Expand Down
3 changes: 2 additions & 1 deletion privateca/snippets/create_certificate_csr.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ def create_certificate_csr(
# Create certificate with CSR.
# The pem_csr contains the public key and the domain details required.
certificate = privateca_v1.Certificate(
pem_csr=pem_csr, lifetime=duration_pb2.Duration(seconds=certificate_lifetime),
pem_csr=pem_csr,
lifetime=duration_pb2.Duration(seconds=certificate_lifetime),
)

# Create the Certificate Request.
Expand Down
11 changes: 8 additions & 3 deletions privateca/snippets/create_certificate_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@


def create_certificate_template(
project_id: str, location: str, certificate_template_id: str,
project_id: str,
location: str,
certificate_template_id: str,
) -> None:
"""
Create a Certificate template. These templates can be reused for common
Expand All @@ -39,13 +41,16 @@ def create_certificate_template(
x509_parameters = privateca_v1.X509Parameters(
key_usage=privateca_v1.KeyUsage(
base_key_usage=privateca_v1.KeyUsage.KeyUsageOptions(
digital_signature=True, key_encipherment=True,
digital_signature=True,
key_encipherment=True,
),
extended_key_usage=privateca_v1.KeyUsage.ExtendedKeyUsageOptions(
server_auth=True,
),
),
ca_options=privateca_v1.X509Parameters.CaOptions(is_ca=False,),
ca_options=privateca_v1.X509Parameters.CaOptions(
is_ca=False,
),
)

# CEL expression that is evaluated against the Subject and
Expand Down
10 changes: 7 additions & 3 deletions privateca/snippets/create_subordinate_ca.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,22 @@ def create_subordinate_ca(
x509_parameters = privateca_v1.X509Parameters(
key_usage=privateca_v1.KeyUsage(
base_key_usage=privateca_v1.KeyUsage.KeyUsageOptions(
crl_sign=True, cert_sign=True,
crl_sign=True,
cert_sign=True,
)
),
ca_options=privateca_v1.X509Parameters.CaOptions(is_ca=True,),
ca_options=privateca_v1.X509Parameters.CaOptions(
is_ca=True,
),
)

# Set certificate authority settings.
certificate_authority = privateca_v1.CertificateAuthority(
type_=privateca_v1.CertificateAuthority.Type.SUBORDINATE,
key_spec=key_version_spec,
config=privateca_v1.CertificateConfig(
subject_config=subject_config, x509_config=x509_parameters,
subject_config=subject_config,
x509_config=x509_parameters,
),
# Set the CA validity duration.
lifetime=duration_pb2.Duration(seconds=ca_duration),
Expand Down
8 changes: 6 additions & 2 deletions privateca/snippets/delete_certificate_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@


def delete_certificate_template(
project_id: str, location: str, certificate_template_id: str,
project_id: str,
location: str,
certificate_template_id: str,
) -> None:
"""
Delete the certificate template present in the given project and location.
Expand All @@ -35,7 +37,9 @@ def delete_certificate_template(
# Request to delete a certificate template.
request = privateca_v1.DeleteCertificateTemplateRequest(
name=caServiceClient.certificate_template_path(
project_id, location, certificate_template_id,
project_id,
location,
certificate_template_id,
)
)
operation = caServiceClient.delete_certificate_template(request=request)
Expand Down
4 changes: 3 additions & 1 deletion privateca/snippets/enable_certificate_authority.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ def enable_certificate_authority(
)

# Create the Enable Certificate Authority Request.
request = privateca_v1.EnableCertificateAuthorityRequest(name=ca_path,)
request = privateca_v1.EnableCertificateAuthorityRequest(
name=ca_path,
)

# Enable the Certificate Authority.
operation = caServiceClient.enable_certificate_authority(request=request)
Expand Down
3 changes: 2 additions & 1 deletion privateca/snippets/filter_certificates.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ def filter_certificates(

# Create the certificate request and set the filter condition.
request = privateca_v1.ListCertificatesRequest(
parent=ca_pool_path, filter=filter_condition,
parent=ca_pool_path,
filter=filter_condition,
)

# Retrieve and print the certificate names.
Expand Down
6 changes: 5 additions & 1 deletion privateca/snippets/list_certificates.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@
import google.cloud.security.privateca_v1 as privateca_v1


def list_certificates(project_id: str, location: str, ca_pool_name: str,) -> None:
def list_certificates(
project_id: str,
location: str,
ca_pool_name: str,
) -> None:
"""
List Certificates present in the given CA pool.
Expand Down
4 changes: 2 additions & 2 deletions privateca/snippets/noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
# WARNING - WARNING - WARNING - WARNING - WARNING
# WARNING - WARNING - WARNING - WARNING - WARNING

BLACK_VERSION = "black==19.10b0"
BLACK_VERSION = "black==22.3.0"

# Copy `noxfile_config.py` to your directory and modify it instead.

Expand Down Expand Up @@ -253,7 +253,7 @@ def py(session: nox.sessions.Session) -> None:


def _get_repo_root() -> Optional[str]:
""" Returns the root folder of the project. """
"""Returns the root folder of the project."""
# Get root of this repository. Assume we don't have directories nested deeper than 10 items.
p = Path(os.getcwd())
for i in range(10):
Expand Down
5 changes: 4 additions & 1 deletion privateca/snippets/revoke_certificate.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@


def revoke_certificate(
project_id: str, location: str, ca_pool_name: str, certificate_name: str,
project_id: str,
location: str,
ca_pool_name: str,
certificate_name: str,
) -> None:
"""
Revoke an issued certificate. Once revoked, the certificate will become invalid and will expire post its lifetime.
Expand Down
20 changes: 16 additions & 4 deletions privateca/snippets/test_certificate_authorities.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,14 @@ def test_enable_and_disable_certificate_authority(

out, _ = capsys.readouterr()

assert re.search(f"Enabled Certificate Authority: {CA_NAME}", out,)
assert re.search(f"Disabled Certificate Authority: {CA_NAME}", out,)
assert re.search(
f"Enabled Certificate Authority: {CA_NAME}",
out,
)
assert re.search(
f"Disabled Certificate Authority: {CA_NAME}",
out,
)


def test_undelete_certificate_authority(
Expand All @@ -84,8 +90,14 @@ def test_undelete_certificate_authority(
delete_ca_pool(PROJECT, LOCATION, CA_POOL_NAME)

out, _ = capsys.readouterr()
assert re.search(f"Successfully undeleted Certificate Authority: {CA_NAME}", out,)
assert re.search(f"Successfully deleted Certificate Authority: {CA_NAME}", out,)
assert re.search(
f"Successfully undeleted Certificate Authority: {CA_NAME}",
out,
)
assert re.search(
f"Successfully deleted Certificate Authority: {CA_NAME}",
out,
)


def test_update_certificate_authority(
Expand Down
5 changes: 4 additions & 1 deletion privateca/snippets/test_certificates.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,10 @@ def test_create_and_revoke_certificate_authority(
filter_certificates(PROJECT, LOCATION, CA_POOL_NAME, FILTER_CONDITION)

revoke_certificate(
PROJECT, LOCATION, CA_POOL_NAME, CERT_NAME,
PROJECT,
LOCATION,
CA_POOL_NAME,
CERT_NAME,
)

disable_certificate_authority(PROJECT, LOCATION, CA_POOL_NAME, CA_NAME)
Expand Down
5 changes: 4 additions & 1 deletion privateca/snippets/test_subordinate_ca.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,10 @@ def test_subordinate_certificate_authority(
)

revoke_certificate(
PROJECT, LOCATION, CA_POOL_NAME, CSR_CERT_NAME,
PROJECT,
LOCATION,
CA_POOL_NAME,
CSR_CERT_NAME,
)

out, _ = capsys.readouterr()
Expand Down
9 changes: 7 additions & 2 deletions privateca/snippets/update_ca_pool_issuance_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@


def update_ca_pool_issuance_policy(
project_id: str, location: str, ca_pool_name: str,
project_id: str,
location: str,
ca_pool_name: str,
) -> None:
"""
Update the issuance policy for a CA Pool. All certificates issued from this CA Pool should
Expand Down Expand Up @@ -52,7 +54,10 @@ def update_ca_pool_issuance_policy(
),
)

ca_pool = privateca_v1.CaPool(name=ca_pool_path, issuance_policy=issuance_policy,)
ca_pool = privateca_v1.CaPool(
name=ca_pool_path,
issuance_policy=issuance_policy,
)

# 1. Set the CA pool with updated values.
# 2. Set the update mask to specify which properties of the CA Pool should be updated.
Expand Down
8 changes: 6 additions & 2 deletions privateca/snippets/update_certificate_authority.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@


def update_ca_label(
project_id: str, location: str, ca_pool_name: str, ca_name: str,
project_id: str,
location: str,
ca_pool_name: str,
ca_name: str,
) -> None:
"""
Update the labels in a certificate authority.
Expand All @@ -39,7 +42,8 @@ def update_ca_label(
project_id, location, ca_pool_name, ca_name
)
certificate_authority = privateca_v1.CertificateAuthority(
name=ca_parent, labels={"env": "test"},
name=ca_parent,
labels={"env": "test"},
)

# Create a request to update the CA.
Expand Down
14 changes: 10 additions & 4 deletions privateca/snippets/update_certificate_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@


def update_certificate_template(
project_id: str, location: str, certificate_template_id: str,
project_id: str,
location: str,
certificate_template_id: str,
) -> None:
"""
Update an existing certificate template.
Expand All @@ -34,14 +36,17 @@ def update_certificate_template(
caServiceClient = privateca_v1.CertificateAuthorityServiceClient()

certificate_name = caServiceClient.certificate_template_path(
project_id, location, certificate_template_id,
project_id,
location,
certificate_template_id,
)

# Set the parent name and the properties to be updated.
certificate_template = privateca_v1.CertificateTemplate(
name=certificate_name,
identity_constraints=privateca_v1.CertificateIdentityConstraints(
allow_subject_passthrough=False, allow_subject_alt_names_passthrough=True,
allow_subject_passthrough=False,
allow_subject_alt_names_passthrough=True,
),
)

Expand All @@ -56,7 +61,8 @@ def update_certificate_template(
# Set the new template.
# Set the mask to specify which properties of the template should be updated.
request = privateca_v1.UpdateCertificateTemplateRequest(
certificate_template=certificate_template, update_mask=field_mask,
certificate_template=certificate_template,
update_mask=field_mask,
)
operation = caServiceClient.update_certificate_template(request=request)
result = operation.result()
Expand Down

0 comments on commit 42384bf

Please sign in to comment.