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

[WIP] default ssh provider updates #1367

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
15 changes: 14 additions & 1 deletion runhouse/resources/hardware/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,8 @@ def delete_configs(self, delete_creds: bool = False):
super().delete_configs()

def _setup_creds(self, ssh_creds: Union[Dict, "Secret", str]):
"""Setup cluster credentials from user provided ssh_creds"""
"""Setup cluster credentials from user provided ssh_creds. If no creds are provided, try using
the default SSH creds saved in Den."""
from runhouse.resources.secrets import Secret
from runhouse.resources.secrets.provider_secrets.sky_secret import SkySecret
from runhouse.resources.secrets.provider_secrets.ssh_secret import SSHSecret
Expand All @@ -284,10 +285,22 @@ def _setup_creds(self, ssh_creds: Union[Dict, "Secret", str]):
self._creds = None

if not ssh_creds:
from runhouse import ProviderSecret

try:
# Use the default ssh creds if saved in Den
ssh_secret = ProviderSecret.from_name("ssh")
self._creds = ssh_secret
return
except ValueError:
pass

return

elif isinstance(ssh_creds, Secret):
self._creds = ssh_creds
return

elif isinstance(ssh_creds, str):
self._creds = Secret.from_name(ssh_creds)
return
Expand Down
3 changes: 2 additions & 1 deletion runhouse/resources/secrets/provider_secrets/ssh_secret.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ def save(
if name:
self.name = name
elif not self.name:
self.name = f"ssh-{self.key}"
# If name not provided treat as the "default" SSH secret
self.name = self._PROVIDER
return super().save(
save_values=save_values,
headers=headers or rns_client.request_headers(),
Expand Down
12 changes: 9 additions & 3 deletions runhouse/resources/secrets/secret_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def secret(
name (str, optional): Name to assign the secret resource.
values (Dict, optional): Dictionary of secret key-value pairs.
load_from_den (bool): Whether to try loading the secret from Den. (Default: ``True``)
provider (str): Provider corresponding to the secret.
dryrun (bool, optional): Whether to create in dryrun mode. (Default: False)
Returns:
Secret: The resulting Secret object.
Expand Down Expand Up @@ -81,13 +82,18 @@ def provider_secret(
return Secret.from_name(name, load_from_den=load_from_den)

elif not any([values, path, env_vars]):
# try reloading by name or provider
try:
return ProviderSecret.from_name(
name or provider, load_from_den=load_from_den
)
except ValueError:
pass
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, load_from_den=load_from_den
)
raise ValueError(f"Provider {provider} not recognized.")

elif sum([bool(x) for x in [values, path, env_vars]]) == 1:
secret_class = _get_provider_class(provider)
Expand Down
Loading