|
1 | 1 | import logging |
| 2 | +import warnings |
2 | 3 | from typing import Any # noqa - This is used for MyPy |
3 | 4 | from typing import Dict |
4 | 5 | from typing import List # noqa - This is used for MyPy |
|
53 | 54 | from oic.utils.keyio import KeyJar |
54 | 55 | from oic.utils.sdb import SessionBackend # noqa |
55 | 56 | from oic.utils.sdb import session_update |
| 57 | +from oic.utils.settings import OauthClientSettings |
| 58 | +from oic.utils.settings import OauthServerSettings |
| 59 | +from oic.utils.settings import PyoidcSettings |
56 | 60 | from oic.utils.time_util import utc_time_sans_frac |
57 | 61 |
|
58 | 62 | __author__ = "rohe0002" |
@@ -170,35 +174,61 @@ def __init__( |
170 | 174 | client_id=None, |
171 | 175 | client_authn_method=None, |
172 | 176 | keyjar=None, |
173 | | - verify_ssl=True, |
| 177 | + verify_ssl=None, |
174 | 178 | config=None, |
175 | 179 | client_cert=None, |
176 | | - timeout=5, |
| 180 | + timeout=None, |
177 | 181 | message_factory: Type[MessageFactory] = OauthMessageFactory, |
| 182 | + settings: PyoidcSettings = None, |
178 | 183 | ): |
179 | 184 | """ |
180 | 185 | Initialize the instance. |
181 | 186 |
|
| 187 | + Keyword Args: |
| 188 | + settings |
| 189 | + Instance of :class:`OauthClientSettings` with configuration options. |
| 190 | + Currently used settings are: |
| 191 | + - verify_ssl |
| 192 | + - client_cert |
| 193 | + - timeout |
| 194 | +
|
182 | 195 | :param client_id: The client identifier |
183 | 196 | :param client_authn_method: Methods that this client can use to |
184 | 197 | authenticate itself. It's a dictionary with method names as |
185 | 198 | keys and method classes as values. |
186 | 199 | :param keyjar: The keyjar for this client. |
187 | | - :param verify_ssl: Whether the SSL certificate should be verified. |
188 | | - :param client_cert: A client certificate to use. |
| 200 | + :param verify_ssl: Whether the SSL certificate should be verified. Deprecated in favor of settings. |
| 201 | + :param client_cert: A client certificate to use. Deprecated in favor of settings. |
189 | 202 | :param timeout: Timeout for requests library. Can be specified either as |
190 | 203 | a single integer or as a tuple of integers. For more details, refer to |
191 | | - ``requests`` documentation. |
| 204 | + ``requests`` documentation. Deprecated in favor of settings. |
192 | 205 | :param: message_factory: Factory for message classes, should inherit from OauthMessageFactory |
193 | 206 | :return: Client instance |
| 207 | +
|
194 | 208 | """ |
195 | | - PBase.__init__( |
196 | | - self, |
197 | | - verify_ssl=verify_ssl, |
198 | | - keyjar=keyjar, |
199 | | - client_cert=client_cert, |
200 | | - timeout=timeout, |
201 | | - ) |
| 209 | + self.settings = settings or OauthClientSettings() |
| 210 | + if verify_ssl is not None: |
| 211 | + warnings.warn( |
| 212 | + "`verify_ssl` is deprecated, please use `settings` instead if you need to set a non-default value.", |
| 213 | + DeprecationWarning, |
| 214 | + stacklevel=2, |
| 215 | + ) |
| 216 | + self.settings.verify_ssl = verify_ssl |
| 217 | + if client_cert is not None: |
| 218 | + warnings.warn( |
| 219 | + "`client_cert` is deprecated, please use `settings` instead if you need to set a non-default value.", |
| 220 | + DeprecationWarning, |
| 221 | + stacklevel=2, |
| 222 | + ) |
| 223 | + self.settings.client_cert = client_cert |
| 224 | + if timeout is not None: |
| 225 | + warnings.warn( |
| 226 | + "`timeout` is deprecated, please use `settings` instead if you need to set a non-default value.", |
| 227 | + DeprecationWarning, |
| 228 | + stacklevel=2, |
| 229 | + ) |
| 230 | + self.settings.timeout = timeout |
| 231 | + PBase.__init__(self, keyjar=keyjar, settings=self.settings) |
202 | 232 |
|
203 | 233 | self.sso_db = None # type: Optional[SessionBackend] |
204 | 234 | self.client_id = client_id |
@@ -1119,19 +1149,44 @@ class Server(PBase): |
1119 | 1149 |
|
1120 | 1150 | def __init__( |
1121 | 1151 | self, |
1122 | | - verify_ssl: bool = True, |
| 1152 | + verify_ssl: bool = None, |
1123 | 1153 | keyjar: KeyJar = None, |
1124 | 1154 | client_cert: Union[str, Tuple[str, str]] = None, |
1125 | | - timeout: int = 5, |
| 1155 | + timeout: float = None, |
1126 | 1156 | message_factory: Type[MessageFactory] = OauthMessageFactory, |
| 1157 | + settings: PyoidcSettings = None, |
1127 | 1158 | ): |
1128 | | - """Initialize the server.""" |
1129 | | - super().__init__( |
1130 | | - verify_ssl=verify_ssl, |
1131 | | - keyjar=keyjar, |
1132 | | - client_cert=client_cert, |
1133 | | - timeout=timeout, |
1134 | | - ) |
| 1159 | + """ |
| 1160 | + Initialize the server. |
| 1161 | +
|
| 1162 | + Keyword Args: |
| 1163 | + settings |
| 1164 | + Instance of :class:`OauthServerSettings` with configuration options. |
| 1165 | +
|
| 1166 | + """ |
| 1167 | + self.settings = settings or OauthServerSettings() |
| 1168 | + if verify_ssl is not None: |
| 1169 | + warnings.warn( |
| 1170 | + "`verify_ssl` is deprecated, please use `settings` instead if you need to set a non-default value.", |
| 1171 | + DeprecationWarning, |
| 1172 | + stacklevel=2, |
| 1173 | + ) |
| 1174 | + self.settings.verify_ssl = verify_ssl |
| 1175 | + if client_cert is not None: |
| 1176 | + warnings.warn( |
| 1177 | + "`client_cert` is deprecated, please use `settings` instead if you need to set a non-default value.", |
| 1178 | + DeprecationWarning, |
| 1179 | + stacklevel=2, |
| 1180 | + ) |
| 1181 | + self.settings.client_cert = client_cert |
| 1182 | + if timeout is not None: |
| 1183 | + warnings.warn( |
| 1184 | + "`timeout` is deprecated, please use `settings` instead if you need to set a non-default value.", |
| 1185 | + DeprecationWarning, |
| 1186 | + stacklevel=2, |
| 1187 | + ) |
| 1188 | + self.settings.timeout = timeout |
| 1189 | + super().__init__(keyjar=keyjar, settings=self.settings) |
1135 | 1190 | self.message_factory = message_factory |
1136 | 1191 |
|
1137 | 1192 | @staticmethod |
|
0 commit comments