public inbox for gentoo-dev@lists.gentoo.org
 help / color / mirror / Atom feed
From: "Maciej Barć" <xgqt@gentoo.org>
To: gentoo-dev@lists.gentoo.org
Cc: dotnet@gentoo.org, "Maciej Barć" <xgqt@gentoo.org>
Subject: [gentoo-dev] [PATCH 7/7] eclass/dotnet-pkg.eclass: prepare for safely using Nuget
Date: Sat,  3 Feb 2024 17:24:18 +0100	[thread overview]
Message-ID: <20240203162422.91906-7-xgqt@gentoo.org> (raw)
In-Reply-To: <20240203162422.91906-1-xgqt@gentoo.org>

Signed-off-by: Maciej Barć <xgqt@gentoo.org>
---
 eclass/dotnet-pkg.eclass |  8 +++++--
 eclass/nuget.eclass      | 47 +++++++++++++++++++++++++++++++++++++++-
 2 files changed, 52 insertions(+), 3 deletions(-)

diff --git a/eclass/dotnet-pkg.eclass b/eclass/dotnet-pkg.eclass
index 3647eb399..337864f1f 100644
--- a/eclass/dotnet-pkg.eclass
+++ b/eclass/dotnet-pkg.eclass
@@ -225,12 +225,16 @@ dotnet-pkg_remove-bad() {
 # Default "src_prepare" for the "dotnet-pkg" eclass.
 # Prepare the package sources.
 #
-# Run "dotnet-pkg-base_remove-global-json"
-# and "dotnet-pkg-base_remove-bad" for each found solution file.
+# Run "dotnet-pkg-base_remove-global-json", "dotnet-pkg-base_remove-bad"
+# for each found solution file and prepare for using Nuget.
 dotnet-pkg_src_prepare() {
 	dotnet-pkg-base_remove-global-json
 	dotnet-pkg-base_foreach-solution "$(pwd)" dotnet-pkg_remove-bad
 
+	find "$(pwd)" -maxdepth 1 -iname "nuget.config" -delete ||
+		die "${FUNCNAME[0]}: failed to remove unwanted \"NuGet.config\" config files"
+	nuget_writeconfig "$(pwd)/"
+
 	default
 }
 
diff --git a/eclass/nuget.eclass b/eclass/nuget.eclass
index 669e21300..ac8629848 100644
--- a/eclass/nuget.eclass
+++ b/eclass/nuget.eclass
@@ -1,4 +1,4 @@
-# Copyright 1999-2023 Gentoo Authors
+# Copyright 1999-2024 Gentoo Authors
 # Distributed under the terms of the GNU General Public License v2
 
 # @ECLASS: nuget.eclass
@@ -226,6 +226,51 @@ nuget_unpack-non-nuget-archives() {
 	done
 }
 
+# @FUNCTION: nuget_writeconfig
+# @USAGE: <path>
+# @DESCRIPTION:
+# Create a "NuGet.config" config file that can be used to overwrite any other
+# Nuget configuration file in order to prevent Nuget executable from accessing
+# the network or undesired NuPkg package sources.
+#
+# If given path ends with a slash, a file name "NuGet.config" is assumed,
+# otherwise contents are written to specified file path exactly.
+#
+# Created configuration file clears all other NuPkg sources and inserts
+# "NUGET_PACKAGES" as the only one source.
+#
+# This function is used inside "dotnet-pkg_src_prepare"
+# from the "dotnet-pkg" eclass.
+#
+# This function is used inside "dotnet-pkg_src_prepare"
+# from the "dotnet-pkg" eclass.
+nuget_writeconfig() {
+	debug-print-function "${FUNCNAME[0]}" "${@}"
+
+	case "${1}" in
+		"" ) die "${FUNCNAME[0]}: no directory/file path specified" ;;
+		*/ ) mkdir -p "${1}" || die ;;
+	esac
+
+	local nuget_config_path
+
+	if [[ -d "${1}" ]] ; then
+		nuget_config_path="${1}/NuGet.config"
+	else
+		nuget_config_path="${1}"
+	fi
+
+	cat <<-EOF > "${nuget_config_path}" || die
+	<?xml version="1.0" encoding="utf-8"?>
+	<configuration>
+		<packageSources>
+			<clear />
+			<add key="nuget" value="${NUGET_PACKAGES}" />
+		</packageSources>
+	</configuration>
+	EOF
+}
+
 # @FUNCTION: nuget_donuget
 # @USAGE: <nuget-path> ...
 # @DESCRIPTION:
-- 
2.43.0



  parent reply	other threads:[~2024-02-03 16:26 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-03 16:24 [gentoo-dev] [PATCH 1/7] eclass/dotnet-pkg-base.eclass: quotes and style tweaks for edge cases Maciej Barć
2024-02-03 16:24 ` [gentoo-dev] [PATCH 2/7] eclass/dotnet-pkg-base.eclass: deprecate wring-style names Maciej Barć
2024-02-03 16:53   ` Ulrich Mueller
2024-02-03 17:09     ` Maciej Barć
2024-02-03 16:24 ` [gentoo-dev] [PATCH 3/7] eclass/dotnet-pkg-base.eclass: dotnet-pkg-base_test - remove directory magic Maciej Barć
2024-02-03 16:24 ` [gentoo-dev] [PATCH 4/7] eclass/dotnet-pkg*: add dotnet-pkg_remove-bad Maciej Barć
2024-02-03 16:24 ` [gentoo-dev] [PATCH 5/7] eclass/dotnet-pkg.eclass: add dotnet-pkg_force-compat Maciej Barć
2024-02-03 16:55   ` Ulrich Mueller
2024-02-03 16:24 ` [gentoo-dev] [PATCH 6/7] eclass/dotnet-pkg-base.eclass: set DOTNET_ROOT Maciej Barć
2024-02-03 16:24 ` Maciej Barć [this message]
2024-02-03 16:57   ` [gentoo-dev] [PATCH 7/7] eclass/dotnet-pkg.eclass: prepare for safely using Nuget Ulrich Mueller
2024-02-03 17:07     ` Maciej Barć
2024-02-03 16:51 ` [gentoo-dev] [PATCH 1/7] eclass/dotnet-pkg-base.eclass: quotes and style tweaks for edge cases Ulrich Mueller
2024-02-08  7:02 ` Sam James
2024-02-08  8:36   ` Maciej Barć

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

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

  git send-email \
    --in-reply-to=20240203162422.91906-7-xgqt@gentoo.org \
    --to=xgqt@gentoo.org \
    --cc=dotnet@gentoo.org \
    --cc=gentoo-dev@lists.gentoo.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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox