Obtain API key for DANDI instance from corresponding env var#1731
Obtain API key for DANDI instance from corresponding env var#1731yarikoptic merged 11 commits intodandi:masterfrom
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1731 +/- ##
==========================================
- Coverage 75.11% 75.07% -0.05%
==========================================
Files 84 84
Lines 11856 11868 +12
==========================================
+ Hits 8906 8910 +4
- Misses 2950 2958 +8
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
@dandi/ember WDYT about this? do your docs ATM instruct to use DANDI_API_KEY already? |
Instead of attempting to obtain API key from the environment variable DANDI_API_KEY when connecting to any known DANI instances, obtain the API key from an environment variable corresponding the to name of the instance. For example, obtain the key from the `DANDI_API_KEY` env var when connecting to the known DANI instance named `dandi` and obtain the key from the `EMBER_SANDBOX_API_KEY` var when the connecting to the known instance named `ember-sandbox`. I.e., the environment variable name is the capitalized version of the instance's name with "-" replaced by "_" suffixed by "_API_KEY".
3040cdd to
01d34a2
Compare
There was a problem hiding this comment.
Pull Request Overview
This PR refactors the handling of API keys for DANDI instances from using a single environment variable DANDI_API_KEY to instance-specific environment variables. This change allows multiple DANDI instances to have their own API keys set simultaneously through environment variables.
Key Changes:
- Introduced
get_api_key_env_name()function to generate instance-specific environment variable names - Updated all test files to use the new instance-specific environment variable names
- Updated documentation to reflect the new environment variable naming convention
Reviewed Changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| dandi/dandiapi.py | Added get_api_key_env_name() function and updated authentication logic to use instance-specific environment variables |
| dandi/tests/test_move.py | Updated all tests to use instance-specific API key environment variables via get_api_key_env_name() |
| dandi/tests/test_keyring.py | Updated test to delete instance-specific API key environment variable |
| dandi/tests/test_delete.py | Updated all tests to use instance-specific API key environment variables |
| dandi/tests/test_dandiapi.py | Added test for get_api_key_env_name() function and updated authentication tests |
| dandi/tests/fixtures.py | Updated SampleDandiset.upload() to use instance-specific environment variables |
| dandi/cli/tests/test_service_scripts.py | Updated tests to use instance-specific environment variables |
| DEVELOPMENT.md | Updated documentation to describe the new environment variable naming scheme |
Comments suppressed due to low confidence (1)
DEVELOPMENT.md:1
- Corrected spelling of 'DAND_API_KEY' to 'DANDI_API_KEY'.
# DANDI Client Development
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull Request Overview
Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
a024555 to
2cef487
Compare
yarikoptic
left a comment
There was a problem hiding this comment.
"compress" code a bit to better centralize and reduce code clutter
dandi/dandiapi.py
Outdated
| :param dandi_instance: the DANDI instance | ||
| :return: the name of the environment variable | ||
| """ | ||
| return f"{dandi_instance.name.upper().replace('-', '_')}_API_KEY" |
There was a problem hiding this comment.
looking at multitude of calls , I wonder if we should add api_key_envvar property to dandi_instance's class and be done to use it -- that would make code shorter.
There was a problem hiding this comment.
Practically, what you proposed is more convenient. Conceptually, it is a bit awkward since the API key environment variable name is not really a property or attribute of a DANDI instance.
There was a problem hiding this comment.
here -- we agreed for it to be moved as a _get_api_key_env_var method of DandiAPIClient
There was a problem hiding this comment.
This logic is refactored into the api_key_env_var property of DandiAPIClient instead since it is actually used externally, https://github.com/candleindark/dandi-cli/blob/84be13a3251237f07dbbc70b296c8986ccd3b259/dandi/tests/fixtures.py#L544.
@yarikoptic |
There was a problem hiding this comment.
Pull Request Overview
Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
f8c29cd to
73694d0
Compare
|
🚀 PR was released in |
dandi-cli 0.73.2 (released Nov 15, 2025) changed API key lookup from the generic DANDI_API_KEY env var to instance-specific env vars (e.g. DANDI_SANDBOX_API_KEY for the sandbox). This broke sandbox uploads because nwb-guide only set DANDI_API_KEY. Now set both DANDI_API_KEY and DANDI_SANDBOX_API_KEY when uploading to the sandbox, maintaining compatibility with both old and new dandi. See: dandi/dandi-cli#1731 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
dandi-cli 0.73.2 (released Nov 15, 2025) changed API key lookup from the generic DANDI_API_KEY env var to instance-specific env vars (e.g. DANDI_SANDBOX_API_KEY for the sandbox). This broke sandbox uploads because nwb-guide only set DANDI_API_KEY. Now set both DANDI_API_KEY and DANDI_SANDBOX_API_KEY when uploading to the sandbox, maintaining compatibility with both old and new dandi. See: dandi/dandi-cli#1731 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This PR closes #1730
Release Notes
Instead of attempting to obtain API key from the environment variable DANDI_API_KEY when connecting to any known DANI instances, obtain the API key from an environment variable corresponding the to name of the instance. For example, obtain the key from the
DANDI_API_KEYenv var when connecting to the known DANI instance nameddandiand obtain the key from theEMBER_SANDBOX_API_KEYvar when the connecting to the known instance namedember-sandbox. I.e., the environment variable name is the capitalized version of the instance's name with "-" replaced by "_" suffixed by "_API_KEY".