inbo / etn

R package to access data from the European Tracking Network
https://inbo.github.io/etn/
MIT License
6 stars 5 forks source link

deprecate `connect_to_etn()` instead of not exporting #303

Closed PietrH closed 1 month ago

PietrH commented 2 months ago

TODO

All examples work again, but they still need to be updated: #308

I'm having a strange issue where the new tests for the deprecation message for connect_to_etn() fail on the RStudio VLIZ server, but only when I call test package or devtools::test(filter = "connect_to_etn"), not when running the tests directly or clicking run tests. Very strange. I also can't replicate it locally. Visually the warning message looks fine.

PietrH commented 2 months ago

I suppose connect_to_etn() should remain functional as we are now going down the road of soft deprecation

peterdesmet commented 2 months ago

Yeah, I guess:

PietrH commented 2 months ago

Soft or hard deprecation

At the moment, the SQL versions of the functions themselves use connect_to_etn() to create database connections like so:

connection <- do.call(connect_to_etn, get_credentials())

So:

What do you prefer?

Leaking credentials

Credentials are can be leaked via RHistory or scripts because people are encouraged to enter their password directly:

connect_to_etn(username = Sys.getenv("userid"), password = Sys.getenv("pwd"))

I'm currently still storing credentials as environmental variables, just like rgbif, but i'd prefer to use something like keyring in the future. This is why the new functions prompt the user, instead of allowing them to enter directly. I'm also using a dependency (askpass) for the password, using the RStudio API so this vital secret can't end up captured somewhere where it doesn't belong.

Any root/sudo user, or any child processes of the current user can access these credentials. It's non trivial for other users to get to them, but environmental variables still aren't a good place to store passwords in my opinion.

peterdesmet commented 2 months ago

Users that currently experience:

library(etn)
con <- connect_to_etn()
con
#> <OdbcConnection> peter.desmet@inbo.be@pgetn.vliz.be
#>   Database: ETN
#>   PostgreSQL Version: 14.0.13
animals <- get_animals(con, animal_id = 305)

Should get something like:

library(etn)
con <- connect_to_etn()
#> Deprecation warning:
#> connect_to_etn() has been deprecated since etn 2.3.0.
#> You will be prompted for credentials instead.
con
#> NULL
animals <- get_animals(con, animal_id = 305)
#> Deprecation warning:
#> `connection` has been deprecated since etn 2.3.0.
#> You will be prompted for credentials instead.

So I prefer:

Hard deprecate, return NULL, add new helper.

This will also make it clearer to us developers to no longer rely on connect_to_etn().

PietrH commented 2 months ago

I agree, that seems to be the cleanest way forward!