Skip to content

Commit e088ad2

Browse files
committed
Rename validate_certs and only_safe_calls
There are other more common names in use in the outer layers.
1 parent 317f29f commit e088ad2

File tree

7 files changed

+49
-33
lines changed

7 files changed

+49
-33
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Rename the `PulpContext` `api_kwargs` parameters `validate_certs` to `verify_ssl` and `safe_calls_only` to `dry_run`.

pulp-glue/pulp_glue/common/authentication.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ def __init__(
1616
client_secret: str,
1717
token_url: str,
1818
scopes: t.Optional[t.List[str]] = None,
19-
verify: t.Optional[t.Union[str, bool]] = None,
19+
verify_ssl: t.Optional[t.Union[str, bool]] = None,
2020
):
2121
self._token_server_auth = requests.auth.HTTPBasicAuth(client_id, client_secret)
2222
self._token_url = token_url
2323
self._scopes = scopes
24-
self._verify = verify
24+
self._verify_ssl = verify_ssl
2525

2626
self._access_token: t.Optional[str] = None
2727
self._expire_at: t.Optional[datetime] = None
@@ -87,7 +87,7 @@ def _retrieve_token(self) -> None:
8787
self._token_url,
8888
data=data,
8989
auth=self._token_server_auth,
90-
verify=self._verify,
90+
verify=self._verify_ssl,
9191
)
9292

9393
response.raise_for_status()

pulp-glue/pulp_glue/common/context.py

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -216,8 +216,8 @@ class PulpContext:
216216
domain: Name of the domain to interact with.
217217
fake_mode: In fake mode, no modifying calls will be performed.
218218
Where possible, instead of failing, the requested result will be faked.
219-
This implies `safe_calls_only=True` on the `api_kwargs`.
220-
verify: A boolean or a path to the CA bundle.
219+
This implies `dry_run=True` on the `api_kwargs`.
220+
verify_ssl: A boolean or a path to the CA bundle.
221221
"""
222222

223223
def echo(self, message: str, nl: bool = True, err: bool = False) -> None:
@@ -246,18 +246,21 @@ def __init__(
246246
timeout: t.Union[int, datetime.timedelta] = 300,
247247
domain: str = "default",
248248
fake_mode: bool = False,
249-
verify: t.Optional[t.Union[bool, str]] = None,
249+
verify_ssl: t.Optional[t.Union[bool, str]] = None,
250+
verify: t.Optional[t.Union[bool, str]] = None, # Deprecated
250251
) -> None:
251252
self._api: t.Optional[OpenAPI] = None
252253
self._api_root: str = api_root
253254
self._api_kwargs = api_kwargs
254-
self.verify = verify
255-
if self.verify is None:
255+
self.verify_ssl = verify_ssl
256+
if self.verify_ssl is None:
256257
# Regrets, regrets...
257-
self.verify = self._api_kwargs.pop("validate_certs", True)
258-
if self.verify is True:
258+
self.verify_ssl = (
259+
verify if verify is not None else self._api_kwargs.pop("validate_certs", True)
260+
)
261+
if self.verify_ssl is True:
259262
# If this is "only" true and we have the PULP_CA_BUNDLE variable set, use it.
260-
self.verify = os.environ.get("PULP_CA_BUNDLE", True)
263+
self.verify_ssl = os.environ.get("PULP_CA_BUNDLE", True)
261264
self._needed_plugins: t.List[PluginRequirement] = [
262265
PluginRequirement("core", specifier=">=3.11.0")
263266
]
@@ -269,7 +272,7 @@ def __init__(
269272
self.timeout: datetime.timedelta = timeout
270273
self.fake_mode: bool = fake_mode
271274
if self.fake_mode:
272-
self._api_kwargs["safe_calls_only"] = True
275+
self._api_kwargs["dry_run"] = True
273276

274277
@classmethod
275278
def from_config_files(
@@ -338,19 +341,14 @@ def from_config(cls, config: t.Dict[str, t.Any]) -> "t.Self":
338341
api_kwargs["headers"] = dict(
339342
(header.split(":", maxsplit=1) for header in config["headers"])
340343
)
341-
for key in ["cert", "key", "user_agent", "cid"]:
344+
for key in ["cert", "key", "user_agent", "cid", "dry_run"]:
342345
if key in config:
343346
api_kwargs[key] = config[key]
344-
for key0, key1 in [
345-
["verify_ssl", "validate_certs"],
346-
["dry_run", "safe_calls_only"],
347-
]:
348-
if key0 in config:
349-
api_kwargs[key1] = config[key0]
350347

351348
return cls(
352349
api_root=config.get("api_root", "/pulp/"),
353350
domain=config.get("domain", "default"),
351+
verify_ssl=config.get("verify_ssl", True),
354352
api_kwargs=api_kwargs,
355353
)
356354

@@ -396,7 +394,7 @@ def api(self) -> OpenAPI:
396394
try:
397395
self._api = OpenAPI(
398396
doc_path=f"{self._api_root}api/v3/docs/api.json",
399-
verify=self.verify,
397+
verify_ssl=self.verify_ssl,
400398
**self._api_kwargs,
401399
)
402400
except OpenAPIError as e:

pulp-glue/pulp_glue/common/openapi.py

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import json
55
import os
66
import typing as t
7+
import warnings
78
from collections import defaultdict
89
from dataclasses import dataclass
910
from io import BufferedReader
@@ -147,12 +148,14 @@ class OpenAPI:
147148
auth_provider: Object that returns requests auth objects according to the api spec.
148149
cert: Client certificate used for auth.
149150
key: Matching key for `cert` if not already included.
150-
verify: Whether to check server TLS certificates agains a CA (requests semantic).
151+
verify_ssl: Whether to check server TLS certificates agains a CA (requests semantic).
151152
refresh_cache: Whether to fetch the api doc regardless.
152-
safe_calls_only: Flag to disallow issuing POST, PUT, PATCH or DELETE calls.
153+
dry_run: Flag to disallow issuing POST, PUT, PATCH or DELETE calls.
153154
debug_callback: Callback that will be called with strings useful for logging or debugging.
154155
user_agent: String to use in the User-Agent header.
155156
cid: Correlation ID to send with all requests.
157+
validate_certs: DEPRECATED use verify_ssl instead.
158+
safe_calls_only: DEPRECATED use dry_run instead.
156159
"""
157160

