-
Notifications
You must be signed in to change notification settings - Fork 27
Allow custom CDISC Library API URL (proxy / local cache support) #1484
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
e9ec3c4
cfe96ae
925c8ea
16a6dbc
31e5e87
464dc31
6482b8c
e55a90c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -508,7 +508,19 @@ def validate( | |
| "Can be provided in the environment " | ||
| "variable CDISC_LIBRARY_API_KEY" | ||
| ), | ||
| required=True, | ||
| required=False, | ||
| default="", | ||
| ) | ||
| @click.option( | ||
| "--apiurl", | ||
| envvar="CDISC_LIBRARY_API_URL", | ||
| help=( | ||
| "CDISC Library api URL (HTTPS/HTTP). Default: https://library.cdisc.org/api. " | ||
| "Can be provided in the environment " | ||
| "variable CDISC_LIBRARY_API_URL" | ||
| ), | ||
| required=False, | ||
| default="", | ||
| ) | ||
| @click.option( | ||
| "-crd", | ||
|
|
@@ -562,15 +574,29 @@ def update_cache( | |
| ctx: click.Context, | ||
| cache_path: str, | ||
| apikey: str, | ||
| apiurl: str, | ||
| custom_rules_directory: str, | ||
| custom_rule: str, | ||
| remove_custom_rules: str, | ||
| update_custom_rule: str, | ||
| custom_standard: str, | ||
| remove_custom_standard: str, | ||
| ): | ||
| logger = logging.getLogger("validator") | ||
|
|
||
| # Validation: Ensure at least one is provided when using default URL | ||
| effective_url = apiurl if apiurl else "https://library.cdisc.org/api" | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can this go into the click "default" value instead? |
||
| if effective_url == "https://library.cdisc.org/api" and not apikey: | ||
| logger.error( | ||
| "CDISC_LIBRARY_API_KEY is required when using the default CDISC Library API URL.\n" | ||
| "Either provide --apikey or set CDISC_LIBRARY_API_KEY environment variable,\n" | ||
| "or specify a custom URL with --apiurl or CDISC_LIBRARY_API_URL environment variable," | ||
| "which does or does not require specific API key for proxy access" | ||
| ) | ||
| ctx.exit(2) | ||
|
Comment on lines
+589
to
+596
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this can be removed |
||
|
|
||
| cache = CacheServiceFactory(config).get_cache_service() | ||
| library_service = CDISCLibraryService(apikey, cache) | ||
| library_service = CDISCLibraryService(apikey, apiurl, cache) | ||
| cache_populator = CachePopulator( | ||
| cache, | ||
| library_service, | ||
|
|
@@ -597,7 +623,6 @@ def update_cache( | |
|
|
||
| print("Cache updated successfully") | ||
|
|
||
|
|
||
| @click.command() | ||
| @click.option( | ||
| "-c", | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| CDISC_LIBRARY_API_KEY=your_api_key_here | ||
| CDISC_LIBRARY_API_URL=http://localhost:31415/api # smart proxy server will not use CDISC_LIBRARY_API_KEY, but will might need it's own key to query upstream server. | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. typo "but will might need" |
||
| DATASET_SIZE_THRESHOLD=10485760 # max dataset size in bytes to force dask implementation | ||
| MAX_REPORT_ROWS = 10 # integer for maximum number of issues per excel sheet (plus headers) in result report | ||
| MAX_ERRORS_PER_RULE = (10, True) # Tuple for maximum number of errors to report per rule during a validation run. Also has a per dataset flag described as second bool value in readme. example value | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,12 +5,34 @@ | |
|
|
||
| import json | ||
| import os | ||
| import pytest | ||
| from unittest.mock import MagicMock, patch | ||
|
|
||
| from cdisc_rules_engine.config import config | ||
| from cdisc_rules_engine.services.cdisc_library_service import CDISCLibraryService | ||
|
|
||
|
|
||
| def test_library_service_requires_key_for_default_url(): | ||
| """Test that API key is required when using default CDISC Library URL.""" | ||
| with pytest.raises(ValueError, match="CDISC_LIBRARY_API_KEY is required"): | ||
| CDISCLibraryService("", "", MagicMock()) | ||
|
Comment on lines
+15
to
+18
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This can be removed |
||
|
|
||
|
|
||
| def test_library_service_allows_custom_url_without_key(): | ||
| """Test that custom URL works without API key.""" | ||
| # Should not raise an error | ||
| library_service = CDISCLibraryService( | ||
| "", "https://custom-library.example.com/api", MagicMock() | ||
| ) | ||
| assert library_service is not None | ||
|
|
||
|
|
||
| def test_library_service_with_key_and_default_url(): | ||
| """Test normal case with API key and default URL.""" | ||
| library_service = CDISCLibraryService("test-key", "", MagicMock()) | ||
| assert library_service is not None | ||
|
|
||
|
|
||
| @patch( | ||
| "cdisc_rules_engine.services.cdisc_library_service.CDISCLibraryClient.get_sdtmig" | ||
| ) | ||
|
|
@@ -24,7 +46,7 @@ def test_get_standard_details(mock_get_sdtmig: MagicMock): | |
| mock_sdtmig_details: dict = json.loads(file.read()) | ||
| mock_get_sdtmig.return_value = mock_sdtmig_details | ||
|
|
||
| library_service = CDISCLibraryService(config, MagicMock()) | ||
| library_service = CDISCLibraryService(config, "", MagicMock()) | ||
| standard_details: dict = library_service.get_standard_details("sdtmig", "3-1-2") | ||
| # expected is that mocked sdtmig details is extended with "domains" key | ||
| assert standard_details == { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will go away with #1506 because a missing library api key will still be able to fetch the rules