From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <pve-devel-bounces@lists.proxmox.com>
Received: from firstgate.proxmox.com (firstgate.proxmox.com [IPv6:2a01:7e0:0:424::9])
	by lore.proxmox.com (Postfix) with ESMTPS id 4C5451FF162
	for <inbox@lore.proxmox.com>; Sat, 27 Jul 2024 17:10:18 +0200 (CEST)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
	by firstgate.proxmox.com (Proxmox) with ESMTP id 6FECA38FC;
	Sat, 27 Jul 2024 17:10:12 +0200 (CEST)
Date: Wed, 17 Jul 2024 18:23:42 +0000
To: pve-devel@lists.proxmox.com
In-Reply-To: <20240717182228.27812-2-root@arnaud.sh>
References: <20240717182228.27812-2-root@arnaud.sh>
X-Mailman-Approved-At: Sat, 27 Jul 2024 17:10:10 +0200
MIME-Version: 1.0
Message-ID: <mailman.3.1722093010.302.pve-devel@lists.proxmox.com>
List-Id: Proxmox VE development discussion <pve-devel.lists.proxmox.com>
List-Post: <mailto:pve-devel@lists.proxmox.com>
From: LightDiscord via pve-devel <pve-devel@lists.proxmox.com>
Precedence: list
Cc: LightDiscord <root@arnaud.sh>
X-Mailman-Version: 2.1.29
X-BeenThere: pve-devel@lists.proxmox.com
List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel>, 
 <mailto:pve-devel-request@lists.proxmox.com?subject=subscribe>
List-Unsubscribe: <https://lists.proxmox.com/cgi-bin/mailman/options/pve-devel>, 
 <mailto:pve-devel-request@lists.proxmox.com?subject=unsubscribe>
List-Archive: <http://lists.proxmox.com/pipermail/pve-devel/>
Reply-To: Proxmox VE development discussion <pve-devel@lists.proxmox.com>
List-Help: <mailto:pve-devel-request@lists.proxmox.com?subject=help>
Subject: [pve-devel] [PATCH pve-storage 1/2] storage: enable upload for
 snippets
Content-Type: multipart/mixed; boundary="===============1217713472710941605=="
Errors-To: pve-devel-bounces@lists.proxmox.com
Sender: "pve-devel" <pve-devel-bounces@lists.proxmox.com>

--===============1217713472710941605==
Content-Type: message/rfc822
Content-Disposition: inline

Return-Path: <root@arnaud.sh>
X-Original-To: pve-devel@lists.proxmox.com
Delivered-To: pve-devel@lists.proxmox.com
Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature RSA-PSS (2048 bits))
	(No client certificate requested)
	by lists.proxmox.com (Postfix) with ESMTPS id E2C97C15AC
	for <pve-devel@lists.proxmox.com>; Wed, 17 Jul 2024 20:33:26 +0200 (CEST)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
	by firstgate.proxmox.com (Proxmox) with ESMTP id C2EEB788
	for <pve-devel@lists.proxmox.com>; Wed, 17 Jul 2024 20:32:56 +0200 (CEST)
