def main() -> None: """Main function""" args = cli.handle_args(parseargs()) actapi = worker.init_act(args) ta_cards = worker.fetch_json( args.thaicert_url, args.proxy_string, args.http_timeout ) process(actapi, ta_cards["values"]) vocab = worker.fetch_json(STIX_VOCAB, args.proxy_string, args.http_timeout) add_sectors(actapi, ta_cards["values"], vocab) countries = worker.fetch_json(COUNTRY_REGIONS, args.proxy_string, args.http_timeout) countries = [country["name"].lower() for country in countries] add_countries(actapi, ta_cards["values"], countries) tools = worker.fetch_json(THAICERT_TOOLS_URL, args.proxy_string, args.http_timeout) add_tools(actapi, ta_cards["values"], tools["values"])
def fetch_country_regions(country_region: Text, proxy_string: Text, http_timeout: int) -> Dict[Text, Text]: "Fetch ISO-3166 list of country/regions" vocabulary: Dict = {} for c_map in worker.fetch_json(country_region, proxy_string, http_timeout): country = c_map["name"] vocabulary[country.lower()] = country return vocabulary
def get_attack(url: str, proxy_string: str, timeout: int) -> MemoryStore: """Fetch Mitre ATT&CK JSON data in Stix2 format and return a Stix2 memory store""" attack = worker.fetch_json(url, proxy_string, timeout) # Create memory store mem = MemoryStore() # Add all objects to the memory store for obj in parse(attack, allow_custom=True).objects: mem.add(obj) return mem
def main_log_error() -> None: "Main function. Log all exceptions to error" # Look for default ini file in "/etc/actworkers.ini" and ~/config/actworkers/actworkers.ini # (or replace .config with $XDG_CONFIG_DIR if set) args = worker.handle_args(parseargs()) actapi = worker.init_act(args) try: process( actapi, worker.fetch_json(args.country_region_url, args.proxy_string, args.http_timeout), args.output_format) except Exception: error("Unhandled exception: {}".format(traceback.format_exc())) raise
def main_log_error() -> None: "Main function. Log all exceptions to error" # Look for default ini file in "/etc/actworkers.ini" and ~/config/actworkers/actworkers.ini # (or replace .config with $XDG_CONFIG_DIR if set) args = worker.handle_args(parseargs()) auth = None if args.http_user: auth = (args.http_user, args.http_password) actapi = act.api.Act(args.act_baseurl, args.user_id, args.loglevel, args.logfile, worker.worker_name(), requests_common_kwargs={'auth': auth}) try: process( actapi, worker.fetch_json(args.country_region_url, args.proxy_string, args.http_timeout), args.output_format ) except Exception: error("Unhandled exception: {}".format(traceback.format_exc())) raise