Skip to content
This repository has been archived by the owner on Nov 19, 2024. It is now read-only.

Commit

Permalink
Update DANDI_API_KEY to LINCBRAIN_API_KEY
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaron Kanzer authored and Aaron Kanzer committed Feb 12, 2024
1 parent a27c02e commit 1d5db72
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 61 deletions.
2 changes: 1 addition & 1 deletion DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ development command line options.
otherwise be hidden from the user-visible (`--help`) interface, unless this
env variable is set to a non-empty value

- `DANDI_API_KEY` -- avoids using keyrings, thus making it possible to
- `LINCBRAIN_API_KEY` -- avoids using keyrings, thus making it possible to
"temporarily" use another account etc for the "API" version of the server.

- `DANDI_LOG_LEVEL` -- set log level. By default `INFO`, should be an int (`10` - `DEBUG`).
Expand Down
4 changes: 2 additions & 2 deletions lincbrain/cli/tests/test_service_scripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def test_reextract_metadata(
asset_id = nwb_dandiset.dandiset.get_asset_by_path(
"sub-mouse001/sub-mouse001.nwb"
).identifier
monkeypatch.setenv("DANDI_API_KEY", nwb_dandiset.api.api_key)
monkeypatch.setenv("LINCBRAIN_API_KEY", nwb_dandiset.api.api_key)
r = CliRunner().invoke(
service_scripts,
["reextract-metadata", "--when=always", nwb_dandiset.dandiset.version_api_url],
Expand Down Expand Up @@ -71,7 +71,7 @@ def test_update_dandiset_from_doi(
) -> None:
dandiset_id = new_dandiset.dandiset_id
repository = new_dandiset.api.instance.gui
monkeypatch.setenv("DANDI_API_KEY", new_dandiset.api.api_key)
monkeypatch.setenv("LINCBRAIN_API_KEY", new_dandiset.api.api_key)
if os.environ.get("DANDI_TESTS_NO_VCR", ""):
ctx = nullcontext()
else:
Expand Down
6 changes: 3 additions & 3 deletions lincbrain/dandiapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ def authenticate(self, token: str, save_to_keyring: bool = False) -> None:
def dandi_authenticate(self) -> None:
"""
Acquire and set the authentication token/API key used by the
`DandiAPIClient`. If the :envvar:`DANDI_API_KEY` environment variable
`DandiAPIClient`. If the :envvar:`LINCBRAIN_API_KEY` environment variable
is set, its value is used as the token. Otherwise, the token is looked
up in the user's keyring under the service
":samp:`dandi-api-{INSTANCE_NAME}`" [#auth]_ and username "``key``".
Expand All @@ -488,9 +488,9 @@ def dandi_authenticate(self) -> None:
"``dandi-api-dandi-staging``" for the staging server
"""
# Shortcut for advanced folks
api_key = os.environ.get("DANDI_API_KEY", None)
api_key = os.environ.get("LINCBRAIN_API_KEY", None)
if api_key:
lgr.debug("Using api key from DANDI_API_KEY environment variable")
lgr.debug("Using api key from LINCBRAIN_API_KEY environment variable")
self.authenticate(api_key)
return
client_name, app_id = self._get_keyring_ids()
Expand Down
2 changes: 1 addition & 1 deletion lincbrain/tests/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ def client(self) -> DandiAPIClient:

def upload(self, paths: list[str | Path] | None = None, **kwargs: Any) -> None:
with pytest.MonkeyPatch().context() as m:
m.setenv("DANDI_API_KEY", self.api.api_key)
m.setenv("LINCBRAIN_API_KEY", self.api.api_key)
upload(
paths=paths or [self.dspath],
dandi_instance=self.api.instance_id,
Expand Down
6 changes: 3 additions & 3 deletions lincbrain/tests/test_dandiapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def test_authenticate_bad_key_good_key_input(
)
confirm_mock = mocker.patch("click.confirm", return_value=True)

monkeypatch.delenv("DANDI_API_KEY", raising=False)
monkeypatch.delenv("LINCBRAIN_API_KEY", raising=False)

client = DandiAPIClient(local_dandi_api.api_url)
assert "Authorization" not in client.session.headers
Expand Down Expand Up @@ -162,7 +162,7 @@ def test_authenticate_good_key_keyring(
is_interactive_spy = mocker.spy(dandiapi, "is_interactive")
confirm_spy = mocker.spy(click, "confirm")

monkeypatch.delenv("DANDI_API_KEY", raising=False)
monkeypatch.delenv("LINCBRAIN_API_KEY", raising=False)

client = DandiAPIClient(local_dandi_api.api_url)
assert "Authorization" not in client.session.headers
Expand Down Expand Up @@ -194,7 +194,7 @@ def test_authenticate_bad_key_keyring_good_key_input(
)
confirm_mock = mocker.patch("click.confirm", return_value=True)

monkeypatch.delenv("DANDI_API_KEY", raising=False)
monkeypatch.delenv("LINCBRAIN_API_KEY", raising=False)

client = DandiAPIClient(local_dandi_api.api_url)
assert "Authorization" not in client.session.headers
Expand Down
30 changes: 15 additions & 15 deletions lincbrain/tests/test_delete.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def test_delete_paths(
remainder: list[Path],
) -> None:
monkeypatch.chdir(text_dandiset.dspath)
monkeypatch.setenv("DANDI_API_KEY", text_dandiset.api.api_key)
monkeypatch.setenv("LINCBRAIN_API_KEY", text_dandiset.api.api_key)
instance = text_dandiset.api.instance_id
dandiset_id = text_dandiset.dandiset_id
delete_spy = mocker.spy(RESTFullAPIClient, "delete")
Expand All @@ -92,7 +92,7 @@ def test_delete_path_confirm(
text_dandiset: SampleDandiset,
) -> None:
monkeypatch.chdir(text_dandiset.dspath)
monkeypatch.setenv("DANDI_API_KEY", text_dandiset.api.api_key)
monkeypatch.setenv("LINCBRAIN_API_KEY", text_dandiset.api.api_key)
instance = text_dandiset.api.instance_id
dandiset_id = text_dandiset.dandiset_id
delete_spy = mocker.spy(RESTFullAPIClient, "delete")
Expand All @@ -113,7 +113,7 @@ def test_delete_path_pyout(
text_dandiset: SampleDandiset,
) -> None:
monkeypatch.chdir(text_dandiset.dspath)
monkeypatch.setenv("DANDI_API_KEY", text_dandiset.api.api_key)
monkeypatch.setenv("LINCBRAIN_API_KEY", text_dandiset.api.api_key)
instance = text_dandiset.api.instance_id
delete_spy = mocker.spy(RESTFullAPIClient, "delete")
delete(["subdir2/coconut.txt"], dandi_instance=instance, force=True)
Expand Down Expand Up @@ -143,7 +143,7 @@ def test_delete_dandiset(
paths: list[str],
) -> None:
monkeypatch.chdir(text_dandiset.dspath)
monkeypatch.setenv("DANDI_API_KEY", text_dandiset.api.api_key)
monkeypatch.setenv("LINCBRAIN_API_KEY", text_dandiset.api.api_key)
instance = text_dandiset.api.instance_id
dandiset_id = text_dandiset.dandiset_id
delete_spy = mocker.spy(RESTFullAPIClient, "delete")
Expand All @@ -166,7 +166,7 @@ def test_delete_dandiset_confirm(
text_dandiset: SampleDandiset,
) -> None:
monkeypatch.chdir(text_dandiset.dspath)
monkeypatch.setenv("DANDI_API_KEY", text_dandiset.api.api_key)
monkeypatch.setenv("LINCBRAIN_API_KEY", text_dandiset.api.api_key)
instance = text_dandiset.api.instance_id
dandiset_id = text_dandiset.dandiset_id
delete_spy = mocker.spy(RESTFullAPIClient, "delete")
Expand All @@ -187,7 +187,7 @@ def test_delete_dandiset_mismatch(
text_dandiset: SampleDandiset,
) -> None:
monkeypatch.chdir(text_dandiset.dspath)
monkeypatch.setenv("DANDI_API_KEY", text_dandiset.api.api_key)
monkeypatch.setenv("LINCBRAIN_API_KEY", text_dandiset.api.api_key)
instance = text_dandiset.api.instance_id
dandiset_id = text_dandiset.dandiset_id
not_dandiset = str(int(dandiset_id) - 1).zfill(6)
Expand Down Expand Up @@ -216,7 +216,7 @@ def test_delete_instance_mismatch(
text_dandiset: SampleDandiset,
) -> None:
monkeypatch.chdir(text_dandiset.dspath)
monkeypatch.setenv("DANDI_API_KEY", text_dandiset.api.api_key)
monkeypatch.setenv("LINCBRAIN_API_KEY", text_dandiset.api.api_key)
instance = text_dandiset.api.instance_id
dandiset_id = text_dandiset.dandiset_id
delete_spy = mocker.spy(RESTFullAPIClient, "delete")
Expand All @@ -242,7 +242,7 @@ def test_delete_instance_mismatch(
def test_delete_nonexistent_dandiset(
local_dandi_api: DandiAPI, mocker: MockerFixture, monkeypatch: pytest.MonkeyPatch
) -> None:
monkeypatch.setenv("DANDI_API_KEY", local_dandi_api.api_key)
monkeypatch.setenv("LINCBRAIN_API_KEY", local_dandi_api.api_key)
instance = local_dandi_api.instance_id
delete_spy = mocker.spy(RESTFullAPIClient, "delete")
with pytest.raises(NotFoundError) as excinfo:
Expand All @@ -259,7 +259,7 @@ def test_delete_nonexistent_dandiset(
def test_delete_nonexistent_dandiset_skip_missing(
local_dandi_api: DandiAPI, mocker: MockerFixture, monkeypatch: pytest.MonkeyPatch
) -> None:
monkeypatch.setenv("DANDI_API_KEY", local_dandi_api.api_key)
monkeypatch.setenv("LINCBRAIN_API_KEY", local_dandi_api.api_key)
instance = local_dandi_api.instance_id
delete_spy = mocker.spy(RESTFullAPIClient, "delete")
delete(
Expand All @@ -277,7 +277,7 @@ def test_delete_nonexistent_asset(
monkeypatch: pytest.MonkeyPatch,
text_dandiset: SampleDandiset,
) -> None:
monkeypatch.setenv("DANDI_API_KEY", text_dandiset.api.api_key)
monkeypatch.setenv("LINCBRAIN_API_KEY", text_dandiset.api.api_key)
instance = text_dandiset.api.instance_id
dandiset_id = text_dandiset.dandiset_id
delete_spy = mocker.spy(RESTFullAPIClient, "delete")
Expand All @@ -304,7 +304,7 @@ def test_delete_nonexistent_asset_skip_missing(
text_dandiset: SampleDandiset,
tmp_path: Path,
) -> None:
monkeypatch.setenv("DANDI_API_KEY", text_dandiset.api.api_key)
monkeypatch.setenv("LINCBRAIN_API_KEY", text_dandiset.api.api_key)
instance = text_dandiset.api.instance_id
dandiset_id = text_dandiset.dandiset_id
delete_spy = mocker.spy(RESTFullAPIClient, "delete")
Expand Down Expand Up @@ -333,7 +333,7 @@ def test_delete_nonexistent_asset_folder(
monkeypatch: pytest.MonkeyPatch,
text_dandiset: SampleDandiset,
) -> None:
monkeypatch.setenv("DANDI_API_KEY", text_dandiset.api.api_key)
monkeypatch.setenv("LINCBRAIN_API_KEY", text_dandiset.api.api_key)
instance = text_dandiset.api.instance_id
dandiset_id = text_dandiset.dandiset_id
delete_spy = mocker.spy(RESTFullAPIClient, "delete")
Expand All @@ -360,7 +360,7 @@ def test_delete_nonexistent_asset_folder_skip_missing(
text_dandiset: SampleDandiset,
tmp_path: Path,
) -> None:
monkeypatch.setenv("DANDI_API_KEY", text_dandiset.api.api_key)
monkeypatch.setenv("LINCBRAIN_API_KEY", text_dandiset.api.api_key)
instance = text_dandiset.api.instance_id
dandiset_id = text_dandiset.dandiset_id
delete_spy = mocker.spy(RESTFullAPIClient, "delete")
Expand All @@ -387,7 +387,7 @@ def test_delete_nonexistent_asset_folder_skip_missing(
def test_delete_version(
local_dandi_api: DandiAPI, mocker: MockerFixture, monkeypatch: pytest.MonkeyPatch
) -> None:
monkeypatch.setenv("DANDI_API_KEY", local_dandi_api.api_key)
monkeypatch.setenv("LINCBRAIN_API_KEY", local_dandi_api.api_key)
instance = local_dandi_api.instance_id
delete_spy = mocker.spy(RESTFullAPIClient, "delete")
with pytest.raises(NotImplementedError) as excinfo:
Expand Down Expand Up @@ -430,7 +430,7 @@ def test_delete_zarr_path(
tmp_path: Path,
) -> None:
monkeypatch.chdir(zarr_dandiset.dspath)
monkeypatch.setenv("DANDI_API_KEY", zarr_dandiset.api.api_key)
monkeypatch.setenv("LINCBRAIN_API_KEY", zarr_dandiset.api.api_key)
instance = zarr_dandiset.api.instance_id
delete_spy = mocker.spy(RESTFullAPIClient, "delete")
delete(["sample.zarr"], dandi_instance=instance, devel_debug=True, force=True)
Expand Down
2 changes: 1 addition & 1 deletion lincbrain/tests/test_keyring.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def ensure_keyring_backends() -> None:
def test_dandi_authenticate_no_env_var(
local_dandi_api: DandiAPI, monkeypatch: pytest.MonkeyPatch, mocker: MockerFixture
) -> None:
monkeypatch.delenv("DANDI_API_KEY", raising=False)
monkeypatch.delenv("LINCBRAIN_API_KEY", raising=False)
monkeypatch.setenv("PYTHON_KEYRING_BACKEND", "keyring.backends.null.Keyring")
inputmock = mocker.patch(
"lincbrain.dandiapi.input", return_value=local_dandi_api.api_key
Expand Down
Loading

0 comments on commit 1d5db72

Please sign in to comment.