Received: from mail-41103.protonmail.ch (mail-41103.protonmail.ch [185.70.41.103])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature RSA-PSS (2048 bits))
	(No client certificate requested)
	by firstgate.proxmox.com (Proxmox) with ESMTPS
	for <pve-devel@lists.proxmox.com>; Wed, 17 Jul 2024 20:32:55 +0200 (CEST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=arnaud.sh;
	s=protonmail; t=1721240628; x=1721499828;
	bh=NixnqMvc0S5mqSiWR9NZk7n6bLIMx4dLicaSGFeBOGk=;
	h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References:
	 Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID:
	 Message-ID:BIMI-Selector;
	b=Azi46Ud16gy4efeK3WuzUCMrW8LPlirCy9ypesZtOm3lpZJ6/DmqBNLOjZJ3JxAw8
	 Dmuvwng9lgWqrkooXt9iESAoOg3IA9MHj/IRKTdMvybk4FSUE5kS6JAwdl9RtbrP1O
	 odCUjRyGcYdLtIqxjsNR3U264z7yT/LS7f7XaIcO3Mud/HJU5xLJ+zMq05C/F6Lgzt
	 ZJoL7UVgC5ZvU51Eb2J73RCPA+dSzrh1p5368ftneWCUSUeJLeR88+FY9BIIroF2IT
	 ieAuM6+xfKj4vqr7X7KQdv5zM+9xJnk4BjpXm9gyqOCwq+trNRTYI39zviOdHM/PY8
	 xQKLicow51V2A==
Date: Wed, 17 Jul 2024 18:23:42 +0000
To: pve-devel@lists.proxmox.com
From: LightDiscord <root@arnaud.sh>
Cc: Arnaud Pascal <root@arnaud.sh>
Subject: [PATCH pve-storage 1/2] storage: enable upload for snippets
Message-ID: <20240717182228.27812-5-root@arnaud.sh>
In-Reply-To: <20240717182228.27812-2-root@arnaud.sh>
References: <20240717182228.27812-2-root@arnaud.sh>
Feedback-ID: 8382646:user:proton
X-Pm-Message-ID: 6e9ab37b98e0533d2f712600502b23205a7daddf
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable
X-SPAM-LEVEL: Spam detection results:  0
	AWL                     0.175 Adjusted score from AWL reputation of From: address
	BAYES_00                 -1.9 Bayes spam probability is 0 to 1%
	DKIM_SIGNED               0.1 Message has a DKIM or DK signature, not necessarily valid
	DKIM_VALID               -0.1 Message has at least one valid DKIM or DK signature
	DKIM_VALID_AU            -0.1 Message has a valid DKIM or DK signature from author's domain
	DKIM_VALID_EF            -0.1 Message has a valid DKIM or DK signature from envelope-from domain
	DMARC_PASS               -0.1 DMARC pass policy
	RCVD_IN_DNSWL_LOW        -0.7 Sender listed at https://www.dnswl.org/, low trust
	SPF_HELO_PASS          -0.001 SPF: HELO matches SPF record
	SPF_PASS               -0.001 SPF: sender matches SPF record
X-Mailman-Approved-At: Sat, 27 Jul 2024 17:10:10 +0200

From: Arnaud Pascal <root@arnaud.sh>

Currently allowing only `.yml` and `.yaml` files.

Signed-off-by: Arnaud Pascal <root@arnaud.sh>
---
 src/PVE/API2/Storage/Status.pm | 14 ++++++++++++--
 src/PVE/Storage.pm             | 11 +++++++++++
 2 files changed, 23 insertions(+), 2 deletions(-)

diff --git a/src/PVE/API2/Storage/Status.pm b/src/PVE/API2/Storage/Status.p=
m
index dc6cc69..d3310e8 100644
--- a/src/PVE/API2/Storage/Status.pm
+++ b/src/PVE/API2/Storage/Status.pm
@@ -382,7 +382,7 @@ __PACKAGE__->register_method ({
 =09    content =3D> {
 =09=09description =3D> "Content type.",
 =09=09type =3D> 'string', format =3D> 'pve-storage-content',
-=09=09enum =3D> ['iso', 'vztmpl'],
+=09=09enum =3D> ['iso', 'vztmpl', 'snippets'],
 =09    },
 =09    filename =3D> {
 =09=09description =3D> "The name of the file to create. Caution: This will=
 be normalized!",
@@ -448,6 +448,11 @@ __PACKAGE__->register_method ({
 =09=09raise_param_exc({ filename =3D> "wrong file extension" });
 =09    }
 =09    $path =3D PVE::Storage::get_vztmpl_dir($cfg, $param->{storage});
+=09} elsif ($content eq 'snippets') {
+=09    if ($filename !~ m![^/]+$PVE::Storage::SNIPPETS_EXT_RE_0$!) {
+=09=09raise_param_exc({ filename =3D> "wrong file extension" });
+=09    }
+=09    $path =3D PVE::Storage::get_snippets_dir($cfg, $param->{storage});
 =09} else {
 =09    raise_param_exc({ content =3D> "upload content type '$content' not =
allowed" });
 =09}
@@ -572,7 +577,7 @@ __PACKAGE__->register_method({
 =09    content =3D> {
 =09=09description =3D> "Content type.", # TODO: could be optional & detect=
ed in most cases
 =09=09type =3D> 'string', format =3D> 'pve-storage-content',
-=09=09enum =3D> ['iso', 'vztmpl'],
+=09=09enum =3D> ['iso', 'vztmpl', 'snippets'],
 =09    },
 =09    filename =3D> {
 =09=09description =3D> "The name of the file to create. Caution: This will=
 be normalized!",
@@ -642,6 +647,11 @@ __PACKAGE__->register_method({
 =09=09raise_param_exc({ filename =3D> "wrong file extension" });
 =09    }
 =09    $path =3D PVE::Storage::get_vztmpl_dir($cfg, $storage);
+=09} elsif ($content eq 'snippets') {
+=09    if ($filename !~ m![^/]+$PVE::Storage::SNIPPETS_EXT_RE_0$!) {
+=09=09raise_param_exc({ filename =3D> "wrong file extension" });
+=09    }
+=09    $path =3D PVE::Storage::get_snippets_dir($cfg, $storage);
 =09} else {
 =09    raise_param_exc({ content =3D> "upload content-type '$content' is n=
ot allowed" });
 =09}
diff --git a/src/PVE/Storage.pm b/src/PVE/Storage.pm
index 57b2038..73cf991 100755
--- a/src/PVE/Storage.pm
+++ b/src/PVE/Storage.pm
@@ -112,6 +112,8 @@ our $ISO_EXT_RE_0 =3D qr/\.(?:iso|img)/i;
=20
 our $VZTMPL_EXT_RE_1 =3D qr/\.tar\.(gz|xz|zst)/i;
=20
+our $SNIPPETS_EXT_RE_0 =3D qr/\.(?:yml|yaml)/i;
+
 our $BACKUP_EXT_RE_2 =3D qr/\.(tgz|(?:tar|vma)(?:\.(${\PVE::Storage::Plugi=
n::COMPRESSOR_RE}))?)/;
=20
 # FIXME remove with PVE 9.0, add versioned breaks for pve-manager
@@ -469,6 +471,15 @@ sub get_vztmpl_dir {
     return $plugin->get_subdir($scfg, 'vztmpl');
 }
=20
+sub get_snippets_dir {
+    my ($cfg, $storeid) =3D @_;
+
+    my $scfg =3D storage_config($cfg, $storeid);
+    my $plugin =3D PVE::Storage::Plugin->lookup($scfg->{type});
+
+    return $plugin->get_subdir($scfg, 'snippets');
+}
+
 sub get_backup_dir {
     my ($cfg, $storeid) =3D @_;
=20
--=20
2.39.2




--===============1217713472710941605==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel

--===============1217713472710941605==--