예제 #1
0
    def __init__(
        self,
        tenant_id,
        client_id,
        client_secret,
        resource_group_name,
        storage_account_name,
        subscription_id=None,
        cloud="public",
    ):
        """Establish connection information."""
        self._resource_group_name = resource_group_name
        self._storage_account_name = storage_account_name
        self._factory = AzureClientFactory(subscription_id, tenant_id,
                                           client_id, client_secret, cloud)

        if not self._factory.subscription_id:
            raise AzureServiceError("Azure Service missing subscription id.")

        self._cloud_storage_account = self._factory.cloud_storage_account(
            resource_group_name, storage_account_name)

        if not self._factory.credentials:
            raise AzureServiceError(
                "Azure Service credentials are not configured.")
예제 #2
0
    def __init__(self,
                 subscription_id,
                 tenant_id,
                 client_id,
                 client_secret,
                 resource_group_name,
                 storage_account_name,
                 cloud='public'):
        """Establish connection information."""
        self._resource_group_name = resource_group_name
        self._storage_account_name = storage_account_name
        self._factory = AzureClientFactory(subscription_id, tenant_id,
                                           client_id, client_secret, cloud)
        self._cloud_storage_account = self._factory.cloud_storage_account(
            resource_group_name, storage_account_name)
        try:
            self._blockblob_service = self._cloud_storage_account.create_block_blob_service(
            )
        except AzureException as error:
            raise AzureServiceError(
                'Unable to create block blob service. Error: %s', str(error))

        if not self._factory.credentials:
            raise AzureServiceError(
                'Azure Service credentials are not configured.')
예제 #3
0
 def test_constructor(self, _):
     """Test that we can create an AzureClientFactory object."""
     obj = AzureClientFactory(subscription_id=FAKE.uuid4(),
                              tenant_id=FAKE.uuid4(),
                              client_id=FAKE.uuid4(),
                              client_secret=FAKE.word(),
                              cloud=random.choice(self.clouds))
     self.assertTrue(isinstance(obj, AzureClientFactory))
예제 #4
0
 def test_subscription_id(self, _):
     """Test the subscription_id property."""
     subscription_id = FAKE.uuid4()
     obj = AzureClientFactory(subscription_id=subscription_id,
                              tenant_id=FAKE.uuid4(),
                              client_id=FAKE.uuid4(),
                              client_secret=FAKE.word(),
                              cloud=random.choice(self.clouds))
     self.assertTrue(obj.subscription_id, subscription_id)
예제 #5
0
 def test_storage_client(self, _):
     """Test the storage_client property."""
     obj = AzureClientFactory(subscription_id=FAKE.uuid4(),
                              tenant_id=FAKE.uuid4(),
                              client_id=FAKE.uuid4(),
                              client_secret=FAKE.word(),
                              cloud=random.choice(self.clouds))
     self.assertTrue(isinstance(obj.storage_client,
                                StorageManagementClient))
예제 #6
0
 def test_credentials(self, _):
     """Test the credentials property."""
     obj = AzureClientFactory(subscription_id=FAKE.uuid4(),
                              tenant_id=FAKE.uuid4(),
                              client_id=FAKE.uuid4(),
                              client_secret=FAKE.word(),
                              cloud=random.choice(self.clouds))
     self.assertTrue(
         isinstance(obj._credentials, ServicePrincipalCredentials))
예제 #7
0
 def test_cloud_storage_account(self, _):
     """Test the cloud_storage_account method."""
     subscription_id = FAKE.uuid4()
     resource_group_name = FAKE.word()
     storage_account_name = FAKE.word()
     obj = AzureClientFactory(
         subscription_id=subscription_id,
         tenant_id=FAKE.uuid4(),
         client_id=FAKE.uuid4(),
         client_secret=FAKE.word(),
         cloud=random.choice(self.clouds),
     )
     with patch.object(StorageManagementClient, "storage_accounts", return_value=None):
         cloud_account = obj.cloud_storage_account(resource_group_name, storage_account_name)
         self.assertTrue(isinstance(cloud_account, BlobServiceClient))