diff --git a/src/docker_publisher_osparc_services/http_interface.py b/src/docker_publisher_osparc_services/http_interface.py index 7e77ec3..ac83da1 100644 --- a/src/docker_publisher_osparc_services/http_interface.py +++ b/src/docker_publisher_osparc_services/http_interface.py @@ -49,10 +49,15 @@ async def _gitlab_get_project_id(repo_model: RepoModel) -> str: }, ) found_repos = result.json() - if len(found_repos) != 1: - message = f"Searching for {repo_name} did not yield the deisired reulst {found_repos}" - raise CouldNotFindAGitlabRepositoryRepoException(message) - return found_repos[0]["id"] + # check for http_url_to_repo + for repo in found_repos: + if repo_model.http_url_to_repo == repo["http_url_to_repo"]: + return repo["id"] + + message = ( + f"Searching for {repo_name} did not yield the deisired result {found_repos}" + ) + raise CouldNotFindAGitlabRepositoryRepoException(message) async def gitlab_did_last_repo_run_pass( diff --git a/src/docker_publisher_osparc_services/models.py b/src/docker_publisher_osparc_services/models.py index 5ac0ca5..8330f00 100644 --- a/src/docker_publisher_osparc_services/models.py +++ b/src/docker_publisher_osparc_services/models.py @@ -91,8 +91,9 @@ def require_access_token_for_gitlab(cls, values): ) return values - @property - def repo(self) -> str: + def _format_repo( + self, escape_credentials: bool = False, strip_credentials: bool = False + ) -> str: if self.gitlab is None: return self.address @@ -101,8 +102,29 @@ def repo(self) -> str: if user is None or password is None: return self.address + clear_password = password.get_secret_value() + if escape_credentials: + user = user.replace("@", "%40") + clear_password = clear_password.replace("@", "%40") + protocol, url = self.address.split("://") - return f"{protocol}://{user}:{password.get_secret_value()}@{url}" + + if strip_credentials: + return f"{protocol}://{url}" + else: + return f"{protocol}://{user}:{clear_password}@{url}" + + @property + def repo(self) -> str: + return self._format_repo(escape_credentials=False) + + @property + def escaped_repo(self) -> str: + return self._format_repo(escape_credentials=True) + + @property + def http_url_to_repo(self) -> str: + return self._format_repo(strip_credentials=True) class ConfigModel(BaseModel): diff --git a/src/docker_publisher_osparc_services/operations.py b/src/docker_publisher_osparc_services/operations.py index 7f569cf..d86b954 100644 --- a/src/docker_publisher_osparc_services/operations.py +++ b/src/docker_publisher_osparc_services/operations.py @@ -12,7 +12,7 @@ async def get_branch_hash(repo_model: RepoModel) -> str: result = await command_output( - f"git ls-remote {repo_model.repo} refs/heads/{repo_model.branch} -q", + f"git ls-remote {repo_model.escaped_repo} refs/heads/{repo_model.branch} -q" ) # since multiple lines might be present in the output, fetch from the end commit_hash = result.split()[-2] @@ -25,7 +25,7 @@ async def get_branch_hash(repo_model: RepoModel) -> str: async def clone_repo(repo_model: RepoModel) -> None: """clones and stores the cloned_dir""" target_dir: Path = Path(TemporaryDirectory().name) - await command_output(f"git clone {repo_model.repo} {target_dir}") + await command_output(f"git clone {repo_model.escaped_repo} {target_dir}") repo_model.clone_path = target_dir