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

Commit

Permalink
Merge pull request #33 from lincbrain/ak-cli-name
Browse files Browse the repository at this point in the history
Update DANDI_API_KEY to LINCBRAIN_API_KEY
  • Loading branch information
aaronkanzer authored Feb 12, 2024
2 parents 392c528 + 1d5db72 commit 09efec3
Show file tree
Hide file tree
Showing 17 changed files with 93 additions and 93 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
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
],
"version": "draft",
"@context": "https://raw.githubusercontent.com/dandi/schema/master/releases/0.6.4/context.json",
"citation": "Aguillon-Rodriguez, Valeria; Angelaki, Dora E.; Bayer, Hannah M.; Bonacchi, Niccol\u00f2; Carandini, Matteo; Cazettes, Fanny; Chapuis, Gaelle A.; Churchland, Anne K.; Dan, Yang; Dewitt, Eric E. J.; Faulkner, Mayo; Forrest, Hamish; Haetzel, Laura M.; Hausser, Michael; Hofer, Sonja B.; Hu, Fei; Khanal, Anup; Krasniak, Christopher S.; Laranjeira, In\u00eas; Mainen, Zachary F.; Meijer, Guido T.; Miska, Nathaniel J.; Mrsic-Flogel, Thomas D.; Murakami, Masayoshi; Noel, Jean-Paul; Pan-Vazquez, Alejandro; Rossant, Cyrille; Sanders, Joshua I.; Socha, Karolina Z.; Terry, Rebecca; Urai, Anne E.; Vergara, Hernando M.; Wells, Miles J.; Wilson, Christian J.; Witten, Ilana B.; Wool, Lauren E.; Zador, Anthony (2023) Standardized and reproducible measurement of decision-making in mice (Version draft) [Data set]. DANDI archive. http://localhost:8085/dandiset/000001/draft",
"citation": "Aguillon-Rodriguez, Valeria; Angelaki, Dora E.; Bayer, Hannah M.; Bonacchi, Niccol\u00f2; Carandini, Matteo; Cazettes, Fanny; Chapuis, Gaelle A.; Churchland, Anne K.; Dan, Yang; Dewitt, Eric E. J.; Faulkner, Mayo; Forrest, Hamish; Haetzel, Laura M.; Hausser, Michael; Hofer, Sonja B.; Hu, Fei; Khanal, Anup; Krasniak, Christopher S.; Laranjeira, In\u00eas; Mainen, Zachary F.; Meijer, Guido T.; Miska, Nathaniel J.; Mrsic-Flogel, Thomas D.; Murakami, Masayoshi; Noel, Jean-Paul; Pan-Vazquez, Alejandro; Rossant, Cyrille; Sanders, Joshua I.; Socha, Karolina Z.; Terry, Rebecca; Urai, Anne E.; Vergara, Hernando M.; Wells, Miles J.; Wilson, Christian J.; Witten, Ilana B.; Wool, Lauren E.; Zador, Anthony (2024) Standardized and reproducible measurement of decision-making in mice (Version draft) [Data set]. DANDI archive. http://localhost:8085/dandiset/000001/draft",
"schemaKey": "Dandiset",
"identifier": "DANDI:000001",
"repository": "http://localhost:8085",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
],
"version": "draft",
"@context": "https://raw.githubusercontent.com/dandi/schema/master/releases/0.6.4/context.json",
"citation": "Chowdhury, Raeed H; Glaser, Joshua I; Miller, Lee E (2023) Area 2 of primary somatosensory cortex encodes kinematics of the whole arm (Version draft) [Data set]. DANDI archive. http://localhost:8085/dandiset/000004/draft",
"citation": "Chowdhury, Raeed H; Glaser, Joshua I; Miller, Lee E (2024) Area 2 of primary somatosensory cortex encodes kinematics of the whole arm (Version draft) [Data set]. DANDI archive. http://localhost:8085/dandiset/000004/draft",
"schemaKey": "Dandiset",
"identifier": "DANDI:000004",
"repository": "http://localhost:8085",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
],
"version": "draft",
"@context": "https://raw.githubusercontent.com/dandi/schema/master/releases/0.6.4/context.json",
"citation": "Ito, Makoto; Doya, Kenji (2023) Validation of Decision-Making Models and Analysis of Decision Variables in the Rat Basal Ganglia (Version draft) [Data set]. DANDI archive. http://localhost:8085/dandiset/000002/draft",
"citation": "Ito, Makoto; Doya, Kenji (2024) Validation of Decision-Making Models and Analysis of Decision Variables in the Rat Basal Ganglia (Version draft) [Data set]. DANDI archive. http://localhost:8085/dandiset/000002/draft",
"schemaKey": "Dandiset",
"identifier": "DANDI:000002",
"repository": "http://localhost:8085",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
],
"version": "draft",
"@context": "https://raw.githubusercontent.com/dandi/schema/master/releases/0.6.4/context.json",
"citation": "Sit, Kevin K.; Goard, Michael J. (2023) Coregistration of heading to visual cues in retrosplenial cortex (Version draft) [Data set]. DANDI archive. http://localhost:8085/dandiset/000005/draft",
"citation": "Sit, Kevin K.; Goard, Michael J. (2024) Coregistration of heading to visual cues in retrosplenial cortex (Version draft) [Data set]. DANDI archive. http://localhost:8085/dandiset/000005/draft",
"schemaKey": "Dandiset",
"identifier": "DANDI:000005",
"repository": "http://localhost:8085",
Expand Down
18 changes: 9 additions & 9 deletions lincbrain/cli/tests/test_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@


