Bin Module¶
bin.bin¶
TcEx Framework Bin Command Base Module.
-
class
tcex.bin.bin.
Bin
(_args)[source]¶ Bases:
object
Base Class for ThreatConnect command line tools.
Parameters: _args (namespace) – The argparser args Namespace. -
db_conn
¶ Create a temporary in memory DB and return the connection.
-
db_create_table
(table_name, columns)[source]¶ Create a temporary DB table.
Parameters: - table_name (str) – The name of the table.
- columns (list) – List of columns to add to the DB.
-
db_insert_record
(table_name, columns)[source]¶ Insert records into DB.
Parameters: - table_name (str) – The name of the table.
- columns (list) – List of columns for insert statement.
-
db_update_record
(table_name, column, value)[source]¶ Insert records into DB.
Parameters: - table_name (str) – The name of the table.
- column (str) – The column name in which the value is to be updated.
- value (str) – The value to update in the column.
-
gen_permutations
(index=0, args=None)[source]¶ Iterate recursively over layout.json parameter names to build permutations.
Note
Permutations are for layout.json based playbook Apps.
Parameters: - index (int, optional) – The current index position in the layout names list.
- args (list, optional) – Defaults to None. The current list of args.
-
static
handle_error
(err, halt=True)[source]¶ Print errors message and optionally exit.
Parameters: - err (str) – The error message to print.
- halt (bool, optional) – Defaults to True. If True the script will exit.
-
profile_settings_args_layout_json
(required)[source]¶ Return args based on layout.json and conditional rendering.
Parameters: required (bool) – If True only required args will be returned. Returns: Dictionary of required or optional App args. Return type: dict
-
redis
¶ Return instance of Redis.
-
tcex_json
¶ Return tcex.json file contents.
-
static
update_system_path
()[source]¶ Update the system path to ensure project modules and dependencies can be found.
-
validate_layout_display
(table, display_condition)[source]¶ Check to see if the display condition passes.
Parameters: - table (str) – The name of the DB table which hold the App data.
- display_condition (str) – The “where” clause of the DB SQL statement.
Returns: True if the row count is greater than 0.
Return type: bool
-
bin.init¶
TcEx App Init.
-
class
tcex.bin.init.
Init
(_args)[source]¶ Bases:
tcex.bin.bin.Bin
Install required modules for ThreatConnect Job or Playbook App.
Parameters: _args (namespace) – The argparser args Namespace. -
check_empty_app_dir
()[source]¶ Check to see if the directory in which the app is going to be created is empty.
-
bin.lib¶
TcEx Library Builder.
-
class
tcex.bin.lib.
Lib
(_args)[source]¶ Bases:
tcex.bin.bin.Bin
Install Required Modules for App.
Parameters: _args (namespace) – The argparser args Namespace. -
_build_command
(python_executable, lib_dir_fq, proxy_enabled)[source]¶ Build the pip command for installing dependencies.
Parameters: - python_executable (str) – The fully qualified path of the Python executable.
- lib_dir_fq (str) – The fully qualified path of the lib directory.
Returns: The Python pip command with all required args.
Return type: list
-
bin.package¶
TcEx Framework Package Module.
-
class
tcex.bin.package.
Package
(_args)[source]¶ Bases:
tcex.bin.bin.Bin
Package ThreatConnect Job or Playbook App for deployment.
This method will package the app for deployment to ThreatConnect. Validation of the install.json file or files will be automatically run before packaging the app.
Parameters: _args (namespace) – The argparser args Namespace. -
_update_install_json
(install_json)[source]¶ Update install.json file.
Parameters: install_json (dict) – The contents of the install.json file. Returns: - The contents of the install.json file and boolean value that is True if
- an update was made.
Return type: dict, bool
-
_write_install_json
(filename, install_json)[source]¶ Write install.json file.
Some projects have bundles App with multiple install.json files. Typically these files are prefixed with the App name (e.g., MyApp.install.json).
Parameters: - filename (str) – The install.json file name.
- install_json (dict) – The contents of the install.json file.
-
app_name
(install_json_name)[source]¶ Return the app package name without version.
- Use the prefix on the install.json file (bundled Apps).
- Use the app_name field from the tcex.json file.
- Use the app directory name. This option should not be used.
-
app_version
(ij)[source]¶ Return the app version “v1”.
- Use app_version value from tcex.json if available. Typicall version is major only (e.g., v1), but from older Apps it could have minor version.
- Use major version from programVersion field in install.json if available.
- Default to ‘1.0.0’ updated to major version only (‘v1’).
-
bundle
(bundle_name)[source]¶ Bundle multiple Job or Playbook Apps into a single zip file.
Parameters: bundle_name (str) – The output name of the bundle zip file.
-
bundle_apps
(bundle_name, bundle_apps)[source]¶ Bundle multiple Job or Playbook Apps (.tcx files) into a single zip file.
Parameters: - bundle_name (str) – The output name of the bundle zip file.
- bundle_apps (list) – A list of Apps to include in the bundle.
-
commit_hash
¶ Return the current commit hash if available.
This is not a required task so best effort is fine. In other words this is not guaranteed to work 100% of the time.
-
bin.test¶
TcEx Framework Profile Generation Module.
-
class
tcex.bin.test.
CustomTemplates
(base_dir, branch='master')[source]¶ Custom method Template Class
-
feature_template
¶ Return the feature template file for custom methods
-
parent_template
¶ Return the parent template file for custom methods
-
-
class
tcex.bin.test.
Profiles
(profile_dir)[source]¶ Profile Class
Raises: NotImplementedError
– The delete method is not currently implemented.NotImplementedError
– The update method is not currently implemented.
-
class
tcex.bin.test.
Test
(_args)[source]¶ Bases:
tcex.bin.bin.Bin
Create profiles for ThreatConnect Job or Playbook App.
Parameters: _args (namespace) – The argparser args Namespace. -
download_file
(remote_filename)[source]¶ Download file from github.
Parameters: remote_filename (str) – The name of the file as defined in git repository.
-
output_variables
¶ Return playbook output variables
-
permutations_file
¶ Return permutations fully qualified filename.
-
profiles_dir
¶ Return profile fully qualified filename.
-
test_file
¶ Return generate test filename.
-
validation_base_file
¶ Return validations fully qualified filename.
-
validation_file
¶ Return validations fully qualified filename.
-
-
class
tcex.bin.test.
TestProfileTemplates
(base_dir, branch='master')[source]¶ TestProfile Template Class
-
test_profiles_template
¶ Return template file
-
-
class
tcex.bin.test.
ValidationTemplates
(base_dir, branch='master')[source]¶ Validation Template Class
Raises: NotImplementedError
– The delete method is not currently implemented.NotImplementedError
– The update method is not currently implemented.
-
_method_name
(variable)[source]¶ Convert variable name to a valid method name.
Parameters: variable (string) – The variable name to convert. Returns: Method name Return type: (str)
-
custom_template
¶ Return template file
-
feature_template
¶ Return template file
-
parent_template
¶ Return template file
bin.validate¶
TcEx Framework Validate Module.
-
class
tcex.bin.validate.
Validate
(_args)[source]¶ Bases:
tcex.bin.bin.Bin
Validate syntax, imports, and schemas.
- Python and JSON file syntax
- Python import modules
- install.json schema
- layout.json schema
Parameters: _args (namespace) – The argparser args Namespace. -
static
check_import_stdlib
(module)[source]¶ Check if module is in Python stdlib.
Parameters: module (str) – The name of the module to check. Returns: Returns True if the module is in the stdlib or template. Return type: bool
-
static
check_imported
(module)[source]¶ Check whether the provide module can be imported (package installed). :param module: The name of the module to check availability. :type module: str
Returns: True if the module can be imported, False otherwise. Return type: bool
-
check_imports
()[source]¶ Check the projects top level directory for missing imports.
This method will check only files ending in .py and does not handle imports validation for sub-directories.
-
check_layout_params
()[source]¶ Check that the layout.json is consistent with install.json.
The layout.json files references the params.name from the install.json file. The method will validate that no reference appear for inputs in install.json that don’t exist.
-
check_syntax
(app_path=None)[source]¶ Run syntax on each “.py” and “.json” file.
Parameters: app_path (str, optional) – Defaults to None. The path of Python files.
-
install_json_schema
¶ Load install.json schema file.
-
layout_json_schema
¶ Load layout.json schema file.