OHDSI / FeatureExtraction

An R package for generating features (covariates) for a cohort using data in the Common Data Model.
http://ohdsi.github.io/FeatureExtraction/
61 stars 60 forks source link

createConnectionDetails() with snowflake dbms #285

Open haleyhuston1 opened 1 day ago

haleyhuston1 commented 1 day ago

Hi,

Trying to use createConnectionDetails() to them use as a parameter in getDbCovariateData(). However, I am trying to connect to snowflake where we use a JWT authenticator rather than individual passwords.

connectionDetails <- createConnectionDetails( dbms = "snowflake", server = keyring::key_get("server"), user = keyring::key_get("user"), connectionString = keyring::key_get("connectionString"), extraSettings = list(AUTHENTICATOR = "SNOWFLAKE_JWT", PRIV_KEY_FILE = fs::path_home(".p8/private_key.p8"), PRIV_KEY_FILE_PWD = Sys.getenv("PRIVATE_KEY_PWD")), pathToDriver = fs::path_home("...") )

I've tried capturing my authenticator connection information under extraSettings but getting an error message:

Connecting using Snowflake driver Error in connectUsingJdbcDriver(): ! Connection propery 'password' is NULL.

Can someone advise? Thanks!

anthonysena commented 8 hours ago

Hi,

I haven't seen an example with using JWT to authenticate to Snowflake but it seems similar to what is done when we are connecting to Google BigQuery as shown here:

https://github.com/OHDSI/FeatureExtraction/blob/437570aa6a955486f9a4ab5917d64ac857971ed4/tests/testthat/setup.R#L111-L126

So you may want to skip using the extraSettings and construct a connectionString that includes the private key file paths and properties that you are using. I'd also suggest using absolute paths vs relative ones to make sure the resources can be found. You can test this out by constructing your connection details and then using DatabaseConnector to connect/disconnect to make sure the connection details are in working order. Then you can re-attempt to run FeatureExtraction.