inbo / etn

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

API Behaviour: authentication and switching between local db and API #280

Open PietrH opened 1 year ago

PietrH commented 1 year ago

This is a technical issue to capture a discussion regarding the future migration of ETN to using an OpenCPU API.

Function Naming

Authentication and switching between the API and a local database connection

flowchart TD

main(("list_animal_ids(
    other_arguments,
    connection = NULL,
    api = TRUE
    )")) --api=true--> api_helper(("list_animal_ids_api(
    other_arguments
    )"))
main --api=false--> sql_helper(("list_animal_ids_sql(
other_arguments
)"))
main --"lifecycle::is_present(connection)"-->warning[["warning: connection is depreciated,
please set API=FALSE to use local db"]]
warning --> sql_helper
api_helper --> get_credentials1["credentials = get_credentials()"]
api_helper --> other_arguments1["other_arguments"]
get_credentials1 --> etnservice[/"ETNSERVICE"/]
other_arguments1 --> etnservice
sql_helper --> get_credentials2["credentials = get_credentials()"]
get_credentials2 --> connection
sql_helper --> other_arguments2["other_arguments"]
connection --> code>"existing code"]
other_arguments2 --> code

Idea's

PietrH commented 1 year ago

Should the tests for the API only, or once for the API route, and once for the SQL route?

For integration into github actions, only the API route makes sense.

PietrH commented 1 year ago

get_credentials() now prompts the user when no values are stored in sys.env: d1a2b06c11f0214e5855f97750db53fdef5bac95

PietrH commented 1 year ago

I'm now using a generic api helper instead of a api helper per function: 8d9a001b108073ac6c9ee93048e0a81248a9e3a3

PietrH commented 1 year ago

The code used for the main functions is very repetitive, and suitable for wrapping in a helper. This would make changes to this code easier in the future and would keep it DRY.

However, it currently is immediately apparent what the main function is doing (some parsing, and passing arguments on to two helpers, one general, and one specific). Using a helper to do this, would detract from the functions being self explaining.

PietrH commented 1 year ago

Instead of having a helper function with almost the same code as etnservice, wouldn't it be cool if the helper could instead just get the code from etnservice directly and evaluate it in place for it's sql functions?

That way we only have to maintain the functions in one place.

peterdesmet commented 1 year ago

Right, we currently need to maintain it in two places ... We could load etnservice as a dependency, but then we also bring in its dependencies.

PietrH commented 1 year ago

etnservice will, at least for the moment have the same dependencies as etn as they are both running the same sql functions. etn also adds some packages for handling the communication with the api.

I think loading etnservice as a dependency is the way forward, but for now I'll keep going ahead with a hard coded _sql helper. And migrate to using etnservice when we are bit further ahead.