コード例 #1
0
 def test_hash_records_for_search(self):
     mock_keys = {
         ApiKeys.SALT_KEYS: [{
             "value": "test-salt-key"
         }],
         ApiKeys.ENCRYPTION_KEY:
         "_hSmVyMTLi-Qo_rmISp8jrH5Aob7frHp1X-28sxQZAU="
     }
     search_queries = HashService.hash_records_for_search(
         self.config, mock_keys)
     assert search_queries.keys() is not None
     for key in search_queries:
         assert isinstance(search_queries[key], list)
         assert isinstance(search_queries[key][0], str)
コード例 #2
0
def run(input_file, log_file, mode):
    """Entry point for the INOIS application."""

    log_level = logging.DEBUG if log_file else logging.CRITICAL
    log_location = log_file if log_file else "inois.log"
    logging.basicConfig(format='%(asctime)s (%(levelname)s): %(message)s',
                        filename=log_location,
                        level=log_level)

    application_mode = mode if mode == ApplicationModeKeys.SEARCH else ApplicationModeKeys.UPLOAD

    logging.info(
        Notifications.APPLICATION_STARTED.format(application_mode,
                                                 datetime.now()))
    print("\n" + Notifications.APPLICATION_STARTED.format(
        application_mode, datetime.now()))
    print(Banner.TEXT)
    config = ConfigService.initialize_config(input_file=input_file)
    session = AuthenticationService(config).get_authorization()
    FileService.validate_files(config)
    keys = KeyService.get_keys(config, session)

    if application_mode == ApplicationModeKeys.UPLOAD:
        HashService.hash_files(config, keys)
        FileService.delete_chunked_files(config)
        EncryptionService.encrypt_files(config, keys)
        FileService.delete_hashed_files(config)
        UploadService.upload_files(config, session)
        FileService.delete_encrypted_files(config)

    elif application_mode == ApplicationModeKeys.SEARCH:
        search_queries = HashService.hash_records_for_search(config, keys)
        SearchService.search_on_all_queries(search_queries, session)

    os.chdir(config.LAUNCH_DIRECTORY)
    logging.info(Notifications.APPLICATION_TERMINATED.format(datetime.now()))
    print("\n" + Notifications.APPLICATION_TERMINATED.format(datetime.now()))