[Fixes #14381] Relax Remote Service URL uniqueness#14404
Open
etj wants to merge 11 commits into
Open
Conversation
Contributor
Author
|
Waiting for #14328 to be merged. |
…ath in test_get_service_handler_wms
…andler Leftover from the earlier manual "Align to master" commit; harmless but redundant.
_get_service_handler (views.py) and GeoNodeServiceHandler.parsed_service
(wms.py) build the request auth via get_request_auth(), which returns a
HashableAuthBase-wrapped requests.auth object, but only passed auth= to
get_service_handler, not auth_config=. Since HashableAuthBase exposes no
`.username` attribute, _build_auth_cache_fingerprint fell through to a
fingerprint that was constant for every HashableAuthBase instance
("auth:HashableAuthBase"), so changing a service's stored credentials
would not bust the cached service handler until it naturally expired.
Fix both call sites to also pass auth_config=service.auth_config,
consistent with every other get_service_handler/get_service_cache_key
call site. Also harden _build_auth_cache_fingerprint itself to unwrap
HashableAuthBase and fingerprint the full underlying credential dict,
so the auth= path is correct on its own rather than relying solely on
callers always supplying auth_config too.
parsed_service calls self.ows_endpoint() (a real HTTP request) before get_cleaned_url_params, which wasn't mocked, causing a real DNS lookup against the phony test hostname. Mock ows_endpoint too.
Contributor
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 12 out of 12 changed files in this pull request and generated 3 comments.
Comments suppressed due to low confidence (1)
geonode/services/serviceprocessors/init.py:61
logger.exception(msg=...)is an invalid call signature for the stdlib logger (the message must be the first positional argument). In the exception handler this will raise aTypeErrorand can mask the original parsing error. Log the message positionally (optionally with%sformatting) and keep the original exception context.
except Exception as e:
logger.exception(e)
logger.exception(msg=f"Could not parse service {base_url}")
raise
Comment on lines
1418
to
1424
| from geonode.services.serviceprocessors import get_service_handler | ||
|
|
||
| handler = get_service_handler( | ||
| instance.remote_service.service_url, service_type=instance.remote_service.type | ||
| instance.remote_service.service_url, | ||
| service_type=instance.remote_service.type, | ||
| service_id=instance.remote_service.id, | ||
| ) |
Comment on lines
+43
to
+57
| cache_key = get_service_cache_key( | ||
| base_url, | ||
| service_type=service_type, | ||
| service_id=service_id, | ||
| auth=kwargs.get("auth"), | ||
| auth_config=kwargs.get("auth_config"), | ||
| ) | ||
|
|
||
| if entry := service_handler_cache.get(cache_key): | ||
| return entry | ||
|
|
||
| handler = service_type_registry.get_handler_class(service_type) | ||
| handler = service_type_registry.get_handler_class(service_type) | ||
| try: | ||
| service_handler = handler(base_url, service_id, *args, **kwargs) | ||
| service_cache.set(service_handler.url, service_handler, settings.SERVICE_CACHE_EXPIRATION_TIME) | ||
| service_handler_cache.set(cache_key, service_handler) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR changes the identity model of remote services from endpoint URL uniqueness to service record uniqueness.
Before:
base_url) implicitly identified one service.After:
base_urlis no longer a unique identifier.Serviceobjects can intentionally reference the same endpoint (e.g., different owners/use-cases/credentials).What this PR changes
Service.base_url.Servicerecords pointing to the same remote endpoint.base_urlvalues.Service.base_urlfield.geoserver_pre_save_maplayerfallback strict on ambiguous dataset matches (logs + raises onMultipleObjectsReturned).ServiceHandlerCacheclass (serviceprocessors/cache.py), mirroring the existingServiceTypeRegistrypattern, instead of loose module-level functions and a duplicated cache handle inviews.py.GeoNodeServiceHandler.parsed_service(predates this PR) that read auth/type/id off a variable that is actually just the rawservice=query-string value, not a Service model -- this would raiseAttributeErrorthe moment the property ran (e.g. registering or probing a GeoNode-type remote service). Auth now resolves the same wayWmsServiceHandler.parsed_servicedoes.Solved
Note: this PR may conflict with #14328Checklist
For all pull requests:
The following are required only for core and extension modules (they are welcomed, but not required, for contrib modules):
Submitting the PR does not require you to check all items, but by the time it gets merged, they should be either satisfied or inapplicable.