-
Notifications
You must be signed in to change notification settings - Fork 5
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
OpenCPU approach #242
Comments
I changed slightly one function to make a connection to the etn directly by providing your username and password in 34254e2. Now it works fine with opencpu! so it seems that we have to go for this solution instead of using the connection object. I hope this is ok for you @peterdesmet? |
Great! For backwards compatibility, I suggest to keep using the con <- list(
username = "x",
password = "y"
) That avoids parameters to be shifted in functions: get_animals(my_con, 305)
# still calls:
get_animals(con = my_con, animal_id = 305)
# rather than:
get_animals(username = my_con, password = 305) |
I gave it a try in 8f93f5a. It works but you will have to be careful with the encoding of the This doesn't work curl -L https://localhost:8004/ocpu/library/etn/R/list_animal_ids/ -X POST -d "con=list(username='[email protected]', password='mypassword')"
# Unparsable argument: list(username This does: curl -L https://localhost:8004/ocpu/library/etn/R/list_animal_ids/ -X POST -d "con=list(username%3D'[email protected]', password%3D'mypassword')"
# /ocpu/tmp/x0829c6393d9cea/R/.val
# /ocpu/tmp/x0829c6393d9cea/R/list_animal_ids
# /ocpu/tmp/x0829c6393d9cea/stdout
# /ocpu/tmp/x0829c6393d9cea/source
# /ocpu/tmp/x0829c6393d9cea/console
# /ocpu/tmp/x0829c6393d9cea/info
# /ocpu/tmp/x0829c6393d9cea/files/DESCRIPTION See also the opencpu documentation about passing arguments: https://www.opencpu.org/api.html#api-arguments I haven't tested in R but I think it will be fine with passing the arguments through |
Ok great! Within the function(s) we can We can also extend con = list(
user = "x",
password = "y",
remote = TRUE
)
if con$remote {
# use openCPU (with url encoded parameters)
} else {
# use local DB connection
} |
@salvafern I would like to implement the OpenCPU functionality over the summer. Are all the ETN package endpoints available in OpenCPU now? |
Hi @peterdesmet we are working on it and they will be ready as soon as possible. I will let you know. |
The etn package is available at: https://opencpu.lifewatch.be/ |
I'm getting a 403 error for https://opencpu.lifewatch.be/ |
The access is forbidden for internet browsers. Try with curl or from R. |
Thanks @salvafern. Indeed, connection can be established via R (package curl): curl::curl(url = "https://opencpu.lifewatch.be/")
A connection with
description "https://opencpu.lifewatch.be/"
class "curl"
mode "r"
text "text"
opened "closed"
can read "yes"
can write "no" |
Does this method expose the credentials to anyone on the network? Or are they already encrypted somehow this way? |
Since opencpu.lifewatch.be is HTTPS by default the credentials are secure |
Excellent, is the The same code works on |
No /ocpu/tmp is not exposed. |
As I understand in 4.3 in the manual, a user posts the function call with arguments, the response includes a tmp path where the user again gets the response objects. You can also request the function output immateriality as a json object in the call using the /json flag. That second option is less attractive to me as some functions return rather large tabular outputs where I'd like a bit more control in the format that they are retrieved, probably rda using gzip compression to reduce server io. Maybe I'm missing something? |
Yes, we have been using /json all the time. |
I've adapted list_animal_ids() to list_animal_ids_api(), seems to work to me: a61a4bb Next I'll adapt a more complicated function to work by directly providing username and password as arguments, I was thinking about |
After further testing I'd like to argue in favor of exposing
|
Any opinions @bart-v @salvafern ? |
There is obvious some security issues involved, i.e. people could just "steal" the output of a more privileged user by guessing the session-id. Can you confirm that the output is written in a random, temporary folder i.e. |
I can confirm every function call should create a new dir under https://gist.github.com/PietrH/14cdb3cb581a3b835221d8b641e74b51 This demo makes use of the opencpu test api (calling We could sanitize these paths on a steady interval. I also believe brute forcing the keys would be quite the challenge since you'd need to try a lot of keys with no guarantee on the type of result even if you manage to find a path that's in use, this risk is further mitigated with protections that might already be in place to protect from denial of service attacks. |
OK paths like |
I'm still getting a 403 on
Are subdirectories also exposed? Is there a mistake in my domain? |
The base path is without "ocpu" I thought we only downloaded files and not special paths like .val, etc... |
My apologies for the confusion, after a POST request the client sends a GET request to one of the paths provided in the POST response body. The most common case will be /tmp/{key}/R/.val with then the requested datatype as a suffix, rds in our case. It's my understanding we'll also be able to use this workflow to get other formats such as is needed for For example you'd GET https://opencpu.lifewatch.be/ocpu/tmp/x010f9753592ec8/R/.val/rds to get a rds stream (compressed) or GET https://opencpu.lifewatch.be/ocpu/tmp/x010f9753592ec8/R/.val/csv or https://opencpu.lifewatch.be/ocpu/tmp/x010f9753592ec8/R/.val/feather (this key might have been voided by the time you read this). I'm following the opencpu manual, section 4.3: https://opencpu.github.io/server-manual/opencpu-server.pdf
|
OK, https://opencpu.lifewatch.be/tmp/x010f9753592ec8/R/.val/rds works now |
It's working now! Thanks for all the help. I'll keep you updated with my progress. |
Summary of March 8 meeting:
Create two "flavours" of all functions in the etn package: local and remote. Function names remain the same, the difference is made in the
con
variable. For localcon
is a database connection, for remotecon
are credentials to be passed via OpenCPU. The intent is to keep a single R package.For remote access, bandwidth and file size might become an issue. Potential solutions:
Transfer data as binary feather files. Read withFeather files are not compressed, so there is no gain here over csv. Most compressed format is very likelyarrow::read_feather()
.rda
, so planning to use that.download_acoustic_detections()
(rather thanget_accoustic_detections()
) so users only have to transfer huge amounts of data once.Next steps:
The text was updated successfully, but these errors were encountered: