From patchwork Thu Dec 29 18:13:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: pukkamustard X-Patchwork-Id: 45685 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 E57DF27BBED; Thu, 29 Dec 2022 18:54:32 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-3.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id 8D3BB27BBE9 for ; Thu, 29 Dec 2022 18:54:31 +0000 (GMT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pAxQp-0000CD-Fj; Thu, 29 Dec 2022 13:15:08 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pAxQl-0000AH-6k for guix-patches@gnu.org; Thu, 29 Dec 2022 13:15:03 -0500 Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pAxQk-000460-TW for guix-patches@gnu.org; Thu, 29 Dec 2022 13:15:02 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1pAxQk-0007RQ-PA for guix-patches@gnu.org; Thu, 29 Dec 2022 13:15:02 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#52555] [PATCH v3 3/8] publish: Add HTTP endpoint for resolving ERIS blocks. Resent-From: pukkamustard Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Thu, 29 Dec 2022 18:15:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 52555 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 52555@debbugs.gnu.org Cc: pukkamustard Received: via spool by 52555-submit@debbugs.gnu.org id=B52555.167233767628495 (code B ref 52555); Thu, 29 Dec 2022 18:15:02 +0000 Received: (at 52555) by debbugs.gnu.org; 29 Dec 2022 18:14:36 +0000 Received: from localhost ([127.0.0.1]:32806 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pAxQK-0007PQ-AR for submit@debbugs.gnu.org; Thu, 29 Dec 2022 13:14:36 -0500 Received: from mout02.posteo.de ([185.67.36.66]:36003) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pAxQC-0007OI-DL for 52555@debbugs.gnu.org; Thu, 29 Dec 2022 13:14:29 -0500 Received: from submission (posteo.de [185.67.36.169]) by mout02.posteo.de (Postfix) with ESMTPS id E41B62401A9 for <52555@debbugs.gnu.org>; Thu, 29 Dec 2022 19:14:22 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1672337662; bh=7ucG2aEORDt0EkiJ7tlZhrXCVtV20NuUyG5fyIXtlLw=; h=From:To:Cc:Subject:Date:From; b=UeM+QlMO0JxAbCTDMB9I+C5ReuvbFqqnir/JNRT7DwV0sNGJXBqtDEwbS4F+Ejvp2 StQ5lWzKwGOSYWuwl11l2mcaTnWpJRcS0vNrVlNJi7/gKZRcKx6p6b9lgQfkiFzQC1 EbFm3DEHSJU7ZVf32t2im+lw7mEFgET5VHHbLtcDf/DxD46x/ONvT5p6rvmgz7EgXX /Ra2FXjtFGRvR4B0j+OnUioR9Y0WLDJsSTMXf1k4q1KWFz8dIN8nkcIrj9eVm3wOyd RspPmI2m0JbPJHHoZ9epxs58wg7tJsgPNR5GAKJps04/tzaCRADM3t8s8DRoaya5cE Dy6OrJaPf+eww== Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4Njc3f2lbTz6tmY; Thu, 29 Dec 2022 19:14:22 +0100 (CET) From: pukkamustard Date: Thu, 29 Dec 2022 18:13:22 +0000 Message-Id: <20221229181327.758-4-pukkamustard@posteo.net> In-Reply-To: <20221229181327.758-1-pukkamustard@posteo.net> References: <20221229181327.758-1-pukkamustard@posteo.net> 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-bounces+patchwork=mira.cbaines.net@gnu.org X-getmail-retrieved-from-mailbox: Patches * guix/eris/http.scm: New file. * Makefile.am (MODULES): Add it. * guix/scripts/publish.scm (make-request-handler): Add handler for RFC 2169 URN resolution endpoint. --- Makefile.am | 1 + guix/eris/http.scm | 40 ++++++++++++++++++++++++++++++++++++++++ guix/scripts/publish.scm | 20 ++++++++++++++++++++ 3 files changed, 61 insertions(+) create mode 100644 guix/eris/http.scm diff --git a/Makefile.am b/Makefile.am index c549fc8580..373f6b7c27 100644 --- a/Makefile.am +++ b/Makefile.am @@ -134,6 +134,7 @@ MODULES = \ guix/ipfs.scm \ guix/eris.scm \ guix/eris/fs-store.scm \ + guix/eris/http.scm \ guix/platform.scm \ guix/platforms/arm.scm \ guix/platforms/mips.scm \ diff --git a/guix/eris/http.scm b/guix/eris/http.scm new file mode 100644 index 0000000000..a8a9520197 --- /dev/null +++ b/guix/eris/http.scm @@ -0,0 +1,40 @@ +;;; GNU Guix --- Functional package management for GNU +;;; Copyright © 2022 pukkamustard +;;; +;;; This file is part of GNU Guix. +;;; +;;; GNU Guix is free software; you can redistribute it and/or modify it +;;; under the terms of the GNU General Public License as published by +;;; the Free Software Foundation; either version 3 of the License, or (at +;;; your option) any later version. +;;; +;;; GNU Guix is distributed in the hope that it will be useful, but +;;; WITHOUT ANY WARRANTY; without even the implied warranty of +;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;;; GNU General Public License for more details. +;;; +;;; You should have received a copy of the GNU General Public License +;;; along with GNU Guix. If not, see . + +(define-module (guix eris http) + #:use-module (eris utils base32) + #:use-module (web uri) + + #:use-module (srfi srfi-2) + + #:export (make-blake2b-urn-query-ref)) + +(define blake2b-uri-path-regexp + (make-regexp "^blake2b:" regexp/icase)) + +(define (make-blake2b-urn-query-ref block-ref) + (lambda (query) + (and-let* ((_ query) ; ensure query is not false + (urn (string->uri query)) + (_ (uri? urn)) + (_ (eqv? (uri-scheme urn) 'urn)) + (_ (regexp-exec blake2b-uri-path-regexp + (uri-path urn))) + (blake2b-ref (base32-decode + (string-drop (uri-path urn) 8)))) + (block-ref blake2b-ref)))) diff --git a/guix/scripts/publish.scm b/guix/scripts/publish.scm index 7f14e4d4d4..15bdf02670 100644 --- a/guix/scripts/publish.scm +++ b/guix/scripts/publish.scm @@ -53,6 +53,8 @@ (define-module (guix scripts publish) #:use-module (guix config) #:use-module (guix derivations) #:use-module (guix eris) + #:use-module (guix eris fs-store) + #:use-module (guix eris http) #:use-module (gcrypt hash) #:use-module (guix pki) #:use-module (gcrypt pk-crypto) @@ -1083,6 +1085,14 @@ (define nar-path? (let ((expected (split-and-decode-uri-path nar-path))) (cut equal? expected <>))) + ;; Get ERIS blocks directly from the filesystem store. + (define eris-block-ref + (eris-fs-store-ref (%eris-block-store-directory))) + + ;; Create a handler for resolving blake2b URN queries. + (define blake2b-urn-query-ref + (make-blake2b-urn-query-ref eris-block-ref)) + (define (handle request body) (format #t "~a ~a~%" (request-method request) @@ -1125,6 +1135,16 @@ (define (handle request body) (("log" name) (render-log-file store request name)) + ;; /uri-res/N2R - RFC2169 URN resolution + (("uri-res" "N2R") + (let ((block (blake2b-urn-query-ref + (uri-query (request-uri request))))) + (if block + (values `((content-type . (application/octet-stream + (charset . "ISO-8859-1")))) + block) + (not-found request)))) + ;; Use different URLs depending on the compression type. This ;; guarantees that /nar URLs remain valid even when 'guix publish' ;; is restarted with different compression parameters.