Exemple #1
0
 def before_swagger_generate(self):
     for o in self.options:
         if 'service' in o:
             self.service = o['service']
         if 'path' in o:
             self.path = o['path']
         if 'all' in o:
             self.all = o['all']
         if 'fields' in o:
             self.fields = o['fields']
         if 'refactor' in o:
             self.refactor = o['refactor']
         if 'headers' in o:
             self.headers = o['headers']
         if 'errors' in o:
             self.errors = o['errors']
     if not self.service:
         raise Exception("no service found")
     urls = self.halo.settings['mservices'][self.service]['record']['path']
     self.data = Util.analyze_swagger(urls)
     if "methods" in self.halo.settings['mservices'][
             self.service]['record']:
         self.methods = self.halo.settings['mservices'][
             self.service]['record']['methods']
         if "exclude" in self.halo.settings['mservices'][
                 self.service]['record']:
             self.exclude = self.halo.settings['mservices'][
                 self.service]['record']['exclude']
         else:
             self.exclude = False
     else:
         self.methods = []
Exemple #2
0
 def test_util_2(self):
     print('test_util_1 valid -a')
     # start(False)
     from halocli.util import Util
     result = Util.check_package_in_env("halo-test-plugin")
     print("r=" + str(result))
     expected_output = 1
     assert len(result) == expected_output
Exemple #3
0
 def get_plugin_class(self, package_name):
     class_list = Util.check_package_in_env(package_name)
     if len(class_list) > 1:
         raise HaloPluginClassException(
             "too many plugin entry point classes package: " + package_name)
     if len(class_list) == 1:
         return class_list[0]
     raise HaloPluginClassException(
         "plugin entry point class not found for package: " + package_name)
Exemple #4
0
 def valid_resources(self):
     if hasattr(self, 'options'):
         for o in self.options:
             if 'attribute' in o:
                 service = o['attribute']
     else:
         return
     ret = Util.valid(self.halo.settings, service)
     if ret == 0:
         self.halo.cli.log("finished valid seccessfuly")
     return ret
Exemple #5
0
 def test_util_1(self):
     print('test_util_1 valid -a')
     #start(False)
     from halocli.util import Util
     expected_output_log = "plugin package: pandas not installed"
     try:
         result = Util.check_package_in_env("pandas")
         print("r=" + str(result))
     except Exception as e:
         print("e=" + str(e))
         assert str(e) == expected_output_log
Exemple #6
0
 def valid_resources(self):
     service = None
     if hasattr(self, 'options'):
         if self.options:
             for o in self.options:
                 if 'service' in o:
                     service = o['service']
     if not service:
         raise Exception("no service found")
     ret = Util.valid(self.halo.settings, service)
     if ret == 0:
         self.halo.cli.log("finished valid seccessfuly")
     return ret
 def file_write(self):
     try:
         path = self.path
         if path:
             file_path = os.path.join(path, str(uuid.uuid4()) + ".json")
         else:
             dir_tmp = tempfile.TemporaryDirectory()
             file_path = os.path.join(dir_tmp.name, str(uuid.uuid4()) + ".json")
         logger.debug(file_path)
         f = open(file_path, "a")
         f.write("")
         f.close()
         Util.dump_file(file_path, self.data)
         logging.debug("Swagger file generated:" + file_path)
         """
         with open(file_path, 'r') as fi:
             f = fi.read()
             print(str(f))
             return f
         """
     except Exception as e:
         raise HaloPluginException(str(e))
Exemple #8
0
 def setup_config(self):
     if hasattr(self, 'options'):
         for o in self.options:
             if 'service_name' in o:
                 service_name = o['service_name']
             if 'service_name' in o:
                 swagger_path = o['swagger_path']
     else:
         return
     ret = Util.config_settings(self.halo.settings, service_name,
                                swagger_path)
     if ret == 0:
         self.halo.cli.log("finished config seccessfuly")
     return ret
 def before_method_generate(self):
     self.id = None
     for o in self.options:
         if 'service' in o:
             self.service = o['service']
         if 'path' in o:
             self.path = o['path']
         if 'id' in o:
             self.id = o['id']
     if self.service not in self.halo.settings['mservices']:
         raise HaloPluginException("service not found in swagger : " +
                                   self.service)
     urls = self.halo.settings['mservices'][self.service]['urls']
     self.data = Util.analyze_swagger(urls)
Exemple #10
0
 def get_plugins(self):
     halo_settings_path = None
     if self.options and "-s" in self.options:
         get = False
         for item in self.options:
             if item.strip() == "-s":
                 get = True
                 continue
             if get:
                 halo_settings_path = item
                 break
         if halo_settings_path:
             #@todo check if its only file name and add current dir
             if not os.path.dirname(halo_settings_path):
                 halo_settings_path = os.path.join(os.getcwd(),
                                                   halo_settings_path)
     else:
         halo_settings_path = os.path.join(os.getcwd(),
                                           'halo_settings.json')
     halo_settings = None
     try:
         halo_settings = Util.load_settings_file(halo_settings_path)
     except ConfigException as e:
         log("Error in HALO CLI settings file: " + str(e), "red")
         sys.exit(1)
     try:
         self.do_settings(halo_settings)
     except HaloCommandException as e:
         log("Error in HALO CLI Command : " + str(e), "red")
         sys.exit(1)
     except HaloPluginMngrException as e:
         log("Error in HALO CLI Plugin: " + str(e), "red")
         sys.exit(1)
     #if settings_error:
     #    log("Error in HALO CLI settings : " + str(settings_error), "red")
     return self.plugin_mngr.get_plugin_instances()
 def after_method_generate(self):
     data = self.data
     Util.validate_swagger(data)