def file_sas(self):
        share_name = self._create_share()
        self.service.create_directory(share_name, 'dir1')
        self.service.create_file_from_text(share_name, 'dir1', 'file1',
                                           b'hello world')

        # Read access only to this particular file
        # Expires in an hour
        token = self.service.generate_file_shared_access_signature(
            share_name,
            'dir1',
            'file1',
            FilePermissions.READ,
            datetime.utcnow() + timedelta(hours=1),
        )

        # Create a service and use the SAS
        sas_service = FileService(
            account_name=self.account.account_name,
            sas_token=token,
        )

        file = sas_service.get_file_to_text(share_name, 'dir1', 'file1')
        content = file.content  # hello world

        self.service.delete_share(share_name)
    def file_sas(self):
        share_name = self._create_share()
        self.service.create_directory(share_name, 'dir1')
        self.service.create_file_from_text(share_name, 'dir1', 'file1', b'hello world')

        # Read access only to this particular file
        # Expires in an hour
        token = self.service.generate_file_shared_access_signature(
            share_name,
            'dir1',
            'file1',
            FilePermissions.READ,
            datetime.utcnow() + timedelta(hours=1),
        )

        # Create a service and use the SAS
        sas_service = FileService(
            account_name=self.account.account_name,
            sas_token=token,
        )

        file = sas_service.get_file_to_text(share_name, 'dir1', 'file1')
        content = file.content  # hello world

        self.service.delete_share(share_name)
    def sas_with_signed_identifiers(self):
        share_name = self._create_share()
        self.service.create_directory(share_name, 'dir1')
        self.service.create_file_from_text(share_name, 'dir1', 'file1',
                                           b'hello world')

        # Set access policy on share
        access_policy = AccessPolicy(permission=SharePermissions.READ,
                                     expiry=datetime.utcnow() +
                                     timedelta(hours=1))
        identifiers = {'id': access_policy}
        acl = self.service.set_share_acl(share_name, identifiers)

        # Wait 30 seconds for acl to propagate
        time.sleep(30)

        # Indicates to use the access policy set on the share
        token = self.service.generate_share_shared_access_signature(share_name,
                                                                    id='id')

        # Create a service and use the SAS
        sas_service = FileService(
            account_name=self.account.account_name,
            sas_token=token,
        )

        file = sas_service.get_file_to_text(share_name, 'dir1', 'file1')
        content = file.content  # hello world

        self.service.delete_share(share_name)
    def sas_with_signed_identifiers(self):
        share_name = self._create_share()
        self.service.create_directory(share_name, 'dir1')
        self.service.create_file_from_text(share_name, 'dir1', 'file1', b'hello world')

        # Set access policy on share
        access_policy = AccessPolicy(permission=SharePermissions.READ,
                                     expiry=datetime.utcnow() + timedelta(hours=1))
        identifiers = {'id': access_policy}
        acl = self.service.set_share_acl(share_name, identifiers)

        # Wait 30 seconds for acl to propagate
        time.sleep(30)

        # Indicates to use the access policy set on the share
        token = self.service.generate_share_shared_access_signature(
            share_name,
            id='id'
        )

        # Create a service and use the SAS
        sas_service = FileService(
            account_name=self.account.account_name,
            sas_token=token,
        )

        file = sas_service.get_file_to_text(share_name, 'dir1', 'file1')
        content = file.content  # hello world

        self.service.delete_share(share_name)
Esempio n. 5
0
def assert_file_in_file_share(test, storage_account, storage_account_key, directory, filename, expected_content):
    """Checks if there is a file with given name and content exists in the Azure File share.

    :param AzureMgmtTestCase test: test instance.
    :param str storage_account: storage account name.
    :param str storage_account_key: storage account key.
    :param str directory: folder.
    :param str filename: filename.
    :param unicode expected_content: expected content.
    """
    if not test.is_live:
        return
    service = FileService(storage_account, storage_account_key)
    actual = service.get_file_to_text(AZURE_FILES_NAME, directory, filename).content
    test.assertEqual(expected_content, actual)
Esempio n. 6
0
    def assert_file_in_file_share(test, storage_account, storage_account_key, directory, filename, expected_content):
        """Checks if there is a file with given name and content exists in the Azure File share.

        :param AzureMgmtTestCase test: test instance.
        :param str storage_account: storage account name.
        :param str storage_account_key: storage account key.
        :param str directory: folder.
        :param str filename: filename.
        :param unicode expected_content: expected content.
        """
        if not test.is_live:
            return
        service = FileService(storage_account, storage_account_key)
        actual = service.get_file_to_text(Helpers.AZURE_FILES_NAME, directory, filename).content
        test.assertEqual(expected_content, actual)
    def share_sas(self):
        share_name = self._create_share()
        self.service.create_file_from_text(share_name, None, 'file1', b'hello world')

        # Access only to the files in the given share
        # Read permissions to access files
        # Expires in an hour
        token = self.service.generate_share_shared_access_signature(
            share_name,
            SharePermissions.READ,
            datetime.utcnow() + timedelta(hours=1),
        )

        # Create a service and use the SAS
        sas_service = FileService(
            account_name=self.account.account_name,
            sas_token=token,
        )

        file = sas_service.get_file_to_text(share_name, None, 'file1')
        content = file.content  # hello world

        self.service.delete_share(share_name)
    def share_sas(self):        
        share_name = self._create_share()
        self.service.create_file_from_text(share_name, None, 'file1', b'hello world')

        # Access only to the files in the given share
        # Read permissions to access files
        # Expires in an hour
        token = self.service.generate_share_shared_access_signature(
            share_name,
            SharePermissions.READ,
            datetime.utcnow() + timedelta(hours=1),
        )

        # Create a service and use the SAS
        sas_service = FileService(
            account_name=self.account.account_name,
            sas_token=token,
        )

        file = sas_service.get_file_to_text(share_name, None, 'file1')
        content = file.content # hello world

        self.service.delete_share(share_name)