Skip to content

Commit 10fcf32

Browse files
committed
refactor(iam_helper): simplify validation of sslmode connection parameter
1 parent 5431276 commit 10fcf32

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

redshift_connector/iam_helper.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,18 @@
1717
_logger: logging.Logger = logging.getLogger(__name__)
1818

1919

20-
class SSLMode(Enum):
20+
class SupportedSSLMode(Enum):
2121
VERIFY_CA: str = "verify-ca"
2222
VERIFY_FULL: str = "verify-full"
2323

24+
@staticmethod
25+
def default() -> str:
26+
return SupportedSSLMode.VERIFY_CA.value
27+
28+
@staticmethod
29+
def list() -> typing.List[str]:
30+
return list(map(lambda mode: mode.value, SupportedSSLMode))
31+
2432

2533
def dynamic_plugin_import(name: str):
2634
components = name.split(".")
@@ -83,12 +91,15 @@ def set_iam_properties(
8391
# Make sure that is set to SSL level VERIFY_CA or higher.
8492
info.ssl = ssl
8593
if info.ssl is True:
86-
if sslmode == SSLMode.VERIFY_CA.value:
87-
info.sslmode = SSLMode.VERIFY_CA.value
88-
elif sslmode == SSLMode.VERIFY_FULL.value:
89-
info.sslmode = SSLMode.VERIFY_FULL.value
94+
if sslmode not in SupportedSSLMode.list():
95+
info.sslmode = SupportedSSLMode.default()
96+
_logger.debug(
97+
"A non-supported value: {} was provides for sslmode. Falling back to default value: {}".format(
98+
sslmode, SupportedSSLMode.default()
99+
)
100+
)
90101
else:
91-
info.sslmode = SSLMode.VERIFY_CA.value
102+
info.sslmode = sslmode
92103
else:
93104
info.sslmode = ""
94105

redshift_connector/redshift_property.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
import typing
2-
from typing import TYPE_CHECKING
32

43
from redshift_connector.config import DEFAULT_PROTOCOL_VERSION
54

6-
if TYPE_CHECKING:
7-
from redshift_connector.iam_helper import SSLMode
8-
95

106
class RedshiftProperty:
117
iam: bool = False

0 commit comments

Comments
 (0)