Skip to content
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

deprecate connect_to_etn() instead of not exporting #303

Closed
10 of 11 tasks
PietrH opened this issue Sep 17, 2024 · 5 comments · Fixed by #313
Closed
10 of 11 tasks

deprecate connect_to_etn() instead of not exporting #303

PietrH opened this issue Sep 17, 2024 · 5 comments · Fixed by #313
Assignees
Labels
actionable Can be implemented API
Milestone

Comments

@PietrH
Copy link
Member

PietrH commented Sep 17, 2024

TODO

  • reexport connect_to_etn()
  • Set return value of connect_to_etn() to NULL
  • all examples should work again
  • all vignettes should work again
  • add test connect_to_etn(): should provide deprecation message
  • Check if information in NEWS is still correct
  • add deprecation badge to connect_to_etn()
  • create new helper in place of connect_to_etn()
  • create test for new helper
  • implement use of helper in all sql helper functions
  • fix issue tests connect_to_etn() only fail in test package on RStudio VLIZ

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
Copy link
Member Author

PietrH commented Sep 25, 2024

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

@peterdesmet
Copy link
Member

Yeah, I guess:

  • The function remains and is marked deprecated
  • The function returns NULL to not leak credentials?

@PietrH
Copy link
Member Author

PietrH commented Sep 25, 2024

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:

  • Soft deprecate and keep using internally: it'll keep working but is not encouraged
  • Hard deprecate, return NULL, add new helper. This should be easy enough.

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.

PietrH added a commit that referenced this issue Sep 25, 2024
@peterdesmet
Copy link
Member

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
Copy link
Member Author

PietrH commented Sep 25, 2024

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

@PietrH PietrH linked a pull request Sep 25, 2024 that will close this issue
@PietrH PietrH closed this as completed Sep 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
actionable Can be implemented API
Projects
None yet
2 participants