Skip to content
2 changes: 1 addition & 1 deletion cognite/extractorutils/configtools/_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def translate_camel(key: str) -> str:
raise ValueError(f"Invalid case style: {case_style}")


def _load_certificate_data(cert_path: str | Path, password: str | None) -> tuple[str, str] | tuple[bytes, bytes]:
def _load_certificate_data(cert_path: str | Path, password: str | None) -> tuple[bytes, bytes]:
path = Path(cert_path) if isinstance(cert_path, str) else cert_path
cert_data = Path(path).read_bytes()

Expand Down
4 changes: 2 additions & 2 deletions cognite/extractorutils/configtools/elements.py
Original file line number Diff line number Diff line change
Expand Up @@ -444,8 +444,8 @@ def get_cognite_client(
credential_provider = OAuthClientCertificate(
authority_url=authority_url,
client_id=self.idp_authentication.client_id,
cert_thumbprint=str(thumprint),
certificate=str(key),
cert_thumbprint=str(thumprint, "utf-8"),
Comment thread
Yaseen-A-Khan marked this conversation as resolved.
certificate=str(key, "utf-8"),
Comment on lines +447 to +448

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

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.

Suggested change
cert_thumbprint=str(thumprint, "utf-8"),
certificate=str(key, "utf-8"),
cert_thumbprint=thumprint.decode("utf-8"),
certificate=key.decode("utf-8"),

@Yaseen-A-Khan Yaseen-A-Khan Jun 29, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.

scopes=self.idp_authentication.scopes,
)

Expand Down
4 changes: 2 additions & 2 deletions cognite/extractorutils/unstable/configuration/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,8 +328,8 @@ def get_cognite_client(self, client_name: str) -> CogniteClient:
credential_provider = OAuthClientCertificate(
authority_url=client_certificate.authority_url,
client_id=client_certificate.client_id,
cert_thumbprint=str(thumbprint),
certificate=str(key),
cert_thumbprint=str(thumbprint, "utf-8"),
certificate=str(key, "utf-8"),
Comment on lines +331 to +332

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

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.

Suggested change
cert_thumbprint=str(thumbprint, "utf-8"),
certificate=str(key, "utf-8"),
cert_thumbprint=thumbprint.decode("utf-8"),
certificate=key.decode("utf-8"),

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.

scopes=list(client_certificate.scopes),
)

Expand Down
Loading