unofficial mirror of guix-patches@gnu.org 
 help / color / mirror / code / Atom feed
From: zimoun <zimon.toutoune@gmail.com>
To: 51216@debbugs.gnu.org
Cc: zimoun <zimon.toutoune@gmail.com>
Subject: [bug#51216] [PATCH v2] swh: Allows token from Software Heritage authentication service.
Date: Fri, 15 Oct 2021 00:14:54 +0200	[thread overview]
Message-ID: <20211014221454.3272836-1-zimon.toutoune@gmail.com> (raw)
In-Reply-To: <20211014213238.3270613-1-zimon.toutoune@gmail.com>

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(+)

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>.

base-commit: cf25ba2d773435af7af2cd315185acb16dcc6b58
-- 
2.32.0





  parent reply	other threads:[~2021-10-14 22:16 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-14 21:32 [bug#51216] [PATCH 0/1] swh: Allows token from Software Heritage authentication service zimoun
2021-10-14 21:33 ` [bug#51216] [PATCH 1/1] " zimoun
2021-10-14 21:46   ` [bug#51216] [PATCH 0/1] " Ludovic Courtès
2021-10-14 21:44 ` Ludovic Courtès
2021-10-14 21:52   ` zimoun
2021-10-14 22:14 ` zimoun [this message]
2021-10-15 20:54   ` bug#51216: " Ludovic Courtès

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://guix.gnu.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211014221454.3272836-1-zimon.toutoune@gmail.com \
    --to=zimon.toutoune@gmail.com \
    --cc=51216@debbugs.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).