Snowflake-Labs / django-snowflake

MIT License
59 stars 15 forks source link

Allow specifying a private_key in DATABASES 'OPTIONS' without PASSWORD or authenticator #69

Closed sfc-gh-hachouraria closed 1 year ago

sfc-gh-hachouraria commented 1 year ago

Current implementation requires an explicit authenticator = 'SNOWFLAKE_JWT' value to be passed when supplying a private_key config.

Conventionally it should be adequate to supply only a private_key and have it ignore PASSWORD without also requiring authenticator.

This change makes passing authenticator optional when passing a private_key value.

Manually tested with configs:

# Passes (Only private_key, no password)
DATABASES = {
    'default': {
        'ENGINE': 'django_snowflake',
        …
        'OPTIONS': {
            'private_key': pkb,
        },
    },
}
# Passes (Only authenticator, no password)
DATABASES = {
    'default': {
        'ENGINE': 'django_snowflake',
        …
        'OPTIONS': {
            'authenticator': 'externalbrowser',
        },
    },
}
# Passes (both options, no password)
DATABASES = {
    'default': {
        'ENGINE': 'django_snowflake',
        …
        'OPTIONS': {
            'private_key': pkb,
            'authenticator': 'SNOWFLAKE_JWT',
        },
    },
}
# Fails (no options, no password)
DATABASES = {
    'default': {
        'ENGINE': 'django_snowflake',
        …
        'OPTIONS': {},
    },
}

All invalid values continue to fail with appropriate exceptions. Specifying password while specifying the other options defers to the priority order in the connector.