Repository navigation
feat: select the credential profile with RUNPOD_PROFILE #686
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
Open
deanq
wants to merge
6
commits into
main
Choose a base branch
from
deanq/sls-971-profile-env
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+152
−7
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
b714953
feat: select the credential profile with RUNPOD_PROFILE
deanq 531e872
fix: tolerate a selected profile without api_key (SLS-971)
deanq 1e5b8e5
Merge branch 'main' into deanq/sls-971-profile-env
deanq f1af922
Merge remote-tracking branch 'origin/main' into deanq/sls-971-profile…
deanq 2cb6865
docs: correct the profile and credentials guide
deanq 6c96edc
docs: keep the getting started guide's file name in this change
deanq File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| """Credential profile selection via RUNPOD_PROFILE.""" | ||
|
|
||
| import importlib | ||
|
|
||
| import pytest | ||
|
|
||
| import runpod | ||
|
|
||
|
|
||
| class TestSelectedProfile: | ||
| def test_defaults_to_default_profile(self, monkeypatch): | ||
| monkeypatch.delenv("RUNPOD_PROFILE", raising=False) | ||
| assert runpod._selected_profile() == "default" | ||
|
|
||
| def test_env_selects_profile(self, monkeypatch): | ||
| monkeypatch.setenv("RUNPOD_PROFILE", "team") | ||
| assert runpod._selected_profile() == "team" | ||
|
|
||
| def test_env_value_is_stripped(self, monkeypatch): | ||
| monkeypatch.setenv("RUNPOD_PROFILE", " team ") | ||
| assert runpod._selected_profile() == "team" | ||
|
|
||
| @pytest.mark.parametrize("value", ["", " "]) | ||
| def test_blank_env_falls_back_to_default(self, monkeypatch, value): | ||
| monkeypatch.setenv("RUNPOD_PROFILE", value) | ||
| assert runpod._selected_profile() == "default" | ||
|
|
||
|
|
||
| class TestApiKeyFromSelectedProfile: | ||
| def test_loads_key_from_selected_profile(self, tmp_path, monkeypatch): | ||
| from runpod.cli.groups.config import functions | ||
|
|
||
| credentials = tmp_path / "config.toml" | ||
| credentials.write_text( | ||
| '[default]\napi_key = "default-key"\n[team]\napi_key = "team-key"\n' | ||
| ) | ||
| monkeypatch.setattr(functions, "CREDENTIAL_FILE", str(credentials)) | ||
| monkeypatch.delenv("RUNPOD_API_KEY", raising=False) | ||
| monkeypatch.setattr(runpod, "profile", "team") | ||
|
|
||
| assert runpod._load_api_key() == "team-key" | ||
|
|
||
| def test_api_key_env_wins_over_profile(self, tmp_path, monkeypatch): | ||
| from runpod.cli.groups.config import functions | ||
|
|
||
| credentials = tmp_path / "config.toml" | ||
| credentials.write_text('[team]\napi_key = "team-key"\n') | ||
| monkeypatch.setattr(functions, "CREDENTIAL_FILE", str(credentials)) | ||
| monkeypatch.setenv("RUNPOD_API_KEY", "env-key") | ||
| monkeypatch.setattr(runpod, "profile", "team") | ||
|
|
||
| assert runpod._load_api_key() == "env-key" | ||
|
|
||
|
|
||
| class TestImportWithSelectedProfile: | ||
| @pytest.fixture | ||
| def reload_runpod(self, monkeypatch): | ||
| """reload runpod under the test env, then again under the restored env.""" | ||
| yield lambda: importlib.reload(runpod) | ||
| monkeypatch.undo() | ||
| importlib.reload(runpod) | ||
|
|
||
| def test_s3_only_profile_imports_without_api_key( | ||
| self, tmp_path, monkeypatch, reload_runpod | ||
| ): | ||
| from runpod.cli.groups.config import functions | ||
|
|
||
| credentials = tmp_path / "config.toml" | ||
| credentials.write_text( | ||
| '[storage]\ns3_access_key = "id"\ns3_secret_key = "secret"\n' | ||
| ) | ||
| monkeypatch.setattr(functions, "CREDENTIAL_FILE", str(credentials)) | ||
| monkeypatch.delenv("RUNPOD_API_KEY", raising=False) | ||
| monkeypatch.setenv("RUNPOD_PROFILE", "storage") | ||
|
|
||
| reload_runpod() | ||
|
|
||
| assert runpod.profile == "storage" | ||
| assert runpod.api_key is None |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.