32
32
global config_path
33
33
config_path = None
34
34
35
+ WORKBENCH_CA_CERT_PATH = "/etc/pki/tls/custom-certs/ca-bundle.crt"
36
+
35
37
36
38
class Authentication (metaclass = abc .ABCMeta ):
37
39
"""
@@ -81,7 +83,7 @@ def __init__(
81
83
token : str ,
82
84
server : str ,
83
85
skip_tls : bool = False ,
84
- ca_cert_path : str = "/etc/pki/tls/custom-certs/ca-bundle.crt" ,
86
+ ca_cert_path : str = None ,
85
87
):
86
88
"""
87
89
Initialize a TokenAuthentication object that requires a value for `token`, the API Token
@@ -91,7 +93,17 @@ def __init__(
91
93
self .token = token
92
94
self .server = server
93
95
self .skip_tls = skip_tls
94
- self .ca_cert_path = ca_cert_path
96
+ self .ca_cert_path = self ._gen_ca_cert_path (ca_cert_path )
97
+
98
+ def _gen_ca_cert_path (self , ca_cert_path : str ):
99
+ if ca_cert_path is not None :
100
+ return ca_cert_path
101
+ elif "CF_SDK_CA_CERT_PATH" in os .environ :
102
+ return os .environ .get ("CF_SDK_CA_CERT_PATH" )
103
+ elif os .path .exists (WORKBENCH_CA_CERT_PATH ):
104
+ return WORKBENCH_CA_CERT_PATH
105
+ else :
106
+ return None
95
107
96
108
def login (self ) -> str :
97
109
"""
@@ -106,13 +118,9 @@ def login(self) -> str:
106
118
configuration .api_key_prefix ["authorization" ] = "Bearer"
107
119
configuration .host = self .server
108
120
configuration .api_key ["authorization" ] = self .token
109
- ca_path_env = os .environ .get ("CF_SDK_CA_CERT_PATH" , self .ca_cert_path )
110
-
111
- if self .skip_tls == False :
112
- if ca_path_env != self .ca_cert_path :
113
- self .ca_cert_path = ca_path_env
114
121
115
- if self .ca_cert_path == None :
122
+ if not self .skip_tls :
123
+ if self .ca_cert_path is None :
116
124
configuration .ssl_ca_cert = None
117
125
elif os .path .isfile (self .ca_cert_path ):
118
126
print (
0 commit comments