@@ -15,12 +15,24 @@ Supported SRC_URI options are:
- destsuffix
Specifies the directory to use to unpack the dependencies (default: ${S}).
+
+- username
+ Specifies the basic auth username to use when accessing an npm registry specified in the shrinkwrap.
+
+- password
+ Specifies the basic auth password (or API key) to use when accessing the npm registry specified in the shrinkwrap.
+
+- basic_auth_registry
+ Specifies the registry within the npm shrinkwrap to use basic authentication with.
+ NOTE: This parameter is optional - if nothing is passed in but a username/password IS supplied, then
+ fetcher will assume to use basic auth credentials for all registries within the shrinkwrap file.
"""
import json
import os
import re
import bb
+import urllib.parse
from bb.fetch2 import Fetch
from bb.fetch2 import FetchMethod
from bb.fetch2 import ParameterError
@@ -67,10 +79,26 @@ class NpmShrinkWrap(FetchMethod):
def urldata_init(self, ud, d):
"""Init npmsw specific variables within url data"""
+ ud.shrinkwrap_file = None
+ ud.dev = None
+ ud.deps = None
+ ud.basic_auth_registry = None
+ ud.username = None
+ ud.password = None
# Get the 'shrinkwrap' parameter
ud.shrinkwrap_file = re.sub(r"^npmsw://", "", ud.url.split(";")[0])
+ if "basic_auth_registry" in ud.parm:
+ ud.basic_auth_registry = ud.parm.get("basic_auth_registry")
+
+ if "username" in ud.parm:
+ ud.username = ud.parm.get("username")
+
+ if "password" in ud.parm:
+ ud.password = ud.parm.get("password")
+
+
# Get the 'dev' parameter
ud.dev = bb.utils.to_boolean(ud.parm.get("dev"), False)
@@ -107,6 +135,14 @@ class NpmShrinkWrap(FetchMethod):
checksum_name, checksum_expected = npm_integrity(integrity)
uri.params[checksum_name] = checksum_expected
+ # Check if the registry we are using matches the registry passed in
+ # that the user wants to use for basic authentication
+ if ud.basic_auth_registry is not None:
+ use_basic_auth = urllib.parse.urlparse(resolved).hostname in ud.basic_auth_registry
+ if (ud.username is not None and ud.password is not None and use_basic_auth):
+ uri.params["user"] = ud.username
+ uri.params["pswd"] = ud.password
+
url = str(uri)
localpath = os.path.join(d.getVar("DL_DIR"), localfile)