EDGE-613 Fix Cognite client certificate auth#544
Conversation
…OAuthClientCertificate
There was a problem hiding this comment.
Code Review
This pull request updates the return type annotation of _load_certificate_data to always return bytes, and updates the certificate loading logic to decode bytes to UTF-8 strings. The reviewer suggested using the more idiomatic .decode("utf-8") method instead of str(bytes, "utf-8") when converting the certificate thumbprint and key to strings.
| cert_thumbprint=str(thumprint, "utf-8"), | ||
| certificate=str(key, "utf-8"), |
There was a problem hiding this comment.
Using str(bytes, "utf-8") is unidiomatic in Python. It is highly recommended to use .decode("utf-8") instead, which is the standard and more readable way to convert bytes to a string.
| cert_thumbprint=str(thumprint, "utf-8"), | |
| certificate=str(key, "utf-8"), | |
| cert_thumbprint=thumprint.decode("utf-8"), | |
| certificate=key.decode("utf-8"), |
There was a problem hiding this comment.
as the functionality remains same for key.decode("utf-8") and str(key, "utf-8"), thinking str seemed to convey that it converts to a string better, i retained it.
| cert_thumbprint=str(thumbprint, "utf-8"), | ||
| certificate=str(key, "utf-8"), |
There was a problem hiding this comment.
Using str(bytes, "utf-8") is unidiomatic in Python. It is highly recommended to use .decode("utf-8") instead, which is the standard and more readable way to convert bytes to a string.
| cert_thumbprint=str(thumbprint, "utf-8"), | |
| certificate=str(key, "utf-8"), | |
| cert_thumbprint=thumbprint.decode("utf-8"), | |
| certificate=key.decode("utf-8"), |
There was a problem hiding this comment.
as the functionality remains same for key.decode("utf-8") and str(key, "utf-8"), thinking str seemed to convey that it converts to a string better, i retained it.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #544 +/- ##
==========================================
+ Coverage 83.08% 83.43% +0.35%
==========================================
Files 45 45
Lines 4522 4522
==========================================
+ Hits 3757 3773 +16
+ Misses 765 749 -16
🚀 New features to boost your workflow:
|
…tor-utils into EDGE-613-cognite-cert-auth
nithinb
left a comment
There was a problem hiding this comment.
I know this is in draft now but a couple of things:
- add integration test
- include version bump in that so you can update the extractor right after this
nithinb
left a comment
There was a problem hiding this comment.
just two minor changes and a nit. Nit can be addressed later if you want
updated the change log to specify the certicate auth is towards CDF.
Background
This is in act of addressing one of the customer issues with cognite client certificate authentication failure where the error log showed,
binascii.Error: Odd-length string, which happens when the thumbprint has an odd-length which was happening because theConnectionConfig.get_cognite_client()was using barestr()on the incoming bytes from_load_certificate_datafunction.Reference to the ticket: https://cognitedata.atlassian.net/browse/CDFBUG-1577
Summary
This PR adds the change to address the issue along with the unit and integration tests.
Test plan