def main(self, args=None): args = args or sys.argv[1:] services = self._get_services() parser = self._create_parser(services) parsed_args, remaining = parser.parse_known_args(args) logger.debug( f"Parsed Arguments: {parsed_args}, Remaining: {remaining}") if parsed_args.service == 'help' or parsed_args.service is None: AlertLogicCLI.show_help( ALCliMainHelpFormatter(Session.list_services())) return 128 if parsed_args.operation == 'help': AlertLogicCLI.show_help( ALCliServiceHelpFormatter( parsed_args.service, Session.get_service_api(parsed_args.service))) return 128 if hasattr(parsed_args, 'help') and \ hasattr(parsed_args, 'service') and \ hasattr(parsed_args, 'operation') and \ parsed_args.help == 'help': spec = Session.get_service_api(parsed_args.service)['operations'] AlertLogicCLI.show_help( ALCliOperationHelpFormatter(spec.get(parsed_args.operation, {}))) return 0 try: return services[parsed_args.service](remaining, parsed_args) except almdrlib.exceptions.AlmdrlibValueError as e: sys.stderr.write(f"{e}\n") return 255 except almdrlib.session.AuthenticationException as e: sys.stderr.write("Access Denied\n") return 255 except Exception as e: template = "An exception of type {0} occurred. Arguments:\n{1!r}" message = template.format(type(e).__name__, e.args) logger.exception(message) return 255
def _get_services(self): if self._services is None: self._services = OrderedDict() services_list = Session.list_services() self._services = { service_name: ServiceOperation(name=service_name) for service_name in services_list } return self._services
def make_documentation(dir, session=None): """Creates documentation for Alert Logic SDK Enumerates all services and generates rst files for sphinx documentation :param dir: The directory to write the files to. Each service's documentation is loacated at dir/services/[service name].rst file :param session: The IWS Services session """ doc_path = os.path.join(dir, 'site', 'services') if not os.path.exists(doc_path): os.makedirs(doc_path) for name in Session.list_services(): doc = ServiceDocGenerator( service_name=name, spec=Session.get_service_api(name)).make_documentation() service_doc_path = os.path.join(doc_path, name + '.rst') with open(service_doc_path, 'wb') as f: f.write(doc)
def test_000_getting_schemas(self): """Test listing services.""" services = Session.list_services() self.assertTrue(self._service_name in services) self.assertTrue(len(Session.get_service_api("testapi")))
def _get_default_session(): global IWS_DEFAULT_SESSION if not IWS_DEFAULT_SESSION: IWS_DEFAULT_SESSION = Session() return IWS_DEFAULT_SESSION
def get_service_api(self, service_name): return Session.get_service_api(service_name=service_name)
def test_000_getting_schemas(self): """Test listing services.""" services = Session.list_services() self.assertTrue(self._service_name in services) self.assertTrue(len(Session.get_service_api("testapi"))) print(f"SCHEMA: {json.dumps(Session.get_service_api('testapi'))}")
def test_003_default_objects_creation(self): """Checks initialisation at least happens""" self.assertIsInstance(Session(), Session) self.assertIsInstance(Config(), Config) self.assertIsInstance(Client(self._service_name), Client)