Skip to content

Commit

Permalink
fix(cli): set git credentials helper correctly on git clone (#3348)
Browse files Browse the repository at this point in the history
  • Loading branch information
Panaetius committed Mar 8, 2023
1 parent 4220f4e commit ac21c32
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
2 changes: 1 addition & 1 deletion renku/command/session.py
Expand Up @@ -29,7 +29,7 @@ def session_list_command():

def session_start_command():
"""Start an interactive session."""
return Command().command(session_start).with_database()
return Command().command(session_start).with_database().require_migration()


def session_stop_command():
Expand Down
15 changes: 8 additions & 7 deletions renku/core/login.py
Expand Up @@ -28,7 +28,13 @@
from renku.core import errors
from renku.core.config import get_value, remove_value, set_value
from renku.core.util import communication
from renku.core.util.git import RENKU_BACKUP_PREFIX, create_backup_remote, get_remote, get_renku_repo_url
from renku.core.util.git import (
RENKU_BACKUP_PREFIX,
create_backup_remote,
get_remote,
get_renku_repo_url,
set_git_credential_helper,
)
from renku.core.util.urls import parse_authentication_endpoint
from renku.domain_model.enums import ConfigFilter
from renku.domain_model.project_context import project_context
Expand Down Expand Up @@ -135,7 +141,7 @@ def login(endpoint: Optional[str], git_login: bool, yes: bool):
_store_token(parsed_endpoint.netloc, access_token)

if git_login and repository:
_set_git_credential_helper(repository=cast("Repository", repository), hostname=parsed_endpoint.netloc)
set_git_credential_helper(repository=cast("Repository", repository), hostname=parsed_endpoint.netloc)
backup_remote_name, backup_exists, remote = create_backup_remote(
repository=repository, remote_name=remote_name, url=remote_url # type:ignore
)
Expand Down Expand Up @@ -171,11 +177,6 @@ def _store_token(netloc, access_token):
os.chmod(project_context.global_config_path, 0o600)


def _set_git_credential_helper(repository: "Repository", hostname):
with repository.get_configuration(writable=True) as config:
config.set_value("credential", "helper", f"!renku credentials --hostname {hostname}")


def _set_renku_url_for_remote(repository: "Repository", remote_name: str, remote_url: str, hostname: str):
"""Set renku repository URL for ``remote_name``.
Expand Down
9 changes: 9 additions & 0 deletions renku/core/util/git.py
Expand Up @@ -241,6 +241,12 @@ def create_backup_remote(repository: "Repository", remote_name: str, url: str) -
return backup_remote_name, False, remote


def set_git_credential_helper(repository: "Repository", hostname):
"""Set up credential helper for renku git."""
with repository.get_configuration(writable=True) as config:
config.set_value("credential", "helper", f"!renku credentials --hostname {hostname}")


def get_full_repository_path(url: Optional[str]) -> str:
"""Extract hostname/path of a git repository from its URL.
Expand Down Expand Up @@ -682,6 +688,9 @@ def clone_renku_repository(

if create_backup:
create_backup_remote(repository=repository, remote_name="origin", url=url)
set_git_credential_helper(
repository=cast("Repository", repository), hostname=deployment_hostname or parsed_url.hostname
)

return repository

Expand Down

0 comments on commit ac21c32

Please sign in to comment.