def main(): install_logging("Validate Premium Packs.log") options = options_handler() exit_code = 0 index_data, index_file_path = get_index_json_data( service_account=options.service_account, production_bucket_name=options.production_bucket_name, extract_path=options.extract_path, storage_base_path=options.storage_base_path ) # Get the first host by the ami env hosts, _ = Build.get_servers(ami_env=options.ami_env) internal_ip, tunnel_port = list(hosts.items())[0] username, password = extract_credentials_from_secret(options.secret) server = Server(internal_ip=internal_ip, port=tunnel_port, user_name=username, password=password) # Verify premium packs in the server paid_packs = get_premium_packs(client=server.client) if paid_packs: logging.info(f"Verifying premium packs in {server.internal_ip}") paid_packs_are_identical = verify_server_paid_packs_by_index(paid_packs, index_data["packs"]) log_message_if_statement(statement=paid_packs_are_identical, error_message=f"Test failed on host: {server.internal_ip}.", success_message=f"All premium packs in host: {server.internal_ip} are valid") if not paid_packs_are_identical: exit_code = 1 else: logging.critical(f"Missing all premium packs in host: {server.internal_ip}") exit_code = 1 # Deleting GCS PATH before exit if os.path.exists(options.service_account): os.remove(options.service_account) sys.exit(exit_code)
def main(): install_logging('Install_Packs.log') options = options_handler() # Get the host by the ami env hosts, _ = Build.get_servers(ami_env=options.ami_env) logging.info('Retrieving the credentials for Cortex XSOAR server') secret_conf_file = get_json_file(path=options.secret) username: str = secret_conf_file.get('username') password: str = secret_conf_file.get('userPassword') # Configure the Servers for host in hosts: server = Server(host=host, user_name=username, password=password) logging.info(f'Adding Marketplace configuration to {host}') error_msg: str = 'Failed to set marketplace configuration.' server.add_server_configuration(config_dict=MARKET_PLACE_CONFIGURATION, error_msg=error_msg) set_marketplace_url(servers=[server], branch_name=options.branch, ci_build_number=options.build_number) # Acquire the server's host and install all content packs (one threaded execution) logging.info(f'Starting to install all content packs in {host}') server_host: str = server.client.api_client.configuration.host install_all_content_packs(client=server.client, host=server_host) logging.success(f'Finished installing all content packs in {host}')
def main(): install_logging('Install_Packs.log', logger=logging) options = options_handler() # Get the host by the ami env server_to_port_mapping, server_version = Build.get_servers( ami_env=options.ami_env) logging.info('Retrieving the credentials for Cortex XSOAR server') secret_conf_file = get_json(file_path=options.secret) username: str = secret_conf_file.get('username') password: str = secret_conf_file.get('userPassword') branch_name: str = options.branch build_number: str = options.build_number # Configure the Servers for server_url, port in server_to_port_mapping.items(): server = Server(internal_ip=server_url, port=port, user_name=username, password=password) logging.info(f'Adding Marketplace configuration to {server_url}') error_msg: str = 'Failed to set marketplace configuration.' server.add_server_configuration(config_dict=MARKET_PLACE_CONFIGURATION, error_msg=error_msg) set_marketplace_url(servers=[server], branch_name=branch_name, ci_build_number=build_number) # Acquire the server's host and install all content packs (one threaded execution) logging.info(f'Starting to install all content packs in {server_url}') server_host: str = server.client.api_client.configuration.host success_flag = install_all_content_packs_from_build_bucket( client=server.client, host=server_host, server_version=server_version, bucket_packs_root_path=GCPConfig. BUILD_BUCKET_PACKS_ROOT_PATH.format(branch=branch_name, build=build_number, marketplace='xsoar'), service_account=options.service_account, extract_destination_path=options.extract_path) if success_flag: logging.success( f'Finished installing all content packs in {server_url}') else: logging.error('Failed to install all packs.') sys.exit(1)