102
102
# git & url (no #rev)
103
103
regex_repo_url = r'^(git\://|file\://|ssh\://|https?\://|)(([^/:@]+)(\:([^/:@]+))?@)?([^/:]{3,})(\:\d+)?[:/](.+?)(\.git|\.hg|\/?)$'
104
104
# mbed url is subset of hg. mbed doesn't support ssh transport though so https? urls cannot be converted to ssh
105
- regex_mbed_url = r'^(https?)://([\ w\-\.]*mbed\.(co\.uk|org|com))/(users|teams)/([\w\-]{1,32})/(repos|code)/([\w\-]+ )/?$'
105
+ regex_mbed_url = r'^(https?)://(([^/:@]+)(\:([^/:@]+))?@)?([\ w\-\.]*mbed\.(co\.uk|org|com))(\:\d+)?[:/](.+? )/?$'
106
106
# mbed sdk builds url are treated specially
107
107
regex_build_url = r'^(https?://([\w\-\.]*mbed\.(co\.uk|org|com))/(users|teams)/([\w\-]{1,32})/(repos|code)/([\w\-]+))/builds/?([\w\-]{6,40}|tip)?/?$'
108
108
@@ -1090,6 +1090,11 @@ def revtype(self, rev=None, ret_type=True, ret_rev=True, fmt=3):
1090
1090
def isurl (cls , url ):
1091
1091
return re .match (regex_url_ref , url .strip ().replace ('\\ ' , '/' ))
1092
1092
1093
+ @classmethod
1094
+ def isinsecure (cls , url ):
1095
+ up = urlparse (url , 'https' )
1096
+ return not up or not up .scheme or up .scheme not in ['http' , 'https' , 'ssh' , 'git' ] or (up .port and int (up .port ) not in [22 , 80 , 443 ])
1097
+
1093
1098
@property
1094
1099
def lib (self ):
1095
1100
return self .path + '.' + ('bld' if self .is_build else 'lib' )
@@ -1709,9 +1714,9 @@ def formaturl(url, format="default"):
1709
1714
m = re .match (regex_mbed_url , url )
1710
1715
if m :
1711
1716
if format == "http" : # mbed urls doesn't convert to ssh - only http and https
1712
- url = 'http://%s/%s/ %s/%s/%s ' % (m .group (2 ), m . group ( 4 ) , m .group (5 ), m .group (6 ) , m .group (7 ))
1717
+ url = 'http://%s%s %s/%s' % (m .group (2 ) or '' , m .group (6 ), m .group (8 ) or '' , m .group (9 ))
1713
1718
else :
1714
- url = 'https://%s/%s/ %s/%s/%s ' % (m .group (2 ), m . group ( 4 ) , m .group (5 ), m .group (6 ) , m .group (7 ))
1719
+ url = 'https://%s%s %s/%s' % (m .group (2 ) or '' , m .group (6 ), m .group (8 ) or '' , m .group (9 ))
1715
1720
else :
1716
1721
m = re .match (regex_repo_url , url )
1717
1722
if m and m .
group (
1 )
== '' :
# no protocol specified, probably ssh string like "[email protected] :ARMmbed/mbed-os.git"
@@ -1720,11 +1725,11 @@ def formaturl(url, format="default"):
1720
1725
1721
1726
if m :
1722
1727
if format == "ssh" :
1723
- url = 'ssh://%s%s%s/%s' % (m .group (2 ) or 'git@' , m .group (6 ), m .group (7 ), m .group (8 ))
1728
+ url = 'ssh://%s%s%s/%s' % (m .group (2 ) or 'git@' , m .group (6 ), m .group (7 ) or '' , m .group (8 ))
1724
1729
elif format == "http" :
1725
- url = 'http://%s%s%s/%s' % (m .group (2 ) if (m .group (2 ) and (m .group (5 ) or m .group (3 ) != 'git' )) else '' , m .group (6 ), m .group (7 ), m .group (8 ))
1730
+ url = 'http://%s%s%s/%s' % (m .group (2 ) if (m .group (2 ) and (m .group (5 ) or m .group (3 ) != 'git' )) else '' , m .group (6 ), m .group (7 ) or '' , m .group (8 ))
1726
1731
elif format == "https" :
1727
- url = 'https://%s%s%s/%s' % (m .group (2 ) if (m .group (2 ) and (m .group (5 ) or m .group (3 ) != 'git' )) else '' , m .group (6 ), m .group (7 ), m .group (8 ))
1732
+ url = 'https://%s%s%s/%s' % (m .group (2 ) if (m .group (2 ) and (m .group (5 ) or m .group (3 ) != 'git' )) else '' , m .group (6 ), m .group (7 ) or '' , m .group (8 ))
1728
1733
return url
1729
1734
1730
1735
@@ -1898,7 +1903,11 @@ def import_(url, path=None, ignore=False, depth=None, protocol=None, insecure=Fa
1898
1903
error ("Cannot import program in the specified location \" %s\" because it's already part of a program \" %s\" .\n "
1899
1904
"Please change your working directory to a different location or use \" mbed add\" to import the URL as a library." % (os .path .abspath (repo .path ), p .name ), 1 )
1900
1905
1901
- protocol = Program ().get_cfg ('PROTOCOL' , protocol )
1906
+ protocol = protocol or Program ().get_cfg ('PROTOCOL' )
1907
+ insecure = insecure or Program ().get_cfg ('INSECURE' )
1908
+
1909
+ if not insecure and Repo .isinsecure (url ):
1910
+ error ("Cannot import \" %s\" in \" %s\" due to arbitrary service schema/port in the repository URL.\n Repositories are usually hosted on service port 443 (https), 80 (http) and 22 (ssh)\n You can use \" --insecure\" switch enable the use arbitrary repository URLs." % (repo .url , repo .path ), 255 )
1902
1911
1903
1912
if os .path .isdir (repo .path ) and len (os .listdir (repo .path )) > 1 :
1904
1913
error ("Directory \" %s\" is not empty. Please ensure that the destination folder is empty." % repo .path , 1 )
@@ -1908,7 +1917,7 @@ def import_(url, path=None, ignore=False, depth=None, protocol=None, insecure=Fa
1908
1917
1909
1918
text = "Importing program" if top else "Adding library"
1910
1919
action ("%s \" %s\" from \" %s\" %s" % (text , relpath (cwd_root , repo .path ), formaturl (repo .url , protocol ), ' at ' + (repo .revtype (repo .rev ))))
1911
- if repo .clone (repo .url , repo .path , rev = repo .rev , depth = depth , protocol = protocol , insecure = insecure ):
1920
+ if repo .clone (repo .url , repo .path , rev = repo .rev , depth = depth , protocol = protocol ):
1912
1921
with cd (repo .path ):
1913
1922
Program (repo .path ).set_root ()
1914
1923
try :
0 commit comments