Skip to content

Commit d64c179

Browse files
authored
fix(service): fixes importing private datasets in deployments with external gitlab (#3523)
1 parent 4ace85b commit d64c179

2 files changed

Lines changed: 21 additions & 1 deletion

File tree

renku/ui/service/jobs/datasets.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
# See the License for the specific language governing permissions and
1616
# limitations under the License.
1717
"""Dataset jobs."""
18+
import os
1819
import urllib
1920

2021
from urllib3.exceptions import HTTPError
@@ -87,7 +88,7 @@ def dataset_import(
8788

8889
def _is_safe_to_pass_gitlab_token(project_git_url, dataset_uri):
8990
"""Passing token is safe if project and dataset belong to the same deployment."""
90-
project_host = GitURL.parse(project_git_url).hostname
91+
project_host = os.environ.get("RENKU_DOMAIN") or GitURL.parse(project_git_url).hostname
9192
dataset_host = urllib.parse.urlparse(dataset_uri).netloc
9293

9394
# NOTE: URLs changed from domain/gitlab to gitlab.domain when moving to cloud native gitlab

tests/service/jobs/test_datasets.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -710,3 +710,22 @@ def test_unlink_dataset_sync(svc_client_cache, it_remote_repo_url_temp_branch, v
710710
assert updated_job
711711
assert {"unlinked", "remote_branch"} == updated_job.ctrl_result["result"].keys()
712712
assert ["data/data1"] == updated_job.ctrl_result["result"]["unlinked"]
713+
714+
715+
@pytest.mark.parametrize(
716+
"renku_domain,dataset_url,result",
717+
[
718+
("renkulab.io", "https://renkulab.io/datasets/abcdefg", True),
719+
("gitlab.renkulab.io", "https://renkulab.io/datasets/abcdefg", True),
720+
("renkulab.io", "https://dev.renku.ch/datasets/abcdefg", False),
721+
("dev.renku.ch", "https://ci-9999.dev.renku.ch/datasets/abcdefg", False),
722+
],
723+
)
724+
def test_dataset_gitlab_token_logic(renku_domain, dataset_url, result, monkeypatch):
725+
"""Test that logic for forwarding gitlab tokens works correctly."""
726+
from renku.ui.service.jobs.datasets import _is_safe_to_pass_gitlab_token
727+
728+
with monkeypatch.context() as monkey:
729+
monkey.setenv("RENKU_DOMAIN", renku_domain)
730+
731+
assert _is_safe_to_pass_gitlab_token("", dataset_url) == result

0 commit comments

Comments
 (0)