Skip to content

Commit e24e77a

Browse files
cachito-nexus: Add compatibility toggle for versions that use orientDB
Nexus has changed the embedded database from versions 3.71.0 forward¹. The older versions used orientDB, which require a small change in the URL when searching for component data. This patch adds a configuration option so that Cachito can handle both versions Nexus. ¹https://help.sonatype.com/en/sonatype-nexus-repository-3-71-0-release-notes.html Signed-off-by: Bruno Pimentel <[email protected]>
1 parent fe2ef76 commit e24e77a

File tree

2 files changed

+35
-3
lines changed

2 files changed

+35
-3
lines changed

cachito/workers/config.py

+2
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,15 @@ class Config(object):
5050
cachito_nexus_hoster_password: Optional[str] = None
5151
cachito_nexus_hoster_url: Optional[str] = None
5252
cachito_nexus_hoster_username: Optional[str] = None
53+
cachito_nexus_hoster_is_orient_db = False
5354
cachito_nexus_js_hosted_repo_name = "cachito-js-hosted"
5455
cachito_nexus_max_search_attempts = 5
5556
cachito_nexus_npm_proxy_url = "http://localhost:8081/repository/cachito-js/"
5657
cachito_nexus_pip_raw_repo_name = "cachito-pip-raw"
5758
cachito_nexus_rubygems_raw_repo_name = "cachito-rubygems-raw"
5859
cachito_nexus_proxy_password: Optional[str] = None
5960
cachito_nexus_proxy_username: Optional[str] = None
61+
cachito_nexus_proxy_is_orient_db = False
6062
cachito_nexus_request_repo_prefix = "cachito-"
6163
cachito_nexus_timeout = 60
6264
cachito_nexus_username = "cachito"

cachito/workers/nexus.py

+33-3
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,30 @@ def get_component_info_from_nexus(
267267
return None
268268

269269

270+
def _get_nexus_orient_db_configuration():
271+
config = get_worker_config()
272+
return config.cachito_nexus_hoster_is_orient_db, config.cachito_nexus_proxy_is_orient_db
273+
274+
275+
def _treat_raw_component_name(name, is_nexus_hoster):
276+
"""
277+
Treats the raw component name based on the use of orientDB by Nexus.
278+
279+
Starting from v3.71.0, Nexus has dropped the use of orientDB in favor of H2, which forces
280+
all raw component names to have a leading slash. This function works as a compatibility layer
281+
for orientDB, removing the leading slash.
282+
"""
283+
nexus_hoster_is_orient_db, nexus_proxy_is_orient_db = _get_nexus_orient_db_configuration()
284+
285+
if is_nexus_hoster and nexus_hoster_is_orient_db:
286+
return name[1:]
287+
288+
if not is_nexus_hoster and nexus_proxy_is_orient_db:
289+
return name[1:]
290+
291+
return name
292+
293+
270294
def get_raw_component_asset_url(repository, name, max_attempts=1, from_nexus_hoster=True):
271295
"""
272296
Get download URL for the asset of a raw component.
@@ -281,8 +305,14 @@ def get_raw_component_asset_url(repository, name, max_attempts=1, from_nexus_hos
281305
available
282306
:return: download URL for the asset, or None if component was not found
283307
"""
308+
treated_name = _treat_raw_component_name(name, from_nexus_hoster)
309+
284310
component = get_component_info_from_nexus(
285-
repository, "raw", name, max_attempts=max_attempts, from_nexus_hoster=from_nexus_hoster
311+
repository,
312+
"raw",
313+
treated_name,
314+
max_attempts=max_attempts,
315+
from_nexus_hoster=from_nexus_hoster,
286316
)
287317
if component is None:
288318
return None
@@ -291,10 +321,10 @@ def get_raw_component_asset_url(repository, name, max_attempts=1, from_nexus_hos
291321

292322
# Sanity checks, in practice this should not happen
293323
if not assets:
294-
raise RuntimeError(f"Component {name} has no assets")
324+
raise RuntimeError(f"Component {treated_name} has no assets")
295325
if len(assets) > 1:
296326
log.debug("All assets: %r", assets)
297-
raise RuntimeError(f"Component {name} has more than 1 asset")
327+
raise RuntimeError(f"Component {treated_name} has more than 1 asset")
298328

299329
return assets[0]["downloadUrl"]
300330

0 commit comments

Comments
 (0)