-
Notifications
You must be signed in to change notification settings - Fork 499
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
base: main
Are you sure you want to change the base?
Conversation
Converting if elif .. statement into visible map
All contributors have signed the CLA ✍️ ✅ |
I have read the CLA Document and I hereby sign the CLA |
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) |
There was a problem hiding this comment.
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.
Converting if elif .. statement into visible map
Please answer these questions before submitting your pull requests. Thanks!
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
Please describe how your code solves the related issue.
Just converting long if elif statement into readable map