158161
def __init__(
@@ -163,19 +166,28 @@ def __init__(
163166
auth_provider: t.Optional[AuthProviderBase] = None,
164167
cert: t.Optional[str] = None,
165168
key: t.Optional[str] = None,
166-
verify: t.Optional[t.Union[bool, str]] = True,
169+
verify_ssl: t.Optional[t.Union[bool, str]] = True,
167170
refresh_cache: bool = False,
168-
safe_calls_only: bool = False,
171+
dry_run: bool = False,
169172
debug_callback: t.Optional[t.Callable[[int, str], t.Any]] = None,
170173
user_agent: t.Optional[str] = None,
171174
cid: t.Optional[str] = None,
175+
validate_certs: t.Optional[bool] = None,
176+
safe_calls_only: t.Optional[bool] = None,
172177
):
178+
if validate_certs is not None:
179+
warnings.warn("validate_certs is deprecated; use verify_ssl instead.")
180+
verify_ssl = validate_certs
181+
if safe_calls_only is not None:
182+
warnings.warn("safe_calls_only is deprecated; use dry_run instead.")
183+
dry_run = safe_calls_only
184+
173185
self._debug_callback: t.Callable[[int, str], t.Any] = debug_callback or (lambda i, x: None)
174186
self._base_url: str = base_url
175187
self._doc_path: str = doc_path
176-
self._safe_calls_only: bool = safe_calls_only
188+
self._dry_run: bool = dry_run
177189
self._headers = CIMultiDict(headers or {})
178-
self._verify = verify
190+
self._verify_ssl = verify_ssl
179191
self._auth_provider = auth_provider
180192
self._cert = cert
181193
self._key = key
@@ -196,7 +208,7 @@ def __init__(
196208
def _setup_session(self) -> None:
197209
# This is specific requests library.
198210

199-
if self._verify is False:
211+
if self._verify_ssl is False:
200212
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
201213

202214
self._session: requests.Session = requests.session()
@@ -214,7 +226,7 @@ def _setup_session(self) -> None:
214226
elif self._key:
215227
raise OpenAPIError(_("Cert is required if key is set."))
216228
session_settings = self._session.merge_environment_settings(
217-
self._base_url, {}, None, self._verify, None
229+
self._base_url, {}, None, self._verify_ssl, None
218230
)
219231
self._session.verify = session_settings["verify"]
220232
self._session.proxies = session_settings["proxies"]
@@ -511,7 +523,7 @@ def _send_request(
511523
self._debug_callback(2, f" {key}: {value}")
512524
if request.body is not None:
513525
self._debug_callback(3, f"{request.body!r}")
514-
if self._safe_calls_only and method.upper() not in SAFE_METHODS:
526+
if self._dry_run and method.upper() not in SAFE_METHODS:
515527
raise UnsafeCallError(_("Call aborted due to safe mode"))
516528
try:
517529
response = self._session.send(request)

pulp_cli/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,9 +217,9 @@ def _debug_callback(level: int, x: str) -> None:
217217
headers=dict((header.split(":", maxsplit=1) for header in headers)),
218218
cert=cert,
219219
key=key,
220-
validate_certs=verify_ssl,
220+
verify_ssl=verify_ssl,
221221
refresh_cache=refresh_api,
222-
safe_calls_only=dry_run,
222+
dry_run=dry_run,
223223
debug_callback=_debug_callback,
224224
user_agent=f"Pulp-CLI/{__version__}",
225225
cid=cid,

pulp_cli/config.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,8 @@ def validate_config(config: t.Dict[str, t.Any], strict: bool = False) -> None:
155155
errors.append(_("'api_root' must begin and end with '/'"))
156156
if "format" in config and config["format"].lower() not in FORMAT_CHOICES:
157157
errors.append(_("'format' is not one of {choices}").format(choices=FORMAT_CHOICES))
158+
if "verify_ssl" in config and not isinstance(config["verify_ssl"], bool):
159+
errors.append(_("'verify_ssl' is not a bool"))
158160
if "dry_run" in config and not isinstance(config["dry_run"], bool):
159161
errors.append(_("'dry_run' is not a bool"))
160162
if "timeout" in config and not isinstance(config["timeout"], int):

pulp_cli/generic.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,12 @@ def __init__(
144144
self.oauth2_client_secret = oauth2_client_secret
145145
if not api_kwargs.get("cert"):
146146
api_kwargs["auth_provider"] = PulpCLIAuthProvider(pulp_ctx=self)
147+
148+
verify_ssl: t.Optional[bool] = api_kwargs.pop("verify_ssl", None)
147149
super().__init__(
148150
api_root=api_root,
149151
api_kwargs=api_kwargs,
152+
verify_ssl=verify_ssl,
150153
background_tasks=background_tasks,
151154
timeout=timeout,
152155
domain=domain,
@@ -269,7 +272,7 @@ def oauth2_client_credentials_auth(
269272
token_url=flow["tokenUrl"],
270273
# Try to request all possible scopes.
271274
scopes=flow["scopes"],
272-
verify=self.pulp_ctx.verify,
275+
verify_ssl=self.pulp_ctx.verify_ssl,
273276
)
274277
else:
275278
self._memoized[key] = OAuth2ClientCredentialsAuth(
@@ -278,7 +281,7 @@ def oauth2_client_credentials_auth(
278281
token_url=flow["tokenUrl"],
279282
# Try to request all possible scopes.
280283
scopes=flow["scopes"],
281-
verify=self.pulp_ctx.verify,
284+
verify_ssl=self.pulp_ctx.verify_ssl,
282285
)
283286
return self._memoized[key]
284287

0 commit comments

Comments
 (0)