Skip to content

Update wif_util.py create_attestation #2315

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

hanooka
Copy link

@hanooka hanooka commented May 7, 2025

Converting if elif .. statement into visible map

Please answer these questions before submitting your pull requests. Thanks!

  1. What GitHub issue is this PR addressing? Make sure that there is an accompanying issue to your PR.

    Code enhances readability and easier to maintain

  2. Please describe how your code solves the related issue.

    Just converting long if elif statement into readable map

Converting if elif .. statement into visible map
Copy link

github-actions bot commented May 7, 2025

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@hanooka
Copy link
Author

hanooka commented May 7, 2025

I have read the CLA Document and I hereby sign the CLA

Comment on lines -308 to +319
attestation: WorkloadIdentityAttestation = None
if provider == AttestationProvider.AWS:
attestation = create_aws_attestation()
elif provider == AttestationProvider.AZURE:
attestation = create_azure_attestation(entra_resource)
elif provider == AttestationProvider.GCP:
attestation = create_gcp_attestation()
elif provider == AttestationProvider.OIDC:
attestation = create_oidc_attestation(token)
elif provider is None:
attestation = create_autodetect_attestation(entra_resource, token)
provider_map = (
lambda: None,
{
AttestationProvider.AWS: lambda: create_aws_attestation(),
AttestationProvider.AZURE: lambda: create_azure_attestation(entra_resource),
AttestationProvider.GCP: lambda: create_gcp_attestation(),
AttestationProvider.OIDC: lambda: create_oidc_attestation(token),
None: lambda: create_autodetect_attestation(entra_resource, token)
}
)
attestation: WorkloadIdentityAttestation = provider_map(provider)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't necessarily think this is more readable. A simple set of if-else conditions is very easy to understand by anyone who knows basic Python. OTOH, I'm not sure why we'd create a tuple of an empty callable and a dictionary, then use the tuple as a dictionary later.

Also, note that the order that we check the providers is intentional (based on perceived usage share). This is much easier to see in the basic procedural code rather than the indirection through a dictionary.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants