diff mbox series

[bug#51216,v2] swh: Allows token from Software Heritage authentication service.

Message ID 20211014221454.3272836-1-zimon.toutoune@gmail.com
State Accepted
Headers show
Series [bug#51216,v2] swh: Allows token from Software Heritage authentication service. | expand

Checks

Context Check Description
cbaines/comparison success View comparision
cbaines/git branch success View Git branch
cbaines/applying patch success View Laminar job
cbaines/issue success View issue

Commit Message

Simon Tournier Oct. 14, 2021, 10:14 p.m. UTC
The token is provided using the environment variable GUIX_SWH_TOKEN.

* guix/swh.scm (%swh-token): New variable.
(call): Use it.
---
 guix/swh.scm | 11 +++++++++++
 1 file changed, 11 insertions(+)


base-commit: cf25ba2d773435af7af2cd315185acb16dcc6b58

Comments

Ludovic Courtès Oct. 15, 2021, 8:54 p.m. UTC | #1
zimoun <zimon.toutoune@gmail.com> skribis:

> The token is provided using the environment variable GUIX_SWH_TOKEN.
>
> * guix/swh.scm (%swh-token): New variable.
> (call): Use it.

Applied, thanks!  :-)

Ludo'.
diff mbox series

Patch

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 <ludo@gnu.org>
 ;;; Copyright © 2020 Jakub Kądziołka <kuba@kadziolka.net>
 ;;; Copyright © 2021 Xinglu Chen <public@yoctocell.xyz>
+;;; Copyright © 2021 Simon Tournier <zimon.toutoune@gmail.com>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -136,6 +137,12 @@  (define %verify-swh-certificate?
   ;; 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
+;; <https://archive.softwareheritage.org/api/>
+(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 @@  (define* (call url decode #:optional (method http-get*)
   (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 <https://archive.softwareheritage.org/api/#rate-limiting>.