Skip to content

Commit

Permalink
Allow boolean values in the cert parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
damian3031 committed Dec 11, 2024
1 parent dfaa905 commit 8b6f0e7
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 deletions.
7 changes: 7 additions & 0 deletions .changes/unreleased/Fixes-20241211-202907.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
kind: Fixes
body: Allow boolean values in the cert parameter
time: 2024-12-11T20:29:07.954737+01:00
custom:
Author: damian3031
Issue: ""
PR: "460"
16 changes: 8 additions & 8 deletions dbt/adapters/trino/connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from dataclasses import dataclass, field
from datetime import date, datetime
from enum import Enum
from typing import Any, Dict, List, Optional
from typing import Any, Dict, List, Optional, Union

import sqlparse
import trino
Expand Down Expand Up @@ -99,7 +99,7 @@ class TrinoNoneCredentials(TrinoCredentials):
user: str
client_tags: Optional[List[str]] = None
roles: Optional[Dict[str, str]] = None
cert: Optional[str] = None
cert: Optional[Union[str, bool]] = None
http_scheme: HttpScheme = HttpScheme.HTTP
http_headers: Optional[Dict[str, str]] = None
session_properties: Dict[str, Any] = field(default_factory=dict)
Expand All @@ -124,7 +124,7 @@ class TrinoCertificateCredentials(TrinoCredentials):
user: Optional[str] = None
client_tags: Optional[List[str]] = None
roles: Optional[Dict[str, str]] = None
cert: Optional[str] = None
cert: Optional[Union[str, bool]] = None
http_headers: Optional[Dict[str, str]] = None
session_properties: Dict[str, Any] = field(default_factory=dict)
prepared_statements_enabled: bool = PREPARED_STATEMENTS_ENABLED_DEFAULT
Expand Down Expand Up @@ -154,7 +154,7 @@ class TrinoLdapCredentials(TrinoCredentials):
impersonation_user: Optional[str] = None
client_tags: Optional[List[str]] = None
roles: Optional[Dict[str, str]] = None
cert: Optional[str] = None
cert: Optional[Union[str, bool]] = None
http_headers: Optional[Dict[str, str]] = None
session_properties: Dict[str, Any] = field(default_factory=dict)
prepared_statements_enabled: bool = PREPARED_STATEMENTS_ENABLED_DEFAULT
Expand Down Expand Up @@ -185,7 +185,7 @@ class TrinoKerberosCredentials(TrinoCredentials):
krb5_config: Optional[str] = None
service_name: Optional[str] = "trino"
mutual_authentication: Optional[bool] = False
cert: Optional[str] = None
cert: Optional[Union[str, bool]] = None
http_headers: Optional[Dict[str, str]] = None
force_preemptive: Optional[bool] = False
hostname_override: Optional[str] = None
Expand Down Expand Up @@ -227,7 +227,7 @@ class TrinoJwtCredentials(TrinoCredentials):
user: Optional[str] = None
client_tags: Optional[List[str]] = None
roles: Optional[Dict[str, str]] = None
cert: Optional[str] = None
cert: Optional[Union[str, bool]] = None
http_headers: Optional[Dict[str, str]] = None
session_properties: Dict[str, Any] = field(default_factory=dict)
prepared_statements_enabled: bool = PREPARED_STATEMENTS_ENABLED_DEFAULT
Expand All @@ -253,7 +253,7 @@ class TrinoOauthCredentials(TrinoCredentials):
user: Optional[str] = None
client_tags: Optional[List[str]] = None
roles: Optional[Dict[str, str]] = None
cert: Optional[str] = None
cert: Optional[Union[str, bool]] = None
http_headers: Optional[Dict[str, str]] = None
session_properties: Dict[str, Any] = field(default_factory=dict)
prepared_statements_enabled: bool = PREPARED_STATEMENTS_ENABLED_DEFAULT
Expand Down Expand Up @@ -282,7 +282,7 @@ class TrinoOauthConsoleCredentials(TrinoCredentials):
user: Optional[str] = None
client_tags: Optional[List[str]] = None
roles: Optional[Dict[str, str]] = None
cert: Optional[str] = None
cert: Optional[Union[str, bool]] = None
http_headers: Optional[Dict[str, str]] = None
session_properties: Dict[str, Any] = field(default_factory=dict)
prepared_statements_enabled: bool = PREPARED_STATEMENTS_ENABLED_DEFAULT
Expand Down
8 changes: 4 additions & 4 deletions tests/unit/test_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ def test_none_authentication_without_http_scheme(self):
"method": "none",
"schema": "dbt_test_schema",
"user": "trino_user",
"cert": "/path/to/cert",
"cert": True,
"client_tags": ["dev", "without_http_scheme"],
"http_headers": {"X-Trino-Client-Info": "dbt-trino"},
"session_properties": {
Expand All @@ -243,7 +243,7 @@ def test_none_authentication_without_http_scheme(self):
self.assert_default_connection_credentials(credentials)
self.assertIsInstance(credentials, TrinoNoneCredentials)
self.assertEqual(credentials.http_scheme, HttpScheme.HTTP)
self.assertEqual(credentials.cert, "/path/to/cert")
self.assertEqual(credentials.cert, True)
self.assertEqual(credentials.client_tags, ["dev", "without_http_scheme"])
self.assertEqual(credentials.timezone, "UTC")

Expand All @@ -261,7 +261,7 @@ def test_ldap_authentication(self):
"user": "trino_user",
"impersonation_user": "impersonated_user" if is_impersonation else None,
"password": "trino_password",
"cert": "/path/to/cert",
"cert": False,
"client_tags": ["dev", "ldap"],
"http_headers": {"X-Trino-Client-Info": "dbt-trino"},
"session_properties": {
Expand All @@ -276,7 +276,7 @@ def test_ldap_authentication(self):
self.assertIsInstance(credentials, TrinoLdapCredentials)
self.assert_default_connection_credentials(credentials)
self.assertEqual(credentials.http_scheme, HttpScheme.HTTPS)
self.assertEqual(credentials.cert, "/path/to/cert")
self.assertEqual(credentials.cert, False)
self.assertEqual(connection.handle.handle.user, expected_user)
self.assertEqual(credentials.client_tags, ["dev", "ldap"])
self.assertEqual(credentials.timezone, "UTC")
Expand Down

0 comments on commit 8b6f0e7

Please sign in to comment.