@create.command()
@click.option(
- "-c", "--config", type=str, required=True, help="Repo config file for how the Nexus repository should be created."
+ "-c",
+ "--configfile",
+ type=str,
+ required=True,
+ help="Repo config file for how the Nexus repository should be created.",
+)
+@click.option(
+ "-s", "--settings", type=str, required=False, help="Optional config file containing administrative settings."
+)
+@click.option(
+ "-u",
+ "--url",
+ type=str,
+ required=False,
+ help=(
+ "Nexus server URL. In the format https:// Can also be set as {} in the environment."
+ "This will override any URL set in settings.yaml."
+ ).format(NEXUS_URL_ENV),
)
-@click.option("-s", "--settings", type=str, required=True, help="Config file containing administrative settings.")
@click.pass_context
-def repo(ctx, config, settings):
+def repo(ctx, configfile, url, settings=False):
"""Create a Nexus repository as defined by a repo-config.yaml file."""
- nexuscmd.create_repos(config, settings)
+ nexuscmd.create_repos(configfile, settings, url)
@create.command()
def get_credentials(settings_file, url=None):
"""Return credentials for Nexus instantiation."""
+
if settings_file:
try:
with open(settings_file, "r") as f:
_nexus.update_repo_group_details(repo_id, repo_update)
-def create_repos(config_file, settings_file):
+def create_repos(config_file, settings_file, url):
"""Create repositories as defined by configuration file.
- :arg str config: Configuration file containing repository definitions that
+ :arg str config_file: Configuration file containing repository definitions that
will be used to create the new Nexus repositories.
:arg str settings: Settings file containing administrative credentials and
information.
+ :arg str url: url in the format https:// user nad password will be taken from lftools
+ if url is provided.
"""
+ if not settings_file:
+ from lftools import config
+
+ settings_url = url.replace("https://", "")
+ password = config.get_setting(settings_url, "password")
+ username = config.get_setting(settings_url, "username")
+
with open(config_file, "r") as f:
config = yaml.safe_load(f)
- with open(settings_file, "r") as f:
- settings = yaml.safe_load(f)
+ if settings_file:
+ with open(settings_file, "r") as f:
+ settings = yaml.safe_load(f)
for setting in ["email_domain", "base_groupId", "repositories"]:
if not setting in config:
log.error("{} needs to be defined in {}".format(setting, config_file))
sys.exit(1)
- for setting in ["nexus", "user", "password"]:
- if not setting in settings:
- log.error("{} needs to be defined in {}".format(setting, settings_file))
- sys.exit(1)
+ if settings_file:
+ for setting in ["nexus", "user", "password"]:
+ if not setting in settings:
+ log.error("{} needs to be defined in {}".format(setting, settings_file))
+ sys.exit(1)
- _nexus = Nexus(settings["nexus"], settings["user"], settings["password"])
+ if settings_file:
+ _nexus = Nexus(settings["nexus"], settings["user"], settings["password"])
+ else:
+ _nexus = Nexus(url, username, password)
def create_nexus_perms(name, targets, email, password, extra_privs=[]):
# Create target
except LookupError as e:
_nexus.create_user(name, email, role_id, password, extra_privs)
- def build_repo(repo, repoId, config, base_groupId, global_privs, email_domain):
+ def build_repo(repo, repoId, config, base_groupId, global_privs, email_domain, strict=True):
log.info("-> Building for {}.{} in Nexus".format(base_groupId, repo))
groupId = "{}.{}".format(base_groupId, repo)
- target = util.create_repo_target_regex(groupId)
+ target = util.create_repo_target_regex(groupId, strict)
if not global_privs and not "extra_privs" in config:
extra_privs = []
global_privs = config["global_privs"]
else:
global_privs = []
+ if "strict_url_regex" in config:
+ strict = config["strict_url_regex"]
+ else:
+ strict = True
for repo in config["repositories"]:
build_repo(
- repo, repo, config["repositories"][repo], config["base_groupId"], global_privs, config["email_domain"]
+ repo,
+ repo,
+ config["repositories"][repo],
+ config["base_groupId"],
+ global_privs,
+ config["email_domain"],
+ strict,
)
"""
with open(config_file, "r") as f:
config = yaml.safe_load(f)
+
with open(settings_file, "r") as f:
settings = yaml.safe_load(f)
log = logging.getLogger(__name__)
-def create_repo_target_regex(group_id):
- """Create a repo_target for Nexus use."""
- return "^/{}/.*".format(group_id.replace(".", "[/\.]"))
+def create_repo_target_regex(group_id, strict=True):
+ """
+ Create a repo_target for Nexus use.
+
+ Example: group_id = "org.o-ran-sc.org"
+ Strict = False : --> "/org/o/ran/sc/org
+ Strict = True : --> "/org/o-ran-sc/org/"
+ """
+
+ repotarget = "^/{}/.*".format(group_id.replace(".", "[/\.]"))
+ if strict:
+ return repotarget
+ else:
+ # Replace - with regex
+ return repotarget.replace("-", "[/\.]")
--- /dev/null
+---
+fixes:
+ - |
+ project names with many dashes such as
+ integration-simulators-pnf-simulator
+ should allow . or - in their pom.xml
+ fix the regex to replace - with [/\.]
+ when creating a new nexus2 Repository target.
+
+ This is enabled by setting strict_url_regex=False in config file.
+
def test_create_repo_target_regex():
"""Test create_repo_target_regex() command."""
- odlparent = util.create_repo_target_regex("org.opendaylight.odlparent")
- odlparent_regex = re.compile(odlparent)
- assert odlparent_regex.match(
- "/org/opendaylight/odlparent/odlparent" "/4.0.0-SNAPSHOT/odlparent-4.0.0-20180424.132124-69.pom"
- )
-
- honeycomb = util.create_repo_target_regex("org.opendaylight.honeycomb.vbd")
- honeycomb_regex = re.compile(honeycomb)
- assert honeycomb_regex.match(
- "/org/opendaylight/honeycomb/vbd/odl-vbd" "/1.4.0-SNAPSHOT/odl-vbd-1.4.0-20180422.024456-12-features.xml"
- )
-
- mso = util.create_repo_target_regex("org.openecomp.mso")
- mso_regex = re.compile(mso)
- assert mso_regex.match("/org/openecomp/mso/" "1.1.0-SNAPSHOT/mso-1.1.0-20170606.171056-26.pom")
-
- dcaegen2 = util.create_repo_target_regex("org.onap.dcaegen2")
- dcaegen2_regex = re.compile(dcaegen2)
- assert dcaegen2_regex.match("/org/onap/dcaegen2/" "1.2.0-SNAPSHOT/dcaegen2-1.2.0-20180403.182529-10.pom")
-
- vpp = util.create_repo_target_regex("io.fd.vpp")
- vpp_regex = re.compile(vpp)
- assert vpp_regex.match("/io/fd/vpp/jvpp/16.06/jvpp-16.06.jar")
+ test_url_3_par = [
+ [False, "org.o-ran-sc.org", "/org/o/ran/sc/org/"],
+ [
+ False,
+ "org.opendaylight.odlparent",
+ "/org/opendaylight/odlparent/odlparent/4.0.0-SNAPSHOT/odlparent-4.0.0-20180424.132124-69.pom",
+ ],
+ [
+ False,
+ "org.opendaylight.honeycomb.vbd",
+ "/org/opendaylight/honeycomb/vbd/odl-vbd/1.4.0-SNAPSHOT/odl-vbd-1.4.0-20180422.024456-12-features.xml",
+ ],
+ [False, "org.openecomp.mso", "/org/openecomp/mso/1.1.0-SNAPSHOT/mso-1.1.0-20170606.171056-26.pom"],
+ [False, "org.onap.dcaegen2", "/org/onap.dcaegen2/1.2.0-SNAPSHOT/dcaegen2-1.2.0-20180403.182529-10.pom"],
+ [False, "io.fd.vpp", "/io/fd/vpp/jvpp/16.06/jvpp-16.06.jar"],
+ [True, "org.o-ran-sc.org", "/org/o-ran-sc/org/"],
+ [True, "org.o-ran-sc.org", "/org/o-ran-sc/org/ric-plt-lib-rmr"],
+ [
+ True,
+ "org.opendaylight.odlparent",
+ "/org/opendaylight/odlparent/odlparent/4.0.0-SNAPSHOT/odlparent-4.0.0-20180424.132124-69.pom",
+ ],
+ [
+ True,
+ "org.opendaylight.honeycomb.vbd",
+ "/org/opendaylight/honeycomb/vbd/odl-vbd/1.4.0-SNAPSHOT/odl-vbd-1.4.0-20180422.024456-12-features.xml",
+ ],
+ [True, "org.openecomp.mso", "/org/openecomp/mso/1.1.0-SNAPSHOT/mso-1.1.0-20170606.171056-26.pom"],
+ [True, "org.onap.dcaegen2", "/org/onap/dcaegen2/1.2.0-SNAPSHOT/dcaegen2-1.2.0-20180403.182529-10.pom"],
+ [True, "io.fd.vpp", "/io/fd/vpp/jvpp/16.06/jvpp-16.06.jar"],
+ ]
+
+ for url in test_url_3_par:
+ a = util.create_repo_target_regex(url[1], url[0])
+ a_regex = re.compile(a)
+ assert a_regex.match(url[2]) != None
+
+ test_url_2_par = [
+ ["org.o-ran-sc.org", "/org/o-ran-sc/org/"],
+ [
+ "org.opendaylight.odlparent",
+ "/org/opendaylight/odlparent/odlparent/4.0.0-SNAPSHOT/odlparent-4.0.0-20180424.132124-69.pom",
+ ],
+ [
+ "org.opendaylight.honeycomb.vbd",
+ "/org/opendaylight/honeycomb/vbd/odl-vbd/1.4.0-SNAPSHOT/odl-vbd-1.4.0-20180422.024456-12-features.xml",
+ ],
+ ["org.openecomp.mso", "/org/openecomp/mso/1.1.0-SNAPSHOT/mso-1.1.0-20170606.171056-26.pom"],
+ ["org.onap.dcaegen2", "/org/onap/dcaegen2/1.2.0-SNAPSHOT/dcaegen2-1.2.0-20180403.182529-10.pom"],
+ ["io.fd.vpp", "/io/fd/vpp/jvpp/16.06/jvpp-16.06.jar"],
+ ]
+
+ for url in test_url_2_par:
+ a = util.create_repo_target_regex(url[0])
+ a_regex = re.compile(a)
+ assert a_regex.match(url[1]) != None