def test_download_defaults(mocker):
mock_download = mocker.patch("dandi.download.download")
mock_download = mocker.patch("lincbrain.download.download")
r = CliRunner().invoke(download)
assert r.exit_code == 0
mock_download.assert_called_once_with(
Expand All @@ -29,7 +29,7 @@ def test_download_defaults(mocker):


def test_download_all_types(mocker):
mock_download = mocker.patch("dandi.download.download")
mock_download = mocker.patch("lincbrain.download.download")
r = CliRunner().invoke(download, ["--download", "all"])
assert r.exit_code == 0
mock_download.assert_called_once_with(
Expand All @@ -47,7 +47,7 @@ def test_download_all_types(mocker):


def test_download_metadata_only(mocker):
mock_download = mocker.patch("dandi.download.download")
mock_download = mocker.patch("lincbrain.download.download")
r = CliRunner().invoke(download, ["--download", "dandiset.yaml"])
assert r.exit_code == 0
mock_download.assert_called_once_with(
Expand All @@ -65,7 +65,7 @@ def test_download_metadata_only(mocker):


def test_download_assets_only(mocker):
mock_download = mocker.patch("dandi.download.download")
mock_download = mocker.patch("lincbrain.download.download")
r = CliRunner().invoke(download, ["--download", "assets"])
assert r.exit_code == 0
mock_download.assert_called_once_with(
Expand All @@ -83,7 +83,7 @@ def test_download_assets_only(mocker):


def test_download_bad_type(mocker):
mock_download = mocker.patch("dandi.download.download")
mock_download = mocker.patch("lincbrain.download.download")
r = CliRunner().invoke(download, ["--download", "foo"], standalone_mode=False)
assert r.exit_code != 0
assert isinstance(r.exception, click.UsageError)
Expand All @@ -95,7 +95,7 @@ def test_download_bad_type(mocker):


def test_download_gui_instance_in_dandiset(mocker):
mock_download = mocker.patch("dandi.download.download")
mock_download = mocker.patch("lincbrain.download.download")
runner = CliRunner()
with runner.isolated_filesystem():
Path(dandiset_metadata_file).write_text("identifier: '123456'\n")
Expand All @@ -120,7 +120,7 @@ def test_download_gui_instance_in_dandiset(mocker):
reason="this instance now has GUI URL",
)
def test_download_api_instance_in_dandiset(mocker):
mock_download = mocker.patch("dandi.download.download")
mock_download = mocker.patch("lincbrain.download.download")
runner = CliRunner()
with runner.isolated_filesystem():
Path(dandiset_metadata_file).write_text("identifier: '123456'\n")
Expand All @@ -141,7 +141,7 @@ def test_download_api_instance_in_dandiset(mocker):


def test_download_url_instance_match(mocker):
mock_download = mocker.patch("dandi.download.download")
mock_download = mocker.patch("lincbrain.download.download")
r = CliRunner().invoke(
download,
[
Expand All @@ -166,7 +166,7 @@ def test_download_url_instance_match(mocker):


def test_download_url_instance_conflict(mocker):
mock_download = mocker.patch("dandi.download.download")
mock_download = mocker.patch("lincbrain.download.download")
r = CliRunner().invoke(
download,
["-i", "dandi", "http://localhost:8000/api/dandisets/123456/"],
Expand Down
4 changes: 2 additions & 2 deletions lincbrain/cli/tests/test_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,14 @@
def test_move_command(
mocker: MockerFixture, cmdline: list[str], srcs: list[str], kwargs: dict[str, Any]
) -> None:
mock_move = mocker.patch("dandi.move.move")
mock_move = mocker.patch("lincbrain.move.move")
r = CliRunner().invoke(move, cmdline)
assert r.exit_code == 0
mock_move.assert_called_once_with(*srcs, **kwargs)


def test_move_command_too_few_paths(mocker: MockerFixture) -> None:
mock_move = mocker.patch("dandi.move.move")
mock_move = mocker.patch("lincbrain.move.move")
r = CliRunner().invoke(move, ["foo"], standalone_mode=False)
assert r.exit_code != 0
# This is a ClickException when map_to_click_exceptions is in effect and a
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/support/digests.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
from .threaded_walk import threaded_walk
from ..utils import Hasher, exclude_from_zarr

lgr = logging.getLogger("dandi.support.digests")
lgr = logging.getLogger("lincbrain.support.digests")


@dataclass
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
20 changes: 10 additions & 10 deletions lincbrain/tests/test_dandiapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,15 +123,15 @@ def test_authenticate_bad_key_good_key_input(

backend_mock = mocker.Mock(spec=["set_password"])
keyring_lookup_mock = mocker.patch(
"dandi.dandiapi.keyring_lookup", return_value=(backend_mock, None)
"lincbrain.dandiapi.keyring_lookup", return_value=(backend_mock, None)
)
input_mock = mocker.patch("dandi.dandiapi.input", side_effect=[bad_key, good_key])
input_mock = mocker.patch("lincbrain.dandiapi.input", side_effect=[bad_key, good_key])
is_interactive_mock = mocker.patch(
"dandi.dandiapi.is_interactive", return_value=True
"lincbrain.dandiapi.is_interactive", return_value=True
)
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 All @@ -156,13 +156,13 @@ def test_authenticate_good_key_keyring(

backend_mock = mocker.Mock(spec=["set_password"])
keyring_lookup_mock = mocker.patch(
"dandi.dandiapi.keyring_lookup", return_value=(backend_mock, good_key)
"lincbrain.dandiapi.keyring_lookup", return_value=(backend_mock, good_key)
)
input_spy = mocker.spy(builtins, "input")
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 All @@ -186,15 +186,15 @@ def test_authenticate_bad_key_keyring_good_key_input(

backend_mock = mocker.Mock(spec=["set_password"])
keyring_lookup_mock = mocker.patch(
"dandi.dandiapi.keyring_lookup", return_value=(backend_mock, bad_key)
"lincbrain.dandiapi.keyring_lookup", return_value=(backend_mock, bad_key)
)
input_mock = mocker.patch("dandi.dandiapi.input", return_value=good_key)
input_mock = mocker.patch("lincbrain.dandiapi.input", return_value=good_key)
is_interactive_mock = mocker.patch(
"dandi.dandiapi.is_interactive", return_value=True
"lincbrain.dandiapi.is_interactive", return_value=True
)
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
Loading

0 comments on commit 09efec3

Please sign in to comment.