From b3f88d593272101378162e57175bc9bed5b1c907 Mon Sep 17 00:00:00 2001 From: Simon Gerber Date: Tue, 17 Dec 2024 11:15:56 +0100 Subject: [PATCH] Add support for using a HTTPS catalog URL for arbitrary catalogs --- gitlab/commodore-compile.jsonnet | 12 ++++++++++++ gitlab/tests/external-catalog.env | 2 +- gitlab/tests/golden/external-catalog.yml | 2 ++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/gitlab/commodore-compile.jsonnet b/gitlab/commodore-compile.jsonnet index 5ce2bb2..0f9e7c7 100644 --- a/gitlab/commodore-compile.jsonnet +++ b/gitlab/commodore-compile.jsonnet @@ -21,12 +21,16 @@ local cpu_requests = to_array('cpu_requests'); local gitInsteadOf(cluster) = local cluster_access_token = '${ACCESS_TOKEN_%s}' % std.strReplace(cluster, '-', '_'); + local cluster_access_user = '${ACCESS_USER_%s:-token}' % std.strReplace(cluster, '-', '_'); local cluster_repo = cluster_catalog_urls[cluster]; local ssh_gitlab = 'ssh://git@%s/' % gitlab_ssh_host; local catalog_path = if std.startsWith(cluster_repo, ssh_gitlab) then // prefix ssh://git@ 0 == ssh, 1 == '', 2 == std.join('/', std.split(cluster_repo, '/')[3:]); + local https_catalog = if std.startsWith(cluster_repo, 'https://') then + std.substr(cluster_repo, std.length('https://'), std.length(cluster_repo)); + local catalogInsteadOf = if catalog_path != null then [ @@ -36,6 +40,14 @@ local gitInsteadOf(cluster) = gitlab_fqdn: gitlab_fqdn, }, ] + else if https_catalog != null then + [ + 'git config --global url."https://%(catalog_user)s:%(access_token)s@%(https_catalog)s".insteadOf https://%(https_catalog)s' % { + catalog_user: cluster_access_user, + access_token: cluster_access_token, + https_catalog: https_catalog, + }, + ] else []; diff --git a/gitlab/tests/external-catalog.env b/gitlab/tests/external-catalog.env index 9c842bc..309f7ec 100644 --- a/gitlab/tests/external-catalog.env +++ b/gitlab/tests/external-catalog.env @@ -1,2 +1,2 @@ CLUSTERS="c-cluster-id-1234 c-cluster-id-5678 c-cluster-id-1111" -CLUSTER_CATALOG_URLS="c-cluster-id-1234=ssh://git@git.vshn.net/cluster-catalogs/c-cluster-id-1234.git c-cluster-id-5678=ssh://git@git.example.com/cluster-catalogs/c-cluster-id-5678.git c-cluster-id-1111=https://user:pass@git.vshn.net/cluster-catalogs/c-cluster-id-1111.git5" +CLUSTER_CATALOG_URLS="c-cluster-id-1234=ssh://git@git.vshn.net/cluster-catalogs/c-cluster-id-1234.git c-cluster-id-5678=ssh://git@git.example.com/cluster-catalogs/c-cluster-id-5678.git c-cluster-id-1111=https://git.vshn.net/cluster-catalogs/c-cluster-id-1111.git5" diff --git a/gitlab/tests/golden/external-catalog.yml b/gitlab/tests/golden/external-catalog.yml index ed71d77..e404ffa 100644 --- a/gitlab/tests/golden/external-catalog.yml +++ b/gitlab/tests/golden/external-catalog.yml @@ -21,6 +21,7 @@ ], "script": [ "git config --global url.\"https://gitlab-ci-token:${CI_JOB_TOKEN}@git.vshn.net:80\".insteadOf ssh://git@${CI_SERVER_SHELL_SSH_HOST}", + "git config --global url.\"https://${ACCESS_USER_c_cluster_id_1111:-token}:${ACCESS_TOKEN_c_cluster_id_1111}@git.vshn.net/cluster-catalogs/c-cluster-id-1111.git5\".insteadOf https://git.vshn.net/cluster-catalogs/c-cluster-id-1111.git5", "/usr/local/bin/entrypoint.sh commodore catalog compile --tenant-repo-revision-override $CI_COMMIT_SHA c-cluster-id-1111", "(cd catalog/ && git --no-pager diff --staged --output ../diff.txt)" ], @@ -47,6 +48,7 @@ ], "script": [ "git config --global url.\"https://gitlab-ci-token:${CI_JOB_TOKEN}@git.vshn.net:80\".insteadOf ssh://git@${CI_SERVER_SHELL_SSH_HOST}", + "git config --global url.\"https://${ACCESS_USER_c_cluster_id_1111:-token}:${ACCESS_TOKEN_c_cluster_id_1111}@git.vshn.net/cluster-catalogs/c-cluster-id-1111.git5\".insteadOf https://git.vshn.net/cluster-catalogs/c-cluster-id-1111.git5", "/usr/local/bin/entrypoint.sh commodore catalog compile --push c-cluster-id-1111" ], "stage": "deploy",