def start() -> None: """ Ran by the webserver before it boots """ try: # Chains are given HMAC keys when created. If found, we write them to storage. key_id = secrets.get_dc_secret("hmac-id") _log.info( "HMAC keys were given to this chain on-boot. Writing them to storage." ) storage.put_object_as_json( f"KEYS/{key_id}", { "id": key_id, "key": secrets.get_dc_secret("hmac-key"), "root": True, "registration_time": 0 }) except exceptions.NotFound: _log.info( "No HMAC keys were given to this chain on-boot. Skipping credential storage write." ) _log.info("Checking if redisearch indexes need to be regenerated") redisearch.generate_indexes_if_necessary() _log.info("Finish pre-boot successful")
def start() -> None: """ Ran by the webserver before it boots """ _log.info("Checking if api key migrations need to be performed") api_key_dao.perform_api_key_migration_v1_if_necessary() try: # Chains are given HMAC keys when created. If found and root key doesn't already exist, we write them to storage. key_id = secrets.get_dc_secret("hmac-id") except exceptions.NotFound: _log.info( "No HMAC keys were given to this chain on-boot. Skipping credential storage write." ) else: try: api_key_dao.get_api_key(key_id, interchain=False) except exceptions.NotFound: _log.info( "HMAC keys were given to this chain on-boot. Writing them to storage." ) api_key = api_key_model.new_root_key( key_id, secrets.get_dc_secret("hmac-key")) api_key_dao.save_api_key(api_key) else: _log.info( "HMAC key secret already exists. Skipping credential storage write." ) if redisearch.ENABLED: _log.info("Checking if redisearch indexes need to be regenerated") redisearch.generate_indexes_if_necessary() _log.info("Finish pre-boot successful")
def start() -> None: """ Ran by the webserver before it boots """ try: # New chains are often given HMAC keys when created. If found, we write them to storage. key_id = secrets.get_dc_secret("hmac-id") json_key = json.dumps( { "id": key_id, "key": secrets.get_dc_secret("hmac-key"), "root": True, "registration_time": 0 }, separators=(",", ":")) _log.info( "HMAC keys were given to this chain on-boot. Writing them to storage." ) storage.put(f"KEYS/{key_id}", json_key.encode("utf-8")) except exceptions.NotFound: _log.info( "No HMAC keys were given to this chain on-boot. Skipping cretential storage write." ) _log.info("Checking if redisearch indexes need to be regenerated") try: redisearch.generate_indexes_if_necessary() except Exception: if not error_allowed: raise _log.info("Finish build successful")
def test_generate_indexes_if_necessary(self, mock_put_document, mock_list, mock_get_json, mock_new_l1, mock_new_txn_type): os.environ["LEVEL"] = "1" mock_redis = MagicMock(get=MagicMock(return_value=False)) redisearch._get_redisearch_index_client = MagicMock(return_value=MagicMock(redis=mock_redis)) redisearch.generate_indexes_if_necessary() redisearch._get_redisearch_index_client.assert_any_call("") redisearch._get_redisearch_index_client.assert_any_call("bk") redisearch._get_redisearch_index_client.assert_any_call("sc") redisearch._get_redisearch_index_client.assert_any_call("tx") redisearch._get_redisearch_index_client.assert_any_call("ver") mock_redis.get.assert_has_calls([call("dc:index_generation_complete"), call("dc:l5_index_generation_complete")]) self.assertEqual(mock_redis.set.call_count, 2) mock_put_document.assert_called()
def test_generate_indexes_if_necessary(self, mock_put_document, mock_list, mock_get_json, mock_new_l1, mock_new_txn_type): os.environ["LEVEL"] = "1" mock_redis = MagicMock(get=MagicMock(return_value=False)) redisearch._get_redisearch_index_client = MagicMock(return_value=MagicMock(redis=mock_redis)) redisearch.generate_indexes_if_necessary() redisearch._get_redisearch_index_client.assert_any_call("") redisearch._get_redisearch_index_client.assert_any_call("bk") redisearch._get_redisearch_index_client.assert_any_call("sc") redisearch._get_redisearch_index_client.assert_any_call("tx") mock_redis.get.assert_called_once_with("dc:index_generation_complete") mock_redis.flushall.assert_called_once() mock_redis.set.assert_called_once() mock_put_document.assert_called()