Skip to content
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

Small bugfixes for secrets functions #235

Merged
merged 1 commit into from
Dec 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 14 additions & 13 deletions runhouse/resources/secrets/secret.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,8 @@ def extract_provider_secrets(cls, names: List[str] = None) -> Dict[str, "Secret"

secrets = {}

# locally configured non-ssh provider secrets
for provider in _str_to_provider_class.keys():
names = names or _str_to_provider_class.keys()
for provider in names:
if provider == "ssh":
continue
try:
Expand All @@ -153,17 +153,18 @@ def extract_provider_secrets(cls, names: List[str] = None) -> Dict[str, "Secret"
continue

# locally configured ssh secrets
default_ssh_folder = "~/.ssh"
ssh_files = os.listdir(os.path.expanduser(default_ssh_folder))
for file in ssh_files:
if file != "sky-key" and f"{file}.pub" in ssh_files:
name = f"ssh-{file}"
secret = provider_secret(
provider="ssh",
name=name,
path=os.path.join(default_ssh_folder, file),
)
secrets[name] = secret
if "ssh" in names:
default_ssh_folder = "~/.ssh"
ssh_files = os.listdir(os.path.expanduser(default_ssh_folder))
for file in ssh_files:
if file != "sky-key" and f"{file}.pub" in ssh_files:
name = f"ssh-{file}"
secret = provider_secret(
provider="ssh",
name=name,
path=os.path.join(default_ssh_folder, file),
)
secrets[name] = secret

return secrets

Expand Down
7 changes: 5 additions & 2 deletions runhouse/resources/secrets/secret_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,11 @@ def provider_secret(
return Secret.from_name(name)

elif not any([values, path, env_vars]):
secret_class = _get_provider_class(provider)
return secret_class(name=name, provider=provider, dryrun=dryrun)
if provider in Secret.builtin_providers(as_str=True):
secret_class = _get_provider_class(provider)
return secret_class(name=name, provider=provider, dryrun=dryrun)
else:
return ProviderSecret.from_name(name or provider)

elif sum([bool(x) for x in [values, path, env_vars]]) == 1:
secret_class = _get_provider_class(provider)
Expand Down
3 changes: 0 additions & 3 deletions tests/test_secret.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,9 +322,6 @@ def test_convert_secret_resource():
headers=rns_client.request_headers,
)

with pytest.raises(ValueError):
load_config(name)

_convert_secrets_resource([name])
assert load_config(name)

Expand Down
Loading