def test_validate_remove_file(): tf = '/tmp/remove.cfg' with open(tf, 'wb') as f: f.write(remove_file_content) assert util.validate_remove_file(remove_file='/tmp/boop') is False os.chmod(tf, 0o644) assert util.validate_remove_file(remove_file=tf) is False os.chmod(tf, 0o600) assert util.validate_remove_file(remove_file=tf) is not False
def pre_update(client, config): if config.version: logger.info(constants.version) sys.exit(constants.sig_kill_ok) # validate the remove file if config.validate: try: validate_remove_file(config) sys.exit(constants.sig_kill_ok) except RuntimeError as e: logger.error(e) sys.exit(constants.sig_kill_bad) # handle cron stuff if config.enable_schedule: # enable automatic scheduling logger.debug('Updating config...') updated = get_scheduler(config).set_daily() if updated: logger.info('Automatic scheduling for Insights has been enabled.') sys.exit(constants.sig_kill_ok) if config.disable_schedule: # disable automatic schedling updated = get_scheduler(config).remove_scheduling() if updated: logger.info('Automatic scheduling for Insights has been disabled.') if not config.register: sys.exit(constants.sig_kill_ok) # test the insights connection if config.test_connection: logger.info("Running Connection Tests...") rc = client.test_connection() if rc == 0: sys.exit(constants.sig_kill_ok) else: sys.exit(constants.sig_kill_bad) if config.support: support = InsightsSupport(config) support.collect_support_info() sys.exit(constants.sig_kill_ok) if config.diagnosis: remediation_id = None if config.diagnosis is not True: remediation_id = config.diagnosis resp = client.get_diagnosis(remediation_id) if not resp: sys.exit(constants.sig_kill_bad) print(json.dumps(resp)) sys.exit(constants.sig_kill_ok)
def test_validate_remove_file_bad_perms(): tf = '/tmp/remove.cfg' with open(tf, 'wb') as f: f.write(remove_file_content) conf = InsightsConfig(remove_file=tf, redaction_file=None, content_redaction_file=None, validate=True) with pytest.raises(RuntimeError): os.chmod(tf, 0o644) util.validate_remove_file(conf) os.chmod(tf, 0o600) assert util.validate_remove_file(conf) is not False os.remove(tf)
def pre_update(): if config['version']: logger.info(constants.version) sys.exit(constants.sig_kill_ok) # validate the remove file if config['validate']: if validate_remove_file(): sys.exit(constants.sig_kill_ok) else: sys.exit(constants.sig_kill_bad) # handle cron stuff if config['enable_schedule'] and config['disable_schedule']: logger.error( 'Conflicting options: --enable-schedule and --disable-schedule') sys.exit(constants.sig_kill_bad) if config['enable_schedule']: # enable automatic scheduling logger.debug('Updating config...') updated = get_scheduler().set_daily() if updated: logger.info('Automatic scheduling for Insights has been enabled.') sys.exit(constants.sig_kill_ok) if config['disable_schedule']: # disable automatic schedling updated = get_scheduler().remove_scheduling() if updated: logger.info('Automatic scheduling for Insights has been disabled.') if not config['register']: sys.exit(constants.sig_kill_ok) if config['container_mode']: logger.debug('Not scanning host.') logger.debug('Scanning image ID, tar file, or mountpoint.') # test the insights connection if config['test_connection']: logger.info("Running Connection Tests...") pconn = client.get_connection() rc = pconn.test_connection() if rc == 0: sys.exit(constants.sig_kill_ok) else: sys.exit(constants.sig_kill_bad) if config['support']: support = InsightsSupport() support.collect_support_info() sys.exit(constants.sig_kill_ok)
def pre_update(client, config): if config.version: logger.info(constants.version) sys.exit(constants.sig_kill_ok) # validate the remove file if config.validate: if validate_remove_file(): sys.exit(constants.sig_kill_ok) else: sys.exit(constants.sig_kill_bad) # handle cron stuff if config.enable_schedule: # enable automatic scheduling logger.debug('Updating config...') updated = get_scheduler(config).set_daily() if updated: logger.info('Automatic scheduling for Insights has been enabled.') sys.exit(constants.sig_kill_ok) if config.disable_schedule: # disable automatic schedling updated = get_scheduler(config).remove_scheduling() if updated: logger.info('Automatic scheduling for Insights has been disabled.') if not config.register: sys.exit(constants.sig_kill_ok) if config.analyze_container: logger.debug('Not scanning host.') logger.debug('Scanning image ID, tar file, or mountpoint.') # test the insights connection if config.test_connection: logger.info("Running Connection Tests...") pconn = client.get_connection() rc = pconn.test_connection() if rc == 0: sys.exit(constants.sig_kill_ok) else: sys.exit(constants.sig_kill_bad) if config.support: support = InsightsSupport() support.collect_support_info() sys.exit(constants.sig_kill_ok)