Allow file:// URLs when building modules locally

This commit is contained in:
Jan Kaluza
2016-11-30 10:33:20 +01:00
parent 27484f2c32
commit f7350a395f
4 changed files with 11 additions and 9 deletions

View File

@@ -201,7 +201,7 @@ def build_module_locally(url):
_insert_fake_baseruntime()
username = getpass.getuser()
submit_module_build(username, url)
submit_module_build(username, url, allow_local_url=True)
msgs = []
msgs.append(RidaModule("local module build", 2, 1))

View File

@@ -47,10 +47,10 @@ class SCM(object):
# Assuming git for HTTP schemas
types = {
"git": ("git://", "git+http://", "git+https://",
"git+rsync://", "http://", "https://")
"git+rsync://", "http://", "https://", "file://")
}
def __init__(self, url, allowed_scm=None):
def __init__(self, url, allowed_scm=None, allow_local = False):
"""Initialize the SCM object using the specified scmurl.
If url is not in the list of allowed_scm, an error will be raised.
@@ -61,6 +61,7 @@ class SCM(object):
git+rsync://
http://
https://
file://
:param str url: The unmodified scmurl
:param list allowed_scm: The list of allowed SCMs, optional
@@ -69,7 +70,8 @@ class SCM(object):
if allowed_scm:
for allowed in allowed_scm:
if url.startswith(allowed):
if (url.startswith(allowed)
or (allow_local and url.startswith("file://"))):
break
else:
raise Unauthorized(

View File

@@ -208,7 +208,7 @@ def filter_module_builds(flask_request):
return query.paginate(page, per_page, False)
def _fetch_mmd(url):
def _fetch_mmd(url, allow_local_url = False):
# Import it here, because SCM uses utils methods
# and fails to import them because of dep-chain.
import module_build_service.scm
@@ -219,7 +219,7 @@ def _fetch_mmd(url):
try:
log.debug('Verifying modulemd')
td = tempfile.mkdtemp()
scm = module_build_service.scm.SCM(url, conf.scmurls)
scm = module_build_service.scm.SCM(url, conf.scmurls, allow_local_url)
cod = scm.checkout(td)
cofn = os.path.join(cod, (scm.name + ".yaml"))
@@ -343,12 +343,12 @@ def record_component_builds(mmd, module, initial_batch = 1):
return batch
def submit_module_build(username, url):
def submit_module_build(username, url, allow_local_url = False):
# Import it here, because SCM uses utils methods
# and fails to import them because of dep-chain.
import module_build_service.scm
mmd, scm, yaml = _fetch_mmd(url)
mmd, scm, yaml = _fetch_mmd(url, allow_local_url)
# If undefined, set the name field to VCS repo name.
if not mmd.name and scm:

View File

@@ -123,7 +123,7 @@ class ModuleBuildAPI(MethodView):
log.error("The submitted scmurl %r is not valid" % url)
raise Unauthorized("The submitted scmurl %s is not valid" % url)
module = submit_module_build(username, url)
module = submit_module_build(username, url, allow_local_url=False)
return jsonify(module.json()), 201