From 7e84de1ba02c9d550981343896836cc96296cdff Mon Sep 17 00:00:00 2001 From: guill Date: Thu, 4 Jul 2024 05:29:40 -0700 Subject: [PATCH] Add support for SSH-style git repo addresses (#835) This allows nodes to be pulled from git repositories that: 1. Require authentication 2. Are located on a computer that does not have any special software beyond an SSH server to serve up git repos 3. Are hosted on sites that exclusively allow SSH access I have also cleaned up the JavaScript regex for identifying valid HTTP addresses. Due to an unescaped '.' and the lack of a count on the first group, it wasn't doing a whole lot anyway -- just checking that the very first character wasn't invalid. --- cm-cli.py | 2 +- glob/manager_core.py | 12 +++++++++--- js/common.js | 5 +++-- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/cm-cli.py b/cm-cli.py index d3dd05aa..518461c5 100644 --- a/cm-cli.py +++ b/cm-cli.py @@ -201,7 +201,7 @@ cm_ctx = Ctx() def install_node(node_name, is_all=False, cnt_msg=''): - if '://' in node_name: + if core.is_valid_url(node_name): # install via urls res = core.gitclone_install([node_name]) if not res: diff --git a/glob/manager_core.py b/glob/manager_core.py index c39bbbb4..3f1bc48f 100644 --- a/glob/manager_core.py +++ b/glob/manager_core.py @@ -515,10 +515,16 @@ class GitProgress(RemoteProgress): def is_valid_url(url): try: + # Check for HTTP/HTTPS URL format result = urlparse(url) - return all([result.scheme, result.netloc]) - except ValueError: - return False + if all([result.scheme, result.netloc]): + return True + finally: + # Check for SSH git URL format + pattern = re.compile(r"^(.+@|ssh:\/\/).+:.+$") + if pattern.match(url): + return True + return False def gitclone_install(files, instant_execution=False, msg_prefix=''): diff --git a/js/common.js b/js/common.js index 7a914953..419862f0 100644 --- a/js/common.js +++ b/js/common.js @@ -34,8 +34,9 @@ function isValidURL(url) { if(url.includes('&')) return false; - const pattern = /^(https?|ftp):\/\/[^\s/$.?#].[^\s]*$/; - return pattern.test(url); + const http_pattern = /^(https?|ftp):\/\/[^\s$?#]+$/; + const ssh_pattern = /^(.+@|ssh:\/\/).+:.+$/; + return http_pattern.test(url) || ssh_pattern.test(url); } export async function install_pip(packages) {