Skip to content

Commit

Permalink
🥅 Simplify SSLCertificateProvider::refresh
Browse files Browse the repository at this point in the history
  • Loading branch information
jemrobinson committed Jan 27, 2025
1 parent b12dc8c commit a9f8f11
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 17 deletions.
4 changes: 2 additions & 2 deletions data_safe_haven/external/api/azure_sdk.py
Original file line number Diff line number Diff line change
Expand Up @@ -641,10 +641,10 @@ def get_keyvault_certificate(
"""Read a certificate from the KeyVault
Returns:
KeyVaultCertificate: The certificate
The KeyVaultCertificate
Raises:
DataSafeHavenAzureError if the secret could not be read
DataSafeHavenAzureError if the certificate could not be read
"""
# Connect to Azure clients
certificate_client = CertificateClient(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,22 +183,19 @@ def diff(
delete_before_replace=True,
)

@override
def refresh(self, props: dict[str, Any]) -> dict[str, Any]:
try:
outs = dict(**props)
with suppress(DataSafeHavenAzureError, KeyError):
azure_sdk = AzureSdk(outs["subscription_name"], disable_logging=True)
certificate = azure_sdk.get_keyvault_certificate(
outs["certificate_secret_name"], outs["key_vault_name"]
)
if certificate.secret_id:
outs["secret_id"] = certificate.secret_id
return outs
except Exception as exc:
cert_name = f"[green]{props['certificate_secret_name']}[/]"
domain_name = f"[green]{props['domain_name']}[/]"
msg = f"Failed to refresh SSL certificate {cert_name} for {domain_name}."
raise DataSafeHavenSSLError(msg) from exc
outs = dict(**props)
with suppress(DataSafeHavenAzureError, KeyError):
azure_sdk = AzureSdk(outs["subscription_name"], disable_logging=True)
kvcert = azure_sdk.get_keyvault_certificate(
outs["certificate_secret_name"], outs["key_vault_name"]
)
if kvcert.secret_id:
outs["secret_id"] = kvcert.secret_id
if kvcert.properties and kvcert.properties.expires_on:
outs["expiry_date"] = kvcert.properties.expires_on.isoformat()
return outs


class SSLCertificate(Resource):
Expand Down

0 comments on commit a9f8f11

Please sign in to comment.