Skip to content

Commit 0c2fc24

Browse files
committed
Add PulpException for ssl CA verification error in replication
1 parent 0d3fa50 commit 0c2fc24

File tree

3 files changed

+67
-37
lines changed

3 files changed

+67
-37
lines changed

pulpcore/app/tasks/replica.py

Lines changed: 45 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import os
22
import platform
3+
import requests
34
import sys
45
from tempfile import NamedTemporaryFile
56

@@ -9,6 +10,7 @@
910
from pulpcore.app.apps import pulp_plugin_configs, PulpAppConfig
1011
from pulpcore.app.models import UpstreamPulp, Task, TaskGroup
1112
from pulpcore.app.replica import ReplicaContext
13+
from pulpcore.exceptions.base import SSLCertificateVerificationError
1214
from pulpcore.tasking.tasks import dispatch
1315

1416
from pulp_glue.common import __version__ as pulp_glue_version
@@ -68,43 +70,49 @@ def replicate_distributions(server_pk):
6870

6971
task_group = TaskGroup.current()
7072
supported_replicators = []
71-
# Load all the available replicators
72-
for config in pulp_plugin_configs():
73-
if config.replicator_classes:
74-
for replicator_class in config.replicator_classes:
75-
req = PluginRequirement(config.label, specifier=replicator_class.required_version)
76-
if ctx.has_plugin(req):
77-
replicator = replicator_class(ctx, task_group, tls_settings, server)
78-
supported_replicators.append(replicator)
79-
80-
for replicator in supported_replicators:
81-
distros = replicator.upstream_distributions(q=server.q_select)
82-
distro_names = []
83-
for distro in distros:
84-
# Create remote
85-
remote = replicator.create_or_update_remote(upstream_distribution=distro)
86-
if not remote:
87-
# The upstream distribution is not serving any content,
88-
# let if fall through the cracks and be cleanup below.
89-
continue
90-
# Check if there is already a repository
91-
repository = replicator.create_or_update_repository(remote=remote)
92-
if not repository:
93-
# No update occured because server.policy==LABELED and there was
94-
# an already existing local repository with the same name
95-
continue
96-
97-
# Dispatch a sync task if needed
98-
if replicator.requires_syncing(distro):
99-
replicator.sync(repository, remote)
100-
101-
# Get or create a distribution
102-
replicator.create_or_update_distribution(repository, distro)
103-
104-
# Add name to the list of known distribution names
105-
distro_names.append(distro["name"])
106-
107-
replicator.remove_missing(distro_names)
73+
try:
74+
# Load all the available replicators
75+
for config in pulp_plugin_configs():
76+
if config.replicator_classes:
77+
for replicator_class in config.replicator_classes:
78+
req = PluginRequirement(
79+
config.label, specifier=replicator_class.required_version
80+
)
81+
if ctx.has_plugin(req):
82+
replicator = replicator_class(ctx, task_group, tls_settings, server)
83+
supported_replicators.append(replicator)
84+
85+
for replicator in supported_replicators:
86+
distros = replicator.upstream_distributions(q=server.q_select)
87+
distro_names = []
88+
for distro in distros:
89+
# Create remote
90+
remote = replicator.create_or_update_remote(upstream_distribution=distro)
91+
if not remote:
92+
# The upstream distribution is not serving any content,
93+
# let if fall through the cracks and be cleanup below.
94+
continue
95+
# Check if there is already a repository
96+
repository = replicator.create_or_update_repository(remote=remote)
97+
if not repository:
98+
# No update occured because server.policy==LABELED and there was
99+
# an already existing local repository with the same name
100+
continue
101+
102+
# Dispatch a sync task if needed
103+
if replicator.requires_syncing(distro):
104+
replicator.sync(repository, remote)
105+
106+
# Get or create a distribution
107+
replicator.create_or_update_distribution(repository, distro)
108+
109+
# Add name to the list of known distribution names
110+
distro_names.append(distro["name"])
111+
112+
replicator.remove_missing(distro_names)
113+
# TEST, NEEDS TO BE REMOVED
114+
except requests.exceptions.SSLError:
115+
raise SSLCertificateVerificationError(server.base_url) # Custom PulpException for this case
108116

109117
dispatch(
110118
finalize_replication,

pulpcore/exceptions/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
UrlSchemeNotSupportedError,
99
ProxyAuthenticationRequiredError,
1010
RepositoryVersionDeleteError,
11+
SSLCertificateVerificationError,
1112
)
1213
from .validation import (
1314
DigestValidationError,

pulpcore/exceptions/base.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,3 +166,24 @@ def __str__(self):
166166
"Cannot delete repository version. Repositories must have at least one "
167167
"repository version."
168168
)
169+
170+
171+
class SSLCertificateVerificationError(PulpException):
172+
"""
173+
Exception raised when SSL certificate verification fails due to incorrect
174+
CA certificate configuration by the user.
175+
"""
176+
177+
def __init__(self, url):
178+
"""
179+
:param url: The URL where certificate verification failed.
180+
:type url: str
181+
"""
182+
super().__init__("PLP0012")
183+
self.url = url
184+
185+
def __str__(self):
186+
return _(
187+
"SSL certificate verification failed for {url}. "
188+
"The configured CA certificate does not match the server's certificate. "
189+
).format(url=self.url)

0 commit comments

Comments
 (0)