From patchwork Thu Oct 14 21:33:46 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Simon Tournier X-Patchwork-Id: 33851 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id 3A6F927BBE4; Thu, 14 Oct 2021 22:34:09 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_MSPIKE_H2, SPF_HELO_PASS,T_DKIM_INVALID,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id E45A027BBE3 for ; Thu, 14 Oct 2021 22:34:08 +0100 (BST) Received: from localhost ([::1]:51098 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mb8Ma-0006tQ-2z for patchwork@mira.cbaines.net; Thu, 14 Oct 2021 17:34:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43292) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mb8MU-0006tH-07 for guix-patches@gnu.org; Thu, 14 Oct 2021 17:34:02 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:53920) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mb8MT-0001rx-O6 for guix-patches@gnu.org; Thu, 14 Oct 2021 17:34:01 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1mb8MT-0004lT-La for guix-patches@gnu.org; Thu, 14 Oct 2021 17:34:01 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#51216] [PATCH 1/1] swh: Allows token from Software Heritage authentication service. References: <20211014213238.3270613-1-zimon.toutoune@gmail.com> In-Reply-To: <20211014213238.3270613-1-zimon.toutoune@gmail.com> Resent-From: zimoun Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Thu, 14 Oct 2021 21:34:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 51216 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 51216@debbugs.gnu.org Cc: zimoun Received: via spool by 51216-submit@debbugs.gnu.org id=B51216.163424723718290 (code B ref 51216); Thu, 14 Oct 2021 21:34:01 +0000 Received: (at 51216) by debbugs.gnu.org; 14 Oct 2021 21:33:57 +0000 Received: from localhost ([127.0.0.1]:37233 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mb8MP-0004kt-8i for submit@debbugs.gnu.org; Thu, 14 Oct 2021 17:33:57 -0400 Received: from mail-wr1-f47.google.com ([209.85.221.47]:37696) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mb8MM-0004kB-IA for 51216@debbugs.gnu.org; Thu, 14 Oct 2021 17:33:55 -0400 Received: by mail-wr1-f47.google.com with SMTP id e12so22760111wra.4 for <51216@debbugs.gnu.org>; Thu, 14 Oct 2021 14:33:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=da1LKgqJdQZT5gfIhnwBtSEI9OUgIxaMI4gcrTXMa+g=; b=eTHrukkLq0ru3Fkhzje8FodFT8QzoraM0394eiaUtx/Q9vgg0JNlExQQ2YC9c6pAMc vptjnyHSxFbAihQMO1OKoHFgn6rAjPd58uFV+NRZSipOtHdSbeHpPykdKA9Fe+fm6u80 FtCak5Rq6T/hvykQkuauohadahx4fRZbkQK2jSb1W+hn5trr3Mj+5gJk4KK6N2WimsHq Z0MJNv2B3398o4cSOWsPq+4atiqXrHKQsOdcSIAWLPJ24r71D86Ka/MKAaOXVUTGltS5 AVa3ABKDZk7vb/KVyoTX43HeEmSW2lwW75RT5wpjIFgc3uoQutvPF2LrB2efjmXyGXDg 75tQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=da1LKgqJdQZT5gfIhnwBtSEI9OUgIxaMI4gcrTXMa+g=; b=hF1K4jJMLLh9fqsuFYQQFQmqrKLf3+myrDmPCaZQ+a4NO6xnUq8YzsoNCTqwKahpy2 sBLOWqrCCZMjGfFr5LzZVddi9Z9h/AiLVitc7qpZCIKtBJQqC+NEym9kcOdAdXbRxFbk 4wUQezllbBI4q+onI8HSVFbBY+wMeehMOSiVt5uHjtTqxB9Qknk2mm4MnN7Qfi0G1BfD Fg+mib5EAalRZSnLTKhmwnHIadtkWb/K3ooMbKv8kj2upZDA32nUCfcecSS5wQ4UIO95 B2pJdYfQV0LqGz9+k4lUdRemHS9isVM+1jGJsUcVeAJHc7ATPj61LBePFn+PikyQ7WDv hUcQ== X-Gm-Message-State: AOAM531/2XU5Tf6/CqRLrG4jCWesxAw1i1d9nGwHhcpLtRRJK9PSVqwY Zw8YRwsp9/EXaaf51qRR/JTE6Yd2o3I= X-Google-Smtp-Source: ABdhPJxvF69zod7dXl1qThBdpuFzItq6d33s1u6zPpw5bb7KFOgjjxHv5hvL6XjfWDiaOXSaOIVTEg== X-Received: by 2002:adf:e584:: with SMTP id l4mr9414890wrm.173.1634247228510; Thu, 14 Oct 2021 14:33:48 -0700 (PDT) Received: from localhost.localdomain ([193.48.40.117]) by smtp.gmail.com with ESMTPSA id k27sm3205993wms.21.2021.10.14.14.33.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Oct 2021 14:33:48 -0700 (PDT) From: zimoun Date: Thu, 14 Oct 2021 23:33:46 +0200 Message-Id: <20211014213346.3270670-1-zimon.toutoune@gmail.com> X-Mailer: git-send-email 2.32.0 MIME-Version: 1.0 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: "Guix-patches" X-getmail-retrieved-from-mailbox: Patches The token is provided using the environment variable GUIX_SWH_TOKEN. * guix/swh.scm (swh-token): New variable. (http-get*, http-post*): Use it. --- guix/swh.scm | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/guix/swh.scm b/guix/swh.scm index 5c41685a24..38a4af723a 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. ;;; @@ -153,12 +154,30 @@ (define url url (string-append url "/"))) +;; Token from an account to the Software Heritage Authentication service +;; +(define swh-token + (match (getenv "GUIX_SWH_TOKEN") + (#f #f) + ((? string-null? s) #f) + ((? string? s) (string->symbol s)))) + ;; XXX: Work around a bug in Guile 3.0.2 where #:verify-certificate? would ;; be ignored (). (define* (http-get* uri #:rest rest) - (apply http-request uri #:method 'GET rest)) + (apply http-request uri #:method 'GET + #:headers + (if swh-token + `((authorization . (Bearer ,swh-token))) + '()) + rest)) (define* (http-post* uri #:rest rest) - (apply http-request uri #:method 'POST rest)) + (apply http-request uri #:method 'POST + #:headers + (if swh-token + `((authorization . (Bearer ,swh-token))) + '()) + rest)) (define %date-regexp ;; Match strings like "2014-11-17T22:09:38+01:00" or