From 498cd9bcdbab2edacff9459d2c45d7631d9fb2d5 Mon Sep 17 00:00:00 2001 From: zimoun Date: Fri, 15 Oct 2021 00:14:54 +0200 Subject: swh: Allows token from Software Heritage authentication service. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The token is provided using the environment variable GUIX_SWH_TOKEN. * guix/swh.scm (%swh-token): New variable. (call): Use it. Signed-off-by: Ludovic Courtès --- guix/swh.scm | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'guix/swh.scm') diff --git a/guix/swh.scm b/guix/swh.scm index 5c41685a24..c7c1c873a2 100644 --- a/guix/swh.scm +++ b/guix/swh.scm @@ -2,6 +2,7 @@ ;;; Copyright © 2018, 2019, 2020, 2021 Ludovic Courtès ;;; Copyright © 2020 Jakub Kądziołka ;;; Copyright © 2021 Xinglu Chen +;;; Copyright © 2021 Simon Tournier ;;; ;;; This file is part of GNU Guix. ;;; @@ -136,6 +137,12 @@ ;; Whether to verify the X.509 HTTPS certificate for %SWH-BASE-URL. (make-parameter #t)) +;; Token from an account to the Software Heritage Authentication service +;; +(define %swh-token + (make-parameter (and=> (getenv "GUIX_SWH_TOKEN") + string->symbol))) + (define (swh-url path . rest) ;; URLs returned by the API may be relative or absolute. This has changed ;; without notice before. Handle both cases by detecting whether the path @@ -246,6 +253,10 @@ FALSE-IF-404? is true, return #f upon 404 responses." (and ((%allow-request?) url method) (let*-values (((response port) (method url #:streaming? #t + #:headers + (if (%swh-token) + `((authorization . (Bearer ,(%swh-token)))) + '()) #:verify-certificate? (%verify-swh-certificate?)))) ;; See . -- cgit v1.2.3