Beispiel #1
0
 def execute_function(self):
     if SysUtils.is_var_in_env('SCRIPT'):
         script_path = SysUtils.join_paths(
             SysUtils.get_env_var("TMP_INPUT_DIR"), self._SCRIPT_FILE_NAME)
         script_content = StrUtils.base64_to_str(
             SysUtils.get_env_var('SCRIPT'))
         FileUtils.create_file_with_content(script_path, script_content)
         get_logger().info("Script file created in '%s'", script_path)
         FileUtils.set_file_execution_rights(script_path)
         get_logger().info("Executing user defined script: '%s'",
                           script_path)
         try:
             pyinstaller_library_path = SysUtils.get_env_var(
                 'LD_LIBRARY_PATH')
             orig_library_path = SysUtils.get_env_var(
                 'LD_LIBRARY_PATH_ORIG')
             if orig_library_path:
                 SysUtils.set_env_var('LD_LIBRARY_PATH', orig_library_path)
             self.output = subprocess.check_output(
                 ['/bin/sh', script_path],
                 stderr=subprocess.STDOUT).decode("latin-1")
             SysUtils.set_env_var('LD_LIBRARY_PATH',
                                  pyinstaller_library_path)
             get_logger().debug("CONTAINER OUTPUT:\n %s", self.output)
         except subprocess.CalledProcessError as cpe:
             # Exit with user script return code if an
             # error occurs (Kubernetes handles the error)
             get_logger().error(cpe.output.decode('latin-1'))
             sys.exit(cpe.returncode)
     else:
         get_logger().error('No user script found!')
 def _get_script_path(self):
     script_path = None
     if SysUtils.is_var_in_env('SCRIPT'):
         script_path = SysUtils.join_paths(
             SysUtils.get_env_var("TMP_INPUT_DIR"), self._SCRIPT_FILE_NAME)
         script_content = StrUtils.base64_to_str(
             SysUtils.get_env_var('SCRIPT'))
         FileUtils.create_file_with_content(script_path, script_content)
         get_logger().info("Script file created in '%s'", script_path)
     elif FileUtils.is_file(self._OSCAR_SCRIPT_PATH):
         script_path = self._OSCAR_SCRIPT_PATH
     return script_path
Beispiel #3
0
 def _parse_exec_script_and_commands(self):
     # Check for script in function event
     if 'script' in self.raw_event:
         self.script_path = f"{self.input_folder}/script.sh"
         script_content = StrUtils.base64_to_str(self.raw_event['script'])
         FileUtils.create_file_with_content(self.script_path, script_content)
     # Container invoked with arguments
     elif 'cmd_args' in self.raw_event:
         # Add args
         self.cmd_args = json.loads(self.raw_event['cmd_args'])
     # Script to be executed every time (if defined)
     elif ConfigUtils.read_cfg_var('init_script') is not '':
         # Add init script
         self.init_script_path = f"{self.input_folder}/init_script.sh"
         FileUtils.cp_file(ConfigUtils.read_cfg_var('init_script'), self.init_script_path)
Beispiel #4
0
 def _parse_exec_script_and_commands(self):
     # Check for script in function event
     if 'script' in self.raw_event:
         self.script_path = f"{self.input_folder}/script.sh"
         script_content = StrUtils.base64_to_str(self.raw_event['script'])
         FileUtils.create_file_with_content(self.script_path,
                                            script_content)
     # Container invoked with arguments
     elif 'cmd_args' in self.raw_event:
         # Add args
         self.cmd_args = json.loads(self.raw_event['cmd_args'])
     # Script to be executed every time (if defined)
     elif SysUtils.is_var_in_env('INIT_SCRIPT_PATH'):
         # Add init script
         self.init_script_path = f"{self.input_folder}/init_script.sh"
         FileUtils.cp_file(SysUtils.get_env_var("INIT_SCRIPT_PATH"),
                           self.init_script_path)
Beispiel #5
0
 def test_base64_to_str(self):
     self.assertEqual(StrUtils.base64_to_str("dGVzdGluZwplbmNvZGUu"),
                      "testing\nencode.")