"""Application. This script is used for adding GSIRT IOC domains and ips to the custom name list in the Bloxone Threat Defense cloud. """ import logging import sys import requests from bloxone import config # Set up logging logging.basicConfig(stream=sys.stdout, level=logging.DEBUG) def domain_block_run(filename): """ PUT request to supply a modified version of IOC domains block list. Domain block list of the requested resource which replaces the original version of the IOC domain block list. """ with open(filename) as f: domain = f.readlines() payload = {'items': domain} domain_block_list_id = config.GSIRT_IOC_DOMAIN_BLOCK_LIST_ID try: response = requests.put( f'{config.BLOXONE_FW_API_URL}/custom_lists/' f'{domain_block_list_id}/items', json=payload, headers=config.headers) logging.info(response) response.raise_for_status() except requests.exceptions.HTTPError as e: if e.response.status_code == 401: logging.info(" ERROR ".center(80, "-")) logging.info("Invalid or expired API key.") exit(1) else: raise Exception('Fix the issue and retry.') if __name__ == '__main__': domain_block_run('../domain_blocks.txt')