-
Notifications
You must be signed in to change notification settings - Fork 2
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
357 query steps #93
357 query steps #93
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good work - nice to see the sensors stuff in there now! One or two minor comments below
KEY_PATH = '/app/sensorprivatekey' | ||
|
||
if ENVIRONMENT == 'prod': | ||
STEPS_URL = 'https://portal.rrdweb.nl/servlets/r2d2/v6.0.4/project/perfectfit/table' \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm wondering if this incredibly specific URL should be in the .env
or here. Maybe it is fine here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It makes sense to put this in the .env
file, but then we should be careful in using the two different URLs for the staging and the prod?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
...hmmm, let's leave it here for now. Best not to create traps for ourselves.
Rasa_Bot/actions/helper.py
Outdated
""" | ||
|
||
with open(KEY_PATH, 'rb') as f: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe SENSOR_KEY_PATH
could be more specific?
|
||
encoded = jwt.encode({"sub": user_id, "iat": int(round(datetime.now().timestamp()))}, | ||
private_key, algorithm="RS256") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this assume that the private key from KEY_PATH
is always RSA with SHA256? What happens if it is not?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If not it will not work, but this is also was was required by RRD, right? Shall we consider different options?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No I think it's ok since that's the key they wanted for this project. I think from a code quality perspective it would be best that the code checks that the key file it loaded was actually RSA 256 first and give a helpful error message, but for this project it is not really needed.
Rasa_Bot/actions/helper.py
Outdated
def get_steps_data(user_id: int, start_date: date, end_date: date) -> List[Dict[Any, Any]]: | ||
""" | ||
Get the encoded JWT token for querying the sensors' data. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to be a comment line from another function
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I should stop making large use of copy-paste XD
Rasa_Bot/actions/helper.py
Outdated
|
||
res = requests.get(STEPS_URL, params=query_params, headers=headers, timeout=60) | ||
res_json = res.json() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this line always return json without erroring? I've worked with annoying systems before where certain errors on the remote caused the return of an html error page and then the .json()
method would fail. If that's the case here, then a try-except might be needed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The documentation of RRD states so. If I see an html page I can close the system for good ahahha. No, I will add the try-catch for robustness
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Haha maybe we can have the code catch this and automatically buy us plane tickets to Argentina, leaving in 2 hours
SonarCloud Quality Gate failed. |
Fixes PerfectFit-project/virtual-coach-issues#357