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

Control BTF authentication via env. variables; cache part of BTF API; resolves #60 #66

Merged
merged 4 commits into from
Apr 6, 2021

Conversation

davidverweij
Copy link
Member

In this PR, I've restructured BTF's authentication from being a class attribute, to being stored in the environmental variables; much like how this is done at the dmpy package. This will ensure that the authentication is re-done every 50 minutes (10 minutes before a token expires) - this check is triggered when preparing for an actual GET request. The proposed solution moved the authentication to the lib/byteflies.py and thereby also removes the need to pass a requests.Session variable around.

Additionally, I've cached the __get_recording_by_id() (maxsize of 1). Since we wanted the code to run for any individual file, at any time (no dependencies on living variables), the pipeline made subsequent calls to the exact same API endpoint. With the proposed changes, the result of this call is cached for max 5 minutes (since the links in the payload are valid for only 10). A quick test shows (for example) out of 21 files to be downloaded from one recording, 7 files to be downloaded were based on the same API call and have now been reduced to one. The other 14 calls could not be cached as they call a deeper API link to retrieve the algorithm download url; which has to be done for each algorithm file. I've turned down the sleep.time() from 1 to .5 to speed this up a bit.

Testing

  • poetry run nox -r
  • set env's to point to local mongoDB
  • clear mongo,DB data and upload folder
  • poetry run consumer
  • python data_transfer/main.py BTF Muenster 0 3
  • (increase the 3 to keep adding records; i.e. go further back in time)

Any feedback highly appreciated @jawrainey @ColinBD !

- remove passing around of session variable
- use time difference to determine if a new auth is required
- allow forcing of new auth (e.g. when getting an 401 HTTP)
@davidverweij davidverweij added bug Oh my feature new feature or request byteflies FS Device data-transfer Data Transfer Protocol labels Apr 6, 2021
@davidverweij davidverweij self-assigned this Apr 6, 2021
@davidverweij davidverweij linked an issue Apr 6, 2021 that may be closed by this pull request
@davidverweij
Copy link
Member Author

NOTE, a few things are left to do; for which I have created Issue #67

Copy link
Member

@jawrainey jawrainey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Worked for me locally with no issues. There's one minor issue with setting environmental variables, but otherwise perfect 👍🏼

@davidverweij davidverweij requested a review from jawrainey April 6, 2021 16:14
@jawrainey jawrainey merged commit 2f02588 into master Apr 6, 2021
@jawrainey jawrainey deleted the btf_auth branch April 6, 2021 16:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Oh my byteflies FS Device data-transfer Data Transfer Protocol feature new feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Reauthorize BTF pipeline
2 participants