TomerFi / aioswitcher

PyPi module integrating with various Switcher devices
https://aioswitcher.tomfi.info
Apache License 2.0
30 stars 19 forks source link

chore: added token support in types and a convertion utility function #766

Closed YogevBokobza closed 6 months ago

YogevBokobza commented 7 months ago

Description

Adding the tok.py had in the previous s11 PR, added token needed for the devices in the discovery and added tests.

Related issue (if any): fixes #issue_number_goes_here

Checklist

Additional information

Anything else?

gitguardian[bot] commented 7 months ago

⚠️ GitGuardian has uncovered 7 secrets following the scan of your pull request.

Please consider investigating the findings and remediating the incidents. Failure to do so may lead to compromising the associated services or software components.

🔎 Detected hardcoded secrets in your pull request
| GitGuardian id | GitGuardian status | Secret | Commit | Filename | | | -------------- | ------------------ | ------------------------------ | ---------------- | --------------- | -------------------- | | [-](https://dashboard.gitguardian.com/workspace/219595/incidents/secrets) | | Generic High Entropy Secret | f80f8a3bdfb34c338a1918d0c42c40260463d224 | src/aioswitcher/device/tools.py | [View secret](https://github.com/TomerFi/aioswitcher/commit/f80f8a3bdfb34c338a1918d0c42c40260463d224#diff-76fda1abe206ffc78578e59e694e42cf998f9158ec5427d72e3f42d8db31c7a4L193) | | [-](https://dashboard.gitguardian.com/workspace/219595/incidents/secrets) | | Generic High Entropy Secret | 81737c4dff8966e40c0ef98240a63e1bdb0fbd62 | src/aioswitcher/device/tools.py | [View secret](https://github.com/TomerFi/aioswitcher/commit/81737c4dff8966e40c0ef98240a63e1bdb0fbd62#diff-76fda1abe206ffc78578e59e694e42cf998f9158ec5427d72e3f42d8db31c7a4R193) | | [-](https://dashboard.gitguardian.com/workspace/219595/incidents/secrets) | | Generic High Entropy Secret | 6de43e926e24eeb4294e4fb98fbeb5e418601d08 | src/aioswitcher/device/tools.py | [View secret](https://github.com/TomerFi/aioswitcher/commit/6de43e926e24eeb4294e4fb98fbeb5e418601d08#diff-76fda1abe206ffc78578e59e694e42cf998f9158ec5427d72e3f42d8db31c7a4L186) | | [-](https://dashboard.gitguardian.com/workspace/219595/incidents/secrets) | | Generic High Entropy Secret | 6de43e926e24eeb4294e4fb98fbeb5e418601d08 | src/aioswitcher/device/tok.py | [View secret](https://github.com/TomerFi/aioswitcher/commit/6de43e926e24eeb4294e4fb98fbeb5e418601d08#diff-eefb4c7dec42b89f2dcafff85eaa9911096e55ade4d752e5c149c19987498e75R25) | | [-](https://dashboard.gitguardian.com/workspace/219595/incidents/secrets) | | Generic High Entropy Secret | f80f8a3bdfb34c338a1918d0c42c40260463d224 | src/aioswitcher/device/tools.py | [View secret](https://github.com/TomerFi/aioswitcher/commit/f80f8a3bdfb34c338a1918d0c42c40260463d224#diff-76fda1abe206ffc78578e59e694e42cf998f9158ec5427d72e3f42d8db31c7a4R186) | | [-](https://dashboard.gitguardian.com/workspace/219595/incidents/secrets) | | Generic High Entropy Secret | baea774c51ab2643e9b223609f142f84b454a081 | src/aioswitcher/device/tok.py | [View secret](https://github.com/TomerFi/aioswitcher/commit/baea774c51ab2643e9b223609f142f84b454a081#diff-eefb4c7dec42b89f2dcafff85eaa9911096e55ade4d752e5c149c19987498e75R24) | | [-](https://dashboard.gitguardian.com/workspace/219595/incidents/secrets) | | Generic High Entropy Secret | afdb14045716f0f40f9faa6efcf894b5480f2768 | src/aioswitcher/device/tok.py | [View secret](https://github.com/TomerFi/aioswitcher/commit/afdb14045716f0f40f9faa6efcf894b5480f2768#diff-eefb4c7dec42b89f2dcafff85eaa9911096e55ade4d752e5c149c19987498e75L24) |
🛠 Guidelines to remediate hardcoded secrets
1. Understand the implications of revoking this secret by investigating where it is used in your code. 2. Replace and store your secrets safely. [Learn here](https://blog.gitguardian.com/secrets-api-management?utm_source=product&utm_medium=GitHub_checks&utm_campaign=check_run_comment) the best practices. 3. Revoke and [rotate these secrets](https://docs.gitguardian.com/secrets-detection/secrets-detection-engine/detectors/generics/generic_high_entropy_secret#revoke-the-secret?utm_source=product&utm_medium=GitHub_checks&utm_campaign=check_run_comment). 4. If possible, [rewrite git history](https://blog.gitguardian.com/rewriting-git-history-cheatsheet?utm_source=product&utm_medium=GitHub_checks&utm_campaign=check_run_comment). Rewriting git history is not a trivial act. You might completely break other contributing developers' workflow and you risk accidentally deleting legitimate data. To avoid such incidents in the future consider - following these [best practices](https://blog.gitguardian.com/secrets-api-management/?utm_source=product&utm_medium=GitHub_checks&utm_campaign=check_run_comment) for managing and storing secrets including API keys and other credentials - install [secret detection on pre-commit](https://docs.gitguardian.com/ggshield-docs/integrations/git-hooks/pre-commit?utm_source=product&utm_medium=GitHub_checks&utm_campaign=check_run_comment) to catch secret before it leaves your machine and ease remediation.

🦉 GitGuardian detects secrets in your source code to help developers and security teams secure the modern development process. You are seeing this because you or someone else with access to this repository has authorized GitGuardian to scan your pull request.

YogevBokobza commented 7 months ago

@thecode @TomerFi Do you have any idea why the tests are failing for Python 3.9? For Python 3.10 it's working fine.

YogevBokobza commented 7 months ago

@thecode @TomerFi Do you have any idea why the tests are failing for Python 3.9? For Python 3.10 it's working fine.

Never mind. I think I fixed that here and here

codecov[bot] commented 7 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

:exclamation: No coverage uploaded for pull request base (runner-support-fixed@0461c30). Click here to learn what that means.

:exclamation: Current head a4253c9 differs from pull request most recent head a4ed349. Consider uploading reports for the commit a4ed349 to get more accurate results

Additional details and impacted files ```diff @@ Coverage Diff @@ ## runner-support-fixed #766 +/- ## ======================================================= Coverage ? 97.97% ======================================================= Files ? 11 Lines ? 1184 Branches ? 0 ======================================================= Hits ? 1160 Misses ? 24 Partials ? 0 ```
YogevBokobza commented 7 months ago

@thecode @TomerFi I just found out this leftover from when we used that API call to get the token.. Do we want to have this token inside a DeviceToken class and possibly make the conversion there? or just have it as a string and remove this class?

TomerFi commented 7 months ago

@thecode @TomerFi I just found out this leftover from when we used that API call to get the token.. Do we want to have this token inside a DeviceToken class and possibly make the conversion there? or just have it as a string and remove this class?

I vote for removing the class. I don't see any value in encapsulating the token.

YogevBokobza commented 7 months ago

@thecode @TomerFi I just found out this leftover from when we used that API call to get the token.. Do we want to have this token inside a DeviceToken class and possibly make the conversion there? or just have it as a string and remove this class?

I vote for removing the class. I don't see any value in encapsulating the token.

I removed that DeviceToken class.

YogevBokobza commented 7 months ago

I took a few days off this PR as I am in the middle of moving apartments. I will get back to this in the coming week.

blorby commented 7 months ago

I took a few days off this PR as I am in the middle of moving apartments. I will get back to this in the coming week.

Mazal Tov and Good luck!

YogevBokobza commented 6 months ago

Still having a linting issue: src/aioswitcher/device/tools.py:188: error: Argument 1 to "bytes" has incompatible type "str | None"; expected "str" [arg-type] I am switching the token parameter from: token: Union[str, None] = None to: token: str

TomerFi commented 6 months ago

Merging - thank you everyone!