|
|
@ -2,6 +2,7 @@ import os |
|
|
|
import uuid |
|
|
|
import uuid |
|
|
|
from flask import current_app |
|
|
|
from flask import current_app |
|
|
|
from web_utils.task import ProcessTask |
|
|
|
from web_utils.task import ProcessTask |
|
|
|
|
|
|
|
from web_utils.business_exception import BusinessException |
|
|
|
import shutil |
|
|
|
import shutil |
|
|
|
from unicodedata import normalize |
|
|
|
from unicodedata import normalize |
|
|
|
import string |
|
|
|
import string |
|
|
@ -24,7 +25,7 @@ def sanitize_name(initial_name): |
|
|
|
valid_chars = "-_.(){0}{1}".format(string.ascii_letters, string.digits) |
|
|
|
valid_chars = "-_.(){0}{1}".format(string.ascii_letters, string.digits) |
|
|
|
name = "".join(ch for ch in name if ch in valid_chars) |
|
|
|
name = "".join(ch for ch in name if ch in valid_chars) |
|
|
|
if len(name) == 0 or '..' in name: |
|
|
|
if len(name) == 0 or '..' in name: |
|
|
|
raise Exception("Invalid name: " + initial_name) |
|
|
|
raise BusinessException("Invalid name: " + initial_name) |
|
|
|
return name |
|
|
|
return name |
|
|
|
|
|
|
|
|
|
|
|
class Document: |
|
|
|
class Document: |
|
|
@ -38,7 +39,7 @@ class Document: |
|
|
|
self.valid = False |
|
|
|
self.valid = False |
|
|
|
return |
|
|
|
return |
|
|
|
else: |
|
|
|
else: |
|
|
|
raise Exception("This document does not exist: "+doc_name+"@"+branch) |
|
|
|
raise BusinessException("This document does not exist: "+doc_name+"@"+branch) |
|
|
|
|
|
|
|
|
|
|
|
self.doc_path = doc_path |
|
|
|
self.doc_path = doc_path |
|
|
|
self.valid = True |
|
|
|
self.valid = True |
|
|
@ -73,7 +74,7 @@ class Document: |
|
|
|
def make_doc_path(doc_name, branch): |
|
|
|
def make_doc_path(doc_name, branch): |
|
|
|
doc_path = os.path.realpath(get_document_root()+'/'+sanitize_name(doc_name)+'/'+sanitize_name(branch)) |
|
|
|
doc_path = os.path.realpath(get_document_root()+'/'+sanitize_name(doc_name)+'/'+sanitize_name(branch)) |
|
|
|
if not doc_path.startswith(get_document_root()): |
|
|
|
if not doc_path.startswith(get_document_root()): |
|
|
|
raise Exception("Invalid document path for "+doc_name+"@"+branch) |
|
|
|
raise BusinessException("Invalid document path for "+doc_name+"@"+branch) |
|
|
|
return doc_path |
|
|
|
return doc_path |
|
|
|
|
|
|
|
|
|
|
|
@staticmethod |
|
|
|
@staticmethod |
|
|
@ -81,14 +82,14 @@ class Document: |
|
|
|
# check the document does not already exist |
|
|
|
# check the document does not already exist |
|
|
|
doc_path = Document.make_doc_path(doc_name, branch) |
|
|
|
doc_path = Document.make_doc_path(doc_name, branch) |
|
|
|
if os.path.isdir(doc_path): |
|
|
|
if os.path.isdir(doc_path): |
|
|
|
raise Exception("This document already exists: "+doc_name+"@"+branch) |
|
|
|
raise BusinessException("This document already exists: "+doc_name+"@"+branch) |
|
|
|
|
|
|
|
|
|
|
|
if source_dir != sanitize_name(source_dir): |
|
|
|
if source_dir != sanitize_name(source_dir): |
|
|
|
raise Exception("Invalid source directory name: " + source_dir) |
|
|
|
raise BusinessException("Invalid source directory name: " + source_dir) |
|
|
|
|
|
|
|
|
|
|
|
# we have potentially serious security issues related to cloning anything. For example cloning from SSH may use a pre-configured server identity, etc. |
|
|
|
# we have potentially serious security issues related to cloning anything. For example cloning from SSH may use a pre-configured server identity, etc. |
|
|
|
if not repo.startswith("https://"): |
|
|
|
if not repo.startswith("https://"): |
|
|
|
raise Exception("Only HTTPS repositories are allowed in current implementation") |
|
|
|
raise BusinessException("Only HTTPS repositories are allowed in current implementation") |
|
|
|
|
|
|
|
|
|
|
|
# Generate an API key |
|
|
|
# Generate an API key |
|
|
|
apikey = str(uuid.uuid4()) |
|
|
|
apikey = str(uuid.uuid4()) |
|
|
|