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
Open
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
25 changes: 13 additions & 12 deletions src/snowflake/connector/wif_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import os
from base64 import b64encode
from dataclasses import dataclass
from collections import defaultdict
from enum import Enum, unique

import boto3
Expand Down Expand Up @@ -304,18 +305,18 @@ def create_attestation(
If an explicit entra_resource was provided to the connector, this will be used. Otherwise, the default Snowflake Entra resource will be used.
"""
entra_resource = entra_resource or DEFAULT_ENTRA_SNOWFLAKE_RESOURCE

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)
Comment on lines -308 to +319
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.


if not attestation:
provider_str = "auto-detect" if provider is None else provider.value
Expand Down