From 7fd951a97ce47864bb495ea0dda59b155de7bdde Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Guerra?= <1297942+joca-bt@users.noreply.github.com> Date: Wed, 14 Jun 2023 18:31:54 +0200 Subject: [PATCH] fix: support http basic auth for curl downloader (#268) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: João Guerra --- oci/private/download.bzl | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/oci/private/download.bzl b/oci/private/download.bzl index 2e14a0c2..0bc2d07b 100644 --- a/oci/private/download.bzl +++ b/oci/private/download.bzl @@ -1,12 +1,19 @@ "Downloader functions " +load("@aspect_bazel_lib//lib:base64.bzl", "base64") + def _auth_to_header(url, auth): for auth_url in auth: if auth_url == url: auth_val = auth[auth_url] - # TODO: basic type - if auth_val["type"] == "pattern": + if auth_val["type"] == "basic": + credentials = base64.encode("{}:{}".format(auth_val["login"], auth_val["password"])) + return [ + "--header", + "Authorization: Basic {}".format(credentials), + ] + elif auth_val["type"] == "pattern": token = auth_val["pattern"].replace("", auth_val["password"]) return [ "--header",