Skip to content

Conversation

@tomhub
Copy link

@tomhub tomhub commented Dec 15, 2025

This PR adds support for configuring a custom CDISC Library API URL, enabling the use of local or private proxy/cache services (e.g. basic example https://github.com/tomhub/cdisc-proxy). This helps reduce load on the upstream CDISC Library API and limits repeated API calls in shared or CI environments.

Key changes

  • Added --apiurl CLI option and CDISC_LIBRARY_API_URL environment variable.
  • --apikey / CDISC_LIBRARY_API_KEY is now optional when using a custom API URL.
  • Validation enforces that at least one of API key or custom API URL is provided:
  • API key is required when using the default CDISC Library endpoint.
  • Custom/proxy URLs may omit the API key if the proxy handles authentication.
  • Updated cache update flow, config service, and data services to pass the API URL consistently.
  • Improved README and .env example with proxy usage guidance.
  • Added unit tests covering default vs custom URL validation logic.

Why this matters

  • Enables local caching and proxying of CDISC Library requests.
  • Reduces API throttling and repeated upstream calls.
  • Improves usability in regulated, offline, or enterprise environments.

This should partially address issue #1413

NOTE: I think [tests/unit/test_cdisc_library_service.py] needs to be properly fixed.

Copy link
Collaborator

@gerrycampion gerrycampion left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

primarily feedback where we will see merge conflicts with #1506 which will allow users to retrieve latest rules with the default library api, but no api key

Comment on lines +25 to +30
# Validation: If using the default CDISC Library URL, API key is required
if api_url == "https://api.library.cdisc.org/api" and not self._api_key:
raise ValueError(
"CDISC_LIBRARY_API_KEY is required when using the default CDISC Library API URL. "
"Either provide an API key or specify a custom CDISC_LIBRARY_API_URL which does not require an API key."
)
Copy link
Collaborator

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

Comment on lines +15 to +18
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())
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be removed

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"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can this go into the click "default" value instead?

Comment on lines +589 to +596
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)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this can be removed

@@ -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.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo "but will might need"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants