Message ID | 20250228130137.400-2-eric.meyers@arthrex.com |
---|---|
State | Accepted, archived |
Commit | 5fa6137b6d98544766f3152b874e67d04fafb88f |
Headers | show |
Series | NPM Fetcher Private Registry Authentication Support: | expand |
On Fri, Feb 28, 2025 at 5:01 AM Eric Meyers <eric.meyers15310@gmail.com> wrote: > Signed-off-by: Eric Meyers <eric.meyers@arthrex.com> > Cc: Geoff Parker <geoffrey.parker@arthrex.com> > Cc: Chuck Wolber <chuckwolber@gmail.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 c09f05044..e469d6676 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: > Signed-off-by: Chuck Wolber <chuckwolber@gmail.com> ..Ch:W..
diff --git a/lib/bb/fetch2/npm.py b/lib/bb/fetch2/npm.py index c09f05044..e469d6676 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:
Signed-off-by: Eric Meyers <eric.meyers@arthrex.com> Cc: Geoff Parker <geoffrey.parker@arthrex.com> Cc: Chuck Wolber <chuckwolber@gmail.com> --- lib/bb/fetch2/npm.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+)