def test_get_storage_client_by_uri(self): account = self.setup_account() url = "https://" + account.name + ".blob.core.windows.net/testcontainer/extrafolder" blob_service, container_name, key_prefix = StorageUtilities.get_blob_client_by_uri(url) self.assertIsNotNone(blob_service) self.assertEqual(container_name, "testcontainer") self.assertEqual(key_prefix, "extrafolder")
def test_get_storage_client_by_uri(self): account = self.setup_account() url = "https://" + account.name + ".blob.core.windows.net/testcontainer" blob_service, container_name = StorageUtilities.get_blob_client_by_uri( url) self.assertIsNotNone(blob_service) self.assertIsNotNone(container_name)
def test_get_storage_client_by_uri(self): account = self.setup_account() url = "https://" + account.name + ".blob.core.windows.net/testcontainer/extrafolder" blob_service, container_name, key_prefix = StorageUtilities.get_blob_client_by_uri(url) self.assertIsNotNone(blob_service) self.assertEqual(container_name, "testcontainer") self.assertEqual(key_prefix, "extrafolder")
def update_policies(self): """ Enumerate all policies from storage. Use the MD5 hashes in the enumerated policies and a local dictionary to decide if we should bother downloading/updating each blob. We maintain an on-disk policy cache for future features. """ if not self.policy_blob_client: self.policy_blob_client = Storage.get_blob_client_by_uri(self.policy_storage_uri, self.storage_session) (client, container, prefix) = self.policy_blob_client try: # All blobs with YAML extension blobs = [b for b in client.list_blobs(container) if Host.has_yaml_ext(b.name)] except AzureHttpError as e: # If blob methods are failing don't keep # a cached client self.policy_blob_client = None raise e # Filter to hashes we have not seen before new_blobs = self._get_new_blobs(blobs) # Get all YAML files on disk that are no longer in blob storage cached_policy_files = [f for f in os.listdir(self.policy_cache) if Host.has_yaml_ext(f)] removed_files = [f for f in cached_policy_files if f not in [b.name for b in blobs]] if not (removed_files or new_blobs): return # Update a copy so we don't interfere with # iterations on other threads policies_copy = self.policies.copy() for f in removed_files: path = os.path.join(self.policy_cache, f) self.unload_policy_file(path, policies_copy) # Get updated YML files for blob in new_blobs: policy_path = os.path.join(self.policy_cache, blob.name) if os.path.exists(policy_path): self.unload_policy_file(policy_path, policies_copy) elif not os.path.isdir(os.path.dirname(policy_path)): os.makedirs(os.path.dirname(policy_path)) client.get_blob_to_path(container, blob.name, policy_path) self.load_policy(policy_path, policies_copy) self.blob_cache.update({blob.name: blob.properties.content_settings.content_md5}) # Assign our copy back over the original self.policies = policies_copy
def test_get_blob_client_by_uri_china_cloud(self, mock_create): url = CHINA_STORAGE_ACCOUNT + "/testcontainer/extrafolder" blob_service, container_name, key_prefix = \ StorageUtilities.get_blob_client_by_uri(url, Session(cloud_endpoints=AZURE_CHINA_CLOUD)) self.assertIsNotNone(blob_service) self.assertEqual(container_name, "testcontainer") self.assertEqual(key_prefix, "extrafolder") self.assertTrue(CHINA_STORAGE_ENDPOINT in blob_service.primary_endpoint) self.assertTrue(mock_create.called_once())
def test_get_storage_client_by_uri(self): account = self.setup_account() url = "https://" + account.name + ".blob.core.windows.net/testcontainer" blob_service, container_name = StorageUtilities.get_blob_client_by_uri(url) self.assertIsNotNone(blob_service) self.assertIsNotNone(container_name)
def get_blob_client_wrapper(output_path, ctx): # provides easier test isolation s = local_session(ctx.session_factory) return StorageUtilities.get_blob_client_by_uri(output_path, s)
def get_blob_client_wrapper(output_path): # provides easier test isolation return StorageUtilities.get_blob_client_by_uri(output_path)
def get_blob_client_wrapper(output_path, ctx): # provides easier test isolation s = local_session(ctx.session_factory) return StorageUtilities.get_blob_client_by_uri(output_path, s)