diff mbox series

[styhead,2.10,v1,1/2] fetch2/npm: Adding npmrc support for private registry authentication

Message ID 20250311122901.13820-2-eric.meyers@arthrex.com
State New
Headers show
Series NPM Fetcher Private Registry Authentication Support | expand

Commit Message

Eric Meyers March 11, 2025, 12:29 p.m. UTC
From: Eric Meyers <eric.meyers15310@gmail.com>

Signed-off-by: Eric Meyers <eric.meyers@arthrex.com>
Cc: Geoff Parker <geoffrey.parker@arthrex.com>
---
 lib/bb/fetch2/npm.py | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

Comments

Eric Meyers March 17, 2025, 6:56 p.m. UTC | #1
On Tue, Mar 11, 2025 at 7:28 AM Eric Meyers <eric.meyers15310@gmail.com>
wrote:

> From: Eric Meyers <eric.meyers15310@gmail.com>
>
> Signed-off-by: Eric Meyers <eric.meyers@arthrex.com>
> Cc: Geoff Parker <geoffrey.parker@arthrex.com>
> ---
>  lib/bb/fetch2/npm.py | 15 +++++++++++++++
>  1 file changed, 15 insertions(+)
>
> diff --git a/lib/bb/fetch2/npm.py b/lib/bb/fetch2/npm.py
> index ac76d64cd..38f460e5b 100644
> --- a/lib/bb/fetch2/npm.py
> +++ b/lib/bb/fetch2/npm.py
> @@ -91,6 +91,12 @@ class NpmEnvironment(object):
>          self.d = d
>
>          self.user_config = tempfile.NamedTemporaryFile(mode="w",
> buffering=1)
> +
> +        hn = self._home_npmrc(d)
> +        if hn is not None:
> +            with open(hn, 'r') as hnf:
> +                self.user_config.write(hnf.read())
> +
>          for key, value in configs:
>              self.user_config.write("%s=%s\n" % (key, value))
>
> @@ -103,6 +109,15 @@ class NpmEnvironment(object):
>          if self.user_config:
>              self.user_config.close()
>
> +    def _home_npmrc(self, d):
> +        """Function to return user's HOME .npmrc file (or None if it
> doesn't exist)"""
> +        home_npmrc_file = os.path.join(os.environ.get("HOME"), ".npmrc")
> +        if d.getVar("BB_USE_HOME_NPMRC") == "1" and
> os.path.exists(home_npmrc_file):
> +            bb.warn(f"BB_USE_HOME_NPMRC flag set and valid .npmrc
> detected - "\
> +                    f"npm fetcher will use {home_npmrc_file}")
> +            return home_npmrc_file
> +        return None
> +
>      def run(self, cmd, args=None, configs=None, workdir=None):
>          """Run npm command in a controlled environment"""
>          with tempfile.TemporaryDirectory() as tmpdir:
>


Just poking this patch submission since I haven't heard anything since
initially submitting it a week ago/haven't seen anything merge yet.

I know @rpurdie said it was borderline new functionality on a previous
thread and might not be accepted into styhead (2.10) and scarthgap (2.8),
but just wanted to have closure if that's the case.

Would be really nice/make our lives easier if this could make it all the
way into scarthgap, but understand if there is hesitation from the
maintainers.

Thanks,
-Eric
Steve Sakoman March 17, 2025, 7:39 p.m. UTC | #2
On Mon, Mar 17, 2025 at 11:56 AM Eric Meyers via
lists.openembedded.org
<eric.meyers15310=gmail.com@lists.openembedded.org> wrote:
>
> On Tue, Mar 11, 2025 at 7:28 AM Eric Meyers <eric.meyers15310@gmail.com> wrote:
>>
>> From: Eric Meyers <eric.meyers15310@gmail.com>
>>
>> Signed-off-by: Eric Meyers <eric.meyers@arthrex.com>
>> Cc: Geoff Parker <geoffrey.parker@arthrex.com>
>> ---
>>  lib/bb/fetch2/npm.py | 15 +++++++++++++++
>>  1 file changed, 15 insertions(+)
>>
>> diff --git a/lib/bb/fetch2/npm.py b/lib/bb/fetch2/npm.py
>> index ac76d64cd..38f460e5b 100644
>> --- a/lib/bb/fetch2/npm.py
>> +++ b/lib/bb/fetch2/npm.py
>> @@ -91,6 +91,12 @@ class NpmEnvironment(object):
>>          self.d = d
>>
>>          self.user_config = tempfile.NamedTemporaryFile(mode="w", buffering=1)
>> +
>> +        hn = self._home_npmrc(d)
>> +        if hn is not None:
>> +            with open(hn, 'r') as hnf:
>> +                self.user_config.write(hnf.read())
>> +
>>          for key, value in configs:
>>              self.user_config.write("%s=%s\n" % (key, value))
>>
>> @@ -103,6 +109,15 @@ class NpmEnvironment(object):
>>          if self.user_config:
>>              self.user_config.close()
>>
>> +    def _home_npmrc(self, d):
>> +        """Function to return user's HOME .npmrc file (or None if it doesn't exist)"""
>> +        home_npmrc_file = os.path.join(os.environ.get("HOME"), ".npmrc")
>> +        if d.getVar("BB_USE_HOME_NPMRC") == "1" and os.path.exists(home_npmrc_file):
>> +            bb.warn(f"BB_USE_HOME_NPMRC flag set and valid .npmrc detected - "\
>> +                    f"npm fetcher will use {home_npmrc_file}")
>> +            return home_npmrc_file
>> +        return None
>> +
>>      def run(self, cmd, args=None, configs=None, workdir=None):
>>          """Run npm command in a controlled environment"""
>>          with tempfile.TemporaryDirectory() as tmpdir:
>
>
>
> Just poking this patch submission since I haven't heard anything since initially submitting it a week ago/haven't seen anything merge yet.
>
> I know @rpurdie said it was borderline new functionality on a previous thread and might not be accepted into styhead (2.10) and scarthgap (2.8), but just wanted to have closure if that's the case.

This does cross the line of adding new functionality, so I'm not
inclined to take it unless Richard (as bitbake maintainer) feels that
an exception should be made.

In any event though, this was only accepted into master a week ago.  I
typically let patches "age" a bit there to see if problems crop up
before backporting.

Steve

> Would be really nice/make our lives easier if this could make it all the way into scarthgap, but understand if there is hesitation from the maintainers.
>
> Thanks,
> -Eric
>
> -=-=-=-=-=-=-=-=-=-=-=-
> Links: You receive all messages sent to this group.
> View/Reply Online (#17449): https://lists.openembedded.org/g/bitbake-devel/message/17449
> Mute This Topic: https://lists.openembedded.org/mt/111638710/3620601
> Group Owner: bitbake-devel+owner@lists.openembedded.org
> Unsubscribe: https://lists.openembedded.org/g/bitbake-devel/unsub [steve@sakoman.com]
> -=-=-=-=-=-=-=-=-=-=-=-
>
diff mbox series

Patch

diff --git a/lib/bb/fetch2/npm.py b/lib/bb/fetch2/npm.py
index ac76d64cd..38f460e5b 100644
--- a/lib/bb/fetch2/npm.py
+++ b/lib/bb/fetch2/npm.py
@@ -91,6 +91,12 @@  class NpmEnvironment(object):
         self.d = d
 
         self.user_config = tempfile.NamedTemporaryFile(mode="w", buffering=1)
+
+        hn = self._home_npmrc(d)
+        if hn is not None:
+            with open(hn, 'r') as hnf:
+                self.user_config.write(hnf.read())
+
         for key, value in configs:
             self.user_config.write("%s=%s\n" % (key, value))
 
@@ -103,6 +109,15 @@  class NpmEnvironment(object):
         if self.user_config:
             self.user_config.close()
 
+    def _home_npmrc(self, d):
+        """Function to return user's HOME .npmrc file (or None if it doesn't exist)"""
+        home_npmrc_file = os.path.join(os.environ.get("HOME"), ".npmrc")
+        if d.getVar("BB_USE_HOME_NPMRC") == "1" and os.path.exists(home_npmrc_file):
+            bb.warn(f"BB_USE_HOME_NPMRC flag set and valid .npmrc detected - "\
+                    f"npm fetcher will use {home_npmrc_file}")
+            return home_npmrc_file
+        return None
+
     def run(self, cmd, args=None, configs=None, workdir=None):
         """Run npm command in a controlled environment"""
         with tempfile.TemporaryDirectory() as tmpdir: