def web_root(self):
     if os.getenv('AWS_REGION') is not None:  # if we are in AWS
         return Files.path_combine('.', './web_root')
     if 'test/browser' in Files.current_folder(
     ):  # if we are in an unit test
         return Files.path_combine('.', '../../../../src/web_root')
     parent_folder = Files.folder_name(__file__)
     if 'pbx-gs-python-utils/src/browser' in parent_folder:
         return Files.path_combine(parent_folder,
                                   '../../../../src/web_root')
     return None
Esempio n. 2
0
 def __init__(self, web_root=None):
     self.src_tmp     = '/tmp/temp_web_server'
     if web_root      : self.web_root = web_root
     else             : self.web_root = self.src_tmp + '/html'
     self.html_file   = Files.path_combine(self.web_root, 'index.html')
     self.port        = Misc.random_number(10000,60000)
     self.server_proc = None
Esempio n. 3
0
 def __init__(self, headless=True):
     self.web_page = '/vis-js/simple.html'
     self.web_root = Files.path_combine(Files.parent_folder(__file__),
                                        '../web_root')
     self.api_browser = API_Browser(
         headless=headless, auto_close=headless).sync__setup_browser()
     self.render_page = Render_Page(api_browser=self.api_browser,
                                    web_root=self.web_root)
Esempio n. 4
0
 def __init__(self, tmp_img=None, clip=None, headless=False):
     self.headless = headless
     self.path_views = Files.path_combine(Files.parent_folder(__file__),
                                          '../../src/web_root')
     self.render_page = Render_Page(headless=self.headless,
                                    auto_close=self.headless,
                                    web_root=self.path_views)
     self.tmp_img = tmp_img
     self.clip = clip
Esempio n. 5
0
 def __init__(self, web_page, headless=True):
     self.web_page = web_page
     self.title = 'browser view'
     self.web_root = Files.path_combine(Files.parent_folder(__file__),
                                        '../web_root')
     self.api_browser = API_Browser(
         headless=headless, auto_close=headless).sync__setup_browser()
     self.web_server = Web_Server(self.web_root)
     self.render_page = Render_Page(api_browser=self.api_browser,
                                    web_server=self.web_server)
 def __init__(self):
     self.web_page = '/google_charts/simple.html'
     self.web_root = Files.path_combine(Files.parent_folder(__file__),
                                        '../web_root')
     self.api_browser = API_Browser().sync__setup_browser()
     self.render_page = Render_Page(api_browser=self.api_browser,
                                    web_root=self.web_root)
     self.table_width = '100%'
     self.columns_defs = None
     self.table_title = None
 def __init__(self):
     self.web_page = '/gs/risk/risks-dashboard.html'
     self.web_root = Files.path_combine(Files.parent_folder(__file__),
                                        '../web_root')
     self.headless = False
     self.api_browser = API_Browser(self.headless,
                                    self.headless).sync__setup_browser()
     self.render_page = Render_Page(api_browser=self.api_browser,
                                    web_root=self.web_root)
     self.graph_name = None
     self.jira_key = None
Esempio n. 8
0
def upload_dependency(target):
    s3 = S3()
    s3_bucket = 'gs-lambda-tests'
    s3_folder = 'dinis/lambdas-dependencies/'
    s3_file = 'dinis/lambdas-dependencies/{0}.zip'.format(target)
    path_libs = Files.path_combine('../../../_lambda_dependencies/', target)
    if Files.not_exists(path_libs):
        raise Exception(
            "In Lambda upload_dependency, could not find dependency for: {0}".
            format(target))
    s3.folder_upload(path_libs, s3_bucket, s3_folder)
    return s3.file_exists(s3_bucket, s3_file)
Esempio n. 9
0
    def update_with_src(
        self,
        path_to_src=None
    ):  # use this when wanting to add a local folder to the lambda source code

        if path_to_src is None:
            path_to_src = Files.path_combine(__file__, '../../../../../../src')
        src_tmp = '/tmp/src_{0}'.format(self.name)
        copy_tree(self.source, src_tmp)
        copy_tree(path_to_src, src_tmp)
        self.source = src_tmp
        return self.update()
Esempio n. 10
0
def load_dependency(target):
    s3 = S3()
    s3_bucket = 'gs-lambda-tests'
    s3_key = 'dinis/lambdas-dependencies/{0}.zip'.format(target)
    tmp_dir = Files.path_combine('/tmp/lambdas-dependencies', target)

    if s3.file_exists(s3_bucket, s3_key) is False:
        raise Exception(
            "In Lambda load_dependency, could not find dependency for: {0}".
            format(target))

    if Files.not_exists(
            tmp_dir
    ):  # if the tmp folder doesn't exist it means that we are loading this for the first time (on a new Lambda execution environment)
        zip_file = s3.file_download(
            s3_bucket, s3_key, False)  # download zip file with dependencies
        shutil.unpack_archive(zip_file, extract_dir=tmp_dir)  # unpack them
        sys.path.append(
            tmp_dir
        )  # add tmp_dir to the path that python uses to check for dependencies
    return Files.not_exists(tmp_dir)
Esempio n. 11
0
 def path_to_file(self, file_path):                                  # has path traversal vulnerability
     if file_path and len(file_path) >0 and file_path[0] == '/':
         file_path = file_path[1:]
     return Files.path_combine(self.web_root, file_path)
Esempio n. 12
0
 def setUp(self):
     self.src_tmp = '/tmp/src_create_map'
     self.folder_src_lambdas = Files.path_combine(__file__,
                                                  '../../../src/lambdas')
     self.folder_src_hugo = Files.path_combine(__file__,
                                               '../../../src/hugo')
Esempio n. 13
0
 def __init__(self, contents='...', extension='tmp'):
     self.tmp_file = Misc.random_filename(extension)
     self.tmp_folder = tempfile.tempdir
     self.file_path = Files.path_combine(self.tmp_folder, self.tmp_file)
     self.contents = contents