Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get configs #1392

Merged
merged 3 commits into from
Mar 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions stix_shifter/scripts/stix_shifter.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
HOST = 'host'
MAPPING = 'mapping'
MODULES = 'modules'
CONFIGS = 'configs'


def main():
Expand Down Expand Up @@ -73,8 +74,13 @@ def main():
# optional arguments
translate_parser.add_argument('-x', '--stix-validator', action='store_true',
help='Run the STIX 2 validator against the translated results')
# configs parser
configs_parser = parent_subparsers.add_parser(CONFIGS, help='Get configs list')
configs_parser.add_argument('module', nargs='?', type=str, help='Module name')

# modules parser
parent_subparsers.add_parser(MODULES, help='Get modules list')
modules_parser = parent_subparsers.add_parser(MODULES, help='Get configs list')
modules_parser.add_argument('module', nargs='?', type=str, help='Module name')

# mapping parser
mapping_parser = parent_subparsers.add_parser(
Expand Down Expand Up @@ -208,7 +214,7 @@ def main():
log.error('Cannot convert supplied data_source json string to json')
help_and_exit = True

if 'module' in args:
if 'module' in args and args.module:
args_module_dialects = args.module

options = {}
Expand Down Expand Up @@ -348,7 +354,15 @@ def is_async():
result = {}
all_modules = modules_list()
for m in all_modules:
result[m] = translation.translate(m, stix_translation.DIALECTS, None, None)
if not args.module or args.module == m:
result[m] = translation.translate(m, stix_translation.DIALECTS, None, None)
elif args.command == CONFIGS:
translation = stix_translation.StixTranslation()
result = {}
all_modules = modules_list()
for m in all_modules:
if not args.module or args.module == m:
result[m] = translation.translate(m, stix_translation.CONFIGS, None, None)
elif args.command == TRANSMIT:
result = transmit(args) # stix_transmission

Expand Down
7 changes: 6 additions & 1 deletion stix_shifter/stix_translation/stix_translation.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
QUERY = 'query'
PARSE = 'parse'
MAPPING = 'mapping'
CONFIGS = 'configs'
DIALECTS = 'dialects'
SUPPORTED_ATTRIBUTES = "supported_attributes"
MAPPING_ERROR = "Unable to map the following STIX objects and properties:"
Expand Down Expand Up @@ -42,7 +43,7 @@ async def translate_async(self, module, translate_type, data_source, data, optio
except Exception as ex:
raise UnsupportedDataSourceException("{} is an unsupported data source.".format(module))
try:
if not translate_type == DIALECTS:
if not translate_type == CONFIGS and not translate_type == DIALECTS:
validated_options = param_validator(module, options, 'connection.options')
else:
validated_options = {}
Expand All @@ -53,6 +54,10 @@ async def translate_async(self, module, translate_type, data_source, data, optio
self.logger.debug(track)
raise

if translate_type == CONFIGS:
dialects = entry_point.get_configs_full()
return dialects

if translate_type == DIALECTS:
dialects = entry_point.get_dialects_full()
return dialects
Expand Down
6 changes: 5 additions & 1 deletion stix_shifter_utils/utils/base_entry_point.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from stix_shifter_utils.modules.base.stix_transmission.base_status_connector import BaseStatusConnector
from stix_shifter_utils.modules.base.stix_transmission.base_ping_connector import BasePingConnector
from stix_shifter_utils.modules.base.stix_transmission.base_json_results_connector import BaseResultsConnector
from stix_shifter_utils.utils.param_validator import param_validator, modernize_objects
from stix_shifter_utils.utils.param_validator import param_validator, modernize_objects, get_merged_config
from stix_shifter_utils.stix_translation.src.utils.exceptions import UnsupportedDialectException
from stix_shifter_utils.utils.error_response import ErrorResponder

Expand Down Expand Up @@ -195,6 +195,10 @@ def get_dialects(self, include_hidden=False):
if include_hidden:
return self.__dialects_all
return self.__dialects_active_default

@translation
def get_configs_full(self):
return get_merged_config(self.__connector_module)

@translation
def get_dialects_full(self):
Expand Down