def test_get_custom_fields_details(): import_definition = package_helpers.get_import_definition_from_customize_py( mock_paths.MOCK_CUSTOMIZE_PY) import_def_data = sdk_helpers.get_from_export( import_definition, fields=["mock_field_number", "mock_field_text_area"]) field_details = CmdDocgen._get_custom_fields_details( import_def_data.get("fields")) field_one = next(x for x in field_details if x["api_name"] == "mock_field_number") field_two = next(x for x in field_details if x["api_name"] == "mock_field_text_area") mock_field_one = { 'api_name': u'mock_field_number', 'label': u'Mock: ล ฦ ว ศ ษ ส ห ฬ อ field number', 'type': u'number', 'prefix': u'properties', 'placeholder': u'-', 'tooltip': u'a mock tooltip ล ฦ ว ศ ษ ส ห ฬ อ' } mock_field_two = { 'api_name': u'mock_field_text_area', 'label': u'Mock: Field Text Area ล ฦ ว ศ ษ ส ห ฬ อ', 'type': u'textarea', 'prefix': u'properties', 'placeholder': u'-', 'tooltip': u'a tooltip ล ฦ ว ศ ษ ส ห ฬ อ' } assert field_one == mock_field_one assert field_two == mock_field_two
def test_get_datatable_details_defaults(): mock_datables = [{ "display_name": "mock_name", "name": "mock_name", "api_name": "mock_name", "fields": { "col_one": {} } }] the_datatable = CmdDocgen._get_datatable_details(mock_datables)[0] mock_datatable = { 'name': 'mock_name', 'anchor': 'mock_name', 'api_name': None, 'simple_name': 'mock-name', 'columns': [{ 'name': None, 'api_name': None, 'type': None, 'tooltip': '-' }] } assert the_datatable == mock_datatable
def test_get_datatable_details(): import_definition = package_helpers.get_import_definition_from_customize_py( mock_paths.MOCK_CUSTOMIZE_PY) import_def_data = sdk_helpers.get_from_export( import_definition, datatables=["mock_data_table"]) datatable_details = CmdDocgen._get_datatable_details( import_def_data.get("datatables")) the_datatable = datatable_details[0] mock_datatable = { 'name': u'Mock: Data Table ล ฦ ว ศ ษ ส ห ฬ อ', 'anchor': u'mock-data-table--ล-ฦ-ว-ศ-ษ-ส-ห-ฬ-อ', 'api_name': u'mock_data_table', 'simple_name': u'mock-data-table----------', 'columns': [{ 'name': u'mock col one', 'api_name': u'mock_col_one', 'type': u'text', 'tooltip': u'a tooltip ล ฦ ว ศ ษ ส ห ฬ อ' }, { 'name': u'mock ล ฦ ว ศ ษ ส ห ฬ อ col two', 'api_name': u'mok_col_two', 'type': u'number', 'tooltip': u'tooltip ล ฦ ว ศ ษ ส ห ฬ อ' }] } assert the_datatable == mock_datatable
def test_get_rule_details(): import_definition = package_helpers.get_import_definition_from_customize_py(mock_paths.MOCK_CUSTOMIZE_PY) import_def_data = sdk_helpers.get_from_export(import_definition, rules=["Mock: Auto Rule"]) rule_details = CmdDocgen._get_rule_details(import_def_data.get("rules")) the_rule = rule_details[0] mock_rule = {'name': u'Mock: Auto Rule', 'object_type': u'incident', 'workflow_triggered': u'mock_workflow_one', 'simple_name': u'mock-auto-rule'} assert the_rule == mock_rule
def test_get_fn_input_details_defaults(): mock_function = { "inputs": [ {"api_name": "", "placeholder": "", "tooltip": ""} ] } fn_input = CmdDocgen._get_fn_input_details(mock_function)[0] mock_input = {'api_name': None, 'name': None, 'type': None, 'required': u'No', 'placeholder': u'-', 'tooltip': u'-'} assert fn_input == mock_input
def test_get_fn_input_details(): import_definition = package_helpers.get_import_definition_from_customize_py(mock_paths.MOCK_CUSTOMIZE_PY) import_def_data = sdk_helpers.get_from_export(import_definition, functions=["mock_function_two"]) fn = import_def_data.get("functions")[0] fn_inputs = CmdDocgen._get_fn_input_details(fn) fn_input = next(x for x in fn_inputs if x["api_name"] == "mock_input_number") mock_input = {'api_name': u'mock_input_number', 'name': u'mock_input_number', 'type': 'number', 'required': 'Yes', 'placeholder': u'-', 'tooltip': u'a mock tooltip ล ฦ ว ศ ษ ส ห ฬ อ'} assert fn_input == mock_input
def test_app_log_results_are_used(fx_copy_fn_main_mock_integration, fx_get_sub_parser, fx_cmd_line_args_docgen): mock_integration_name = fx_copy_fn_main_mock_integration[0] path_fn_main_mock_integration = fx_copy_fn_main_mock_integration[1] # Replace cmd line arg "fn_main_mock_integration" with path to temp dir location sys.argv[sys.argv.index( mock_integration_name)] = path_fn_main_mock_integration cmd_docgen = CmdDocgen(fx_get_sub_parser) args = cmd_docgen.parser.parse_known_args()[0] cmd_docgen.execute_command(args) readme_file = sdk_helpers.read_file( os.path.join(path_fn_main_mock_integration, package_helpers.BASE_NAME_README)) assert ' "custom_results": "these are my custom results!"' in "\n".join( readme_file)
def test_cmd_docgen_setup(fx_get_sub_parser, fx_cmd_line_args_docgen): cmd_docgen = CmdDocgen(fx_get_sub_parser) assert isinstance(cmd_docgen, base_cmd.BaseCmd) assert cmd_docgen.CMD_NAME == "docgen" assert cmd_docgen.CMD_HELP == "Generate documentation for an app" assert cmd_docgen.CMD_USAGE == """ $ resilient-sdk docgen -p <path_to_package>""" assert cmd_docgen.CMD_DESCRIPTION == "Generate documentation for an app" args = cmd_docgen.parser.parse_known_args()[0] assert args.p == "fn_main_mock_integration"
def test_get_script_details(): import_definition = package_helpers.get_import_definition_from_customize_py(mock_paths.MOCK_CUSTOMIZE_PY) import_def_data = sdk_helpers.get_from_export(import_definition, scripts=["Mock Script One"]) scripts = import_def_data.get("scripts") script_details = CmdDocgen._get_script_details(scripts) the_script = script_details[0] assert the_script.get("name") == "Mock Script One" assert the_script.get("simple_name") == "mock-script-one" assert the_script.get("anchor") == "mock-script-one" assert the_script.get("description") == "a sample Artifact script" assert the_script.get("object_type") == "artifact" assert the_script.get("script_text") == """log.info("Print this message")"""
def test_get_custom_fields_details_defaults(): mock_fields = [ { "api_name": "mock_field", "placeholder": "", "tooltip": "" } ] field_details = CmdDocgen._get_custom_fields_details(mock_fields)[0] mock_field = {'placeholder': '-', 'tooltip': '-', 'prefix': None, 'api_name': None, 'label': None, 'type': None} assert field_details == mock_field
def test_get_custom_artifact_details(): import_definition = package_helpers.get_import_definition_from_customize_py(mock_paths.MOCK_CUSTOMIZE_PY) import_def_data = sdk_helpers.get_from_export(import_definition, artifact_types=["mock_artifact_2"]) artifact_details = CmdDocgen._get_custom_artifact_details(import_def_data.get("artifact_types")) the_artifact = artifact_details[0] mock_artifact = { 'api_name': u'mock_artifact_2', 'display_name': u'Mock Artifact 2 ㌎ ㌏ ㌐ ㌑ ㌒ ㌓ ㌔ ㌕ ㌖', 'description': u'㌎ ㌏ ㌐ ㌑ ㌒ ㌓ ㌔ ㌕ ㌖ ㌎ ㌏ ㌐ ㌑ ㌒ ㌓ ㌔ ㌕ ㌖asdf ㌎ ㌏ ㌐ ㌑ ㌒ ㌓ ㌔ ㌕ ㌖' } assert the_artifact == mock_artifact
def test_get_function_details(): import_definition = package_helpers.get_import_definition_from_customize_py(mock_paths.MOCK_CUSTOMIZE_PY) import_def_data = sdk_helpers.get_from_export(import_definition, functions=["mock_function_two"], workflows=["mock_workflow_two"]) functions = import_def_data.get("functions") workflows = import_def_data.get("workflows") function_details = CmdDocgen._get_function_details(functions, workflows) the_function = function_details[0] assert the_function.get("name") == u"mock function ล ฦ ว ศ ษ ส ห ฬ อ two" assert the_function.get("pre_processing_script") in u"""# mock pre script of function ล ฦ ว ศ ษ ส ห ฬ อ ล ฦ ว ศ ษ ส ห ฬ อ ล ฦ ว ศ ษ ส ห ฬ อ two:\n\ninputs.mock_input_boolean = False\ninputs.mock_input_number = 1001\ninputs.mock_input_text = u" ล ฦ ว ศ ษ ส ห ฬ อ ล ฦ ว ศ ษ ส ห ฬ อ ramdom text" """ assert the_function.get("post_processing_script") is None
html_domain_indices = False # Add any paths that contain custom static files (such as style sheets) here, # relative to this directory. They are copied after the builtin static files, # so a file named "default.css" will overwrite the builtin "default.css". html_static_path = ['_static'] # autodoc configs add_module_names = False # resilient-sdk parser sdk_parser = sdk_app.get_main_app_parser() sdk_sub_parser = sdk_app.get_main_app_sub_parser(sdk_parser) cmd_codegen = CmdCodegen(sdk_sub_parser) cmd_docgen = CmdDocgen(sdk_sub_parser) cmd_ext_package = CmdExtPackage(sdk_sub_parser) cmd_clone = CmdClone(sdk_sub_parser) cmd_extract = CmdExtract(sdk_sub_parser) cmd_validate = CmdValidate(sdk_sub_parser) # parse the setup.py files the_globals = {"__file__": "", "long_description": ""} resilient_setup_attributes = parse_setup_py( os.path.abspath("../resilient/setup.py"), SUPPORTED_SETUP_PY_ATTRIBUTE_NAMES, the_globals=the_globals) circuits_setup_attributes = parse_setup_py( os.path.abspath("../resilient-circuits/setup.py"), SUPPORTED_SETUP_PY_ATTRIBUTE_NAMES, the_globals=the_globals)
def main(): """ Main entry point for resilient-sdk """ # See if RES_SDK_DEV environment var is set sdk_dev = sdk_helpers.str_to_bool(os.getenv("RES_SDK_DEV")) # Get main parser object parser = get_main_app_parser() # Get sub_parser object, its dest is cmd sub_parser = get_main_app_sub_parser(parser) # Add any subcommands to main app parser here cmd_codegen = CmdCodegen(sub_parser) cmd_clone = CmdClone(sub_parser) cmd_docgen = CmdDocgen(sub_parser) cmd_extract = CmdExtract(sub_parser) cmd_ext_package = CmdExtPackage(sub_parser) if sdk_dev: # Add 'dev' command if environment var set cmd_dev = CmdDev(sub_parser) try: # Parse the arguments args = parser.parse_args() if args.cmd is None: parser.print_help() sys.exit() except SDKException as err: # Get main_cmd (codegen, docgen etc.) main_cmd = sdk_helpers.get_main_cmd() LOG.error(err) LOG.info("\n-----------------\n") # Print specifc usage for that cmd for these errors if "too few arguments" in err.message or "no subcommand provided" in err.message: if main_cmd == cmd_codegen.CMD_NAME: cmd_codegen.parser.print_usage() elif main_cmd == cmd_clone.CMD_NAME: cmd_clone.parser.print_usage() elif main_cmd == cmd_docgen.CMD_NAME: cmd_docgen.parser.print_usage() elif main_cmd == cmd_extract.CMD_NAME: cmd_extract.parser.print_usage() elif main_cmd == cmd_ext_package.CMD_NAME: cmd_ext_package.parser.print_usage() elif sdk_dev and main_cmd == cmd_dev.CMD_NAME: cmd_dev.parser.print_usage() else: parser.print_help() # Exit sys.exit() # If -v was specified, set the log level to DEBUG if args.verbose: LOG.setLevel(logging.DEBUG) LOG.debug("Logging set to DEBUG mode") # Handle what subcommand was called if args.cmd == cmd_docgen.CMD_NAME: cmd_docgen.execute_command(args) elif args.cmd == cmd_codegen.CMD_NAME: cmd_codegen.execute_command(args) elif args.cmd == cmd_clone.CMD_NAME: cmd_clone.execute_command(args) elif args.cmd == cmd_extract.CMD_NAME: cmd_extract.execute_command(args) elif args.cmd == cmd_ext_package.CMD_NAME: cmd_ext_package.execute_command(args) elif sdk_dev and args.cmd == cmd_dev.CMD_NAME: cmd_dev.execute_command(args)
def main(): """ Main entry point for resilient-sdk """ # add color support for WINDOWS os.system("") # See if RES_SDK_DEV environment var is set sdk_dev = sdk_helpers.is_env_var_set(constants.ENV_VAR_DEV) # Get main parser object parser = get_main_app_parser() # Get sub_parser object, its dest is cmd sub_parser = get_main_app_sub_parser(parser) if sdk_dev: # Add 'dev' command if environment var set cmd_dev = CmdDev(sub_parser) LOG.info("{0}Running SDK in Developer Mode{0}".format(constants.LOG_DIVIDER)) # Add any subcommands to main app parser here cmd_validate = CmdValidate(sub_parser) cmd_codegen = CmdCodegen(sub_parser) cmd_clone = CmdClone(sub_parser) cmd_docgen = CmdDocgen(sub_parser) cmd_extract = CmdExtract(sub_parser) cmd_ext_package = CmdExtPackage(sub_parser, cmd_validate=cmd_validate) try: # Parse the arguments args = parser.parse_args() if args.cmd is None: parser.print_help() sys.exit() except SDKException as err: # Get main_cmd (codegen, docgen etc.) main_cmd = sdk_helpers.get_main_cmd() LOG.error(err) LOG.info("{0}".format(constants.LOG_DIVIDER)) # Print specifc usage for that cmd for these errors if "too few arguments" in err.message or "no subcommand provided" in err.message: if main_cmd == cmd_codegen.CMD_NAME: cmd_codegen.parser.print_usage() elif main_cmd == cmd_clone.CMD_NAME: cmd_clone.parser.print_usage() elif main_cmd == cmd_docgen.CMD_NAME: cmd_docgen.parser.print_usage() elif main_cmd == cmd_extract.CMD_NAME: cmd_extract.parser.print_usage() elif main_cmd == cmd_ext_package.CMD_NAME: cmd_ext_package.parser.print_usage() elif main_cmd == cmd_validate.CMD_NAME: cmd_validate.parser.print_usage() elif sdk_dev and main_cmd == cmd_dev.CMD_NAME: cmd_dev.parser.print_usage() else: parser.print_help() # Exit sys.exit() # If -v was specified, set the log level to DEBUG if args.verbose: LOG.setLevel(logging.DEBUG) LOG.debug("Logging set to DEBUG mode") # Handle what subcommand was called if args.cmd == cmd_docgen.CMD_NAME: cmd_docgen.execute_command(args) elif args.cmd == cmd_codegen.CMD_NAME: cmd_codegen.execute_command(args) elif args.cmd == cmd_clone.CMD_NAME: cmd_clone.execute_command(args) elif args.cmd == cmd_extract.CMD_NAME: cmd_extract.execute_command(args) elif args.cmd == cmd_ext_package.CMD_NAME: cmd_ext_package.execute_command(args) elif args.cmd == cmd_validate.CMD_NAME: cmd_validate.execute_command(args) elif sdk_dev and args.cmd == cmd_dev.CMD_NAME: cmd_dev.execute_command(args)