Inputs Module¶
inputs.inputs¶
TcEx Framework Inputs module
-
class
tcex.inputs.inputs.
Inputs
(tcex, config, config_file=None)[source]¶ Bases:
object
Module for handling inputs passed to App from CLI, Config, SecureParams, and AOT
Parameters: - tcex (tcex.TcEx) – Instance of TcEx class.
- config (dict) – A dictionary containing the configuration data for tcex and App.
- config_file (str, optional) – An filename containing JSON configuration data. Defaults to None.
-
_get_secure_params
()[source]¶ Load secure params from the API.
# API Response:
1 2 3 4 5 6 7 8
{ "inputs": { "tc_playbook_db_type": "Redis", "fail_on_error": true, "api_default_org": "TCI" } }
Returns: Parameters (“inputs”) from the TC API. Return type: dict
-
_results_tc_args
()[source]¶ Read data from results_tc file from previous run of app.
This method is only required when not running from within the TcEX platform and is only intended for testing apps locally.
-
args
(parse=False)[source]¶ Parse args if they have not already been parsed and return the Namespace for args.
Note
Accessing args should only be done directly in the App.
Returns: ArgParser parsed arguments. Return type: (namespace)
-
config
(config_data, preserve=True)[source]¶ Add configuration data to update default_args.
Below are the default args that the TcEx frameworks supports. Any App specific args should be included in the provided data.
{ "api_access_id": "$env.API_ACCESS_ID", "api_default_org": "$env.API_DEFAULT_ORG", "api_secret_key": "$envs.API_SECRET_KEY", "tc_api_path": "$env.TC_API_PATH", "tc_log_level": "debug", "tc_log_path": "log", "tc_owner": "MyOwner", "tc_proxy_host": "$env.TC_PROXY_HOST", "tc_proxy_password": "$envs.TC_PROXY_PASSWORD", "tc_proxy_port": "$env.TC_PROXY_PORT", "tc_proxy_tc": false, "tc_proxy_username": "$env.TC_PROXY_USERNAME" }
Parameters: - config (dict) – A dictionary of configuration values.
- preserve (bool) – Don’t overwrite arg values define in sys.argv
-
config_file
(filename, key=None)[source]¶ Load configuration data from provided file and update default_args.
Parameters: - config (str) – The configuration file name.
- key (str) – The configuration file encryption key.
Returns: The JSON contents of the file as a dict.
Return type: dict
-
default_args
¶ Parse args and return default args.
-
params
¶ Return input params.
-
resolved_args
(parse=False)[source]¶ Return namespace of args that have all playbook variables automatically resolved.
Note
Accessing resolved_args should only be done directly in the App.
Returns: ArgParser parsed arguments with Playbook variables automatically resolved. Return type: (namespace)
-
resolved_params
¶ Return input params.
-
tc_bool_args
¶ Return a list of default ThreatConnect Args that are booleans.
-
tc_reserved_args
¶ Return a list of all ThreatConnect reserved arg values.
inputs.argument_parser¶
TcEx Common Arg Handler
-
class
tcex.inputs.argument_parser.
TcArgumentParser
(**kwargs)[source]¶ Bases:
argparse.ArgumentParser
Overload of the ArgumentParser class.
Adding common arguments for TcEx apps.
-
_api_arguments
()[source]¶ Define TC API args.
--tc_token token Token provided by ThreatConnect for app Authorization. --tc_token_expires token_expires Expiration time for the passed Token. --api_access_id access_id Access ID used for HMAC Authorization. --api_secret_key secret_key Secret Key used for HMAC Authorization.
-
_batch_arguments
()[source]¶ Define Batch API args.
--batch_action action Action for the batch job [‘Create’, ‘Delete’]. --batch_chunk number The maximum number of indicator per batch job. --batch_halt_on_error Flag to indicate that the batch job should halt on error. --batch_poll_interval seconds Seconds between batch status polls. --batch_interval_max seconds Seconds before app should time out waiting on batch job completion. --batch_write_type type Write type for Indicator attributes [‘Append’, ‘Replace’].
-
_logger_arguments
()[source]¶ Define logger args supported by every TcEx App.
--tc_log_backup_count count The number of backup files to keep. --tc_log_max_bytes bytes The max size before rotating log file. --tc_log_file filename The app log file name. --tc_log_path path The app log path. --tc_log_to_api Flag to indicate that app should log to API. --tc_log_level level The logging level for the app. --logging level Alias for tc_log_level.
-
_playbook_arguments
()[source]¶ Define playbook specific args.
These arguments will be passed to every playbook app by default.
--tc_playbook_db_type type The DB type (currently on Redis is supported). --tc_playbook_db_context context The playbook context provided by TC. --tc_playbook_db_path path The DB path or server name. --tc_playbook_db_port port The DB port when required. --tc_playbook_out_variables vars The output variable requested by downstream apps.
-
_service_arguments
()[source]¶ Define service specific args.
These arguments will be passed to every playbook app by default.
--tc_svc_broker_cacert_file file The Broker SSL CA (full chain) certificate. --tc_svc_broker_cert_file file The Broker SSL Server certificate. --tc_svc_broker_conn_timeout seconds The Broker service conn timeout (seconds). --tc_svc_broker_host host The Broker service hostname. --tc_svc_broker_jks_file file Unused. --tc_svc_broker_jks_pwd password Unused. --tc_svc_broker_port port The Broker service port. --tc_svc_broker_service service The Broker service (mqtt/redis). --tc_svc_broker_timeout seconds The Broker service timeout (tcex only). --tc_svc_broker_token token The Broker auth token. --tc_svc_client_topic topic The topic to send client message. --tc_svc_hb_timeout_seconds seconds The heartbeat interval in seconds. --tc_svc_server_topic topic The topic to receive server message.
-
_standard_arguments
()[source]¶ Define standard args passed to every TcEx App.
--api_default_org org The TC API user default organization. --tc_api_path path The TC API path (e.g https://api.threatconnect.com). --tc_in_path path The app in path. --tc_out_path path The app out path. --tc_secure_params bool Flag to indicator secure params is supported. --tc_temp_path path The app temp path. --tc_user_id id The user id of user running the job. --tc_proxy_host host The proxy host. --tc_proxy_port port The proxy port. --tc_proxy_username user The proxy username. --tc_proxy_password pass The proxy password. --tc_proxy_external Flag to indicate external communications requires the use of a proxy. --tc_proxy_tc Flag to indicate TC communications requires the use of a proxy.
-
add_argument
(*args, **kwargs)[source]¶ Customize add_argument method for parser.
Remove required flag from App args and instead insert a default value from default_args namespace. This is an attempt to move away from manipulating sys.argv and using args in favor on adding args in as a config (dict) in all cases.
-