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

357 query steps #93

Merged
merged 6 commits into from
Jun 6, 2023
Merged

357 query steps #93

merged 6 commits into from
Jun 6, 2023

Conversation

wbaccinelli
Copy link
Contributor

Copy link
Contributor

@raar1 raar1 left a 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' \
Copy link
Contributor

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

Copy link
Contributor Author

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?

Copy link
Contributor

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.

"""

with open(KEY_PATH, 'rb') as f:
Copy link
Contributor

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")
Copy link
Contributor

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?

Copy link
Contributor Author

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?

Copy link
Contributor

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.

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.
Copy link
Contributor

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

Copy link
Contributor Author

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


res = requests.get(STEPS_URL, params=query_params, headers=headers, timeout=60)
res_json = res.json()
Copy link
Contributor

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

Copy link
Contributor Author

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

Copy link
Contributor

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

@sonarqubecloud
Copy link

sonarqubecloud bot commented Jun 6, 2023

SonarCloud Quality Gate failed.    Quality Gate failed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 3 Code Smells

41.2% 41.2% Coverage
0.0% 0.0% Duplication

@wbaccinelli wbaccinelli merged commit f165784 into main Jun 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement functions to query steps data
2 participants