sas_definition_sample.py
def create_blob_sas_defintion(self):
        """
        Creates a service SAS definition with access to a blob container.
        """

        from azure.storage.blob import BlockBlobService, ContainerPermissions
        from azure.keyvault.models import SasTokenType, SasDefinitionAttributes
        from azure.keyvault import SecretId

        # create the blob sas definition template
        # the sas template uri for service sas definitions contains the storage entity url with the template token
        # this sample demonstrates constructing the template uri for a blob container, but a similar approach can
        # be used for all other storage service, i.e. File, Queue, Table

        # create a template sas token for the container
        service = BlockBlobService(account_name=self.config.storage_account_name,
                                   # don't sign the template with the storage account key use key 00000000
                                   account_key='00000000')
        permissions = ContainerPermissions(read=True, write=True, delete=True, list=True)
        temp_token = service.generate_container_shared_access_signature(container_name='blobcontainer',
                                                                        permission=permissions,
                                                                        expiry='2020-01-01')

        # use the BlockBlobService to construct the template uri for the container sas definition
        blob_sas_template_uri = service.make_container_url(container_name='blobcontainer',
                                                           protocol='https',
                                                           sas_token=temp_token)
        # create the sas definition in the vault
        attributes = SasDefinitionAttributes(enabled=True)
        blob_sas_def = self.keyvault_client.set_sas_definition(vault_base_url=self.sample_vault_url,
                                                               storage_account_name=self.config.storage_account_name,
                                                               sas_definition_name='blobcontall',
                                                               template_uri=blob_sas_template_uri,
                                                               sas_type=SasTokenType.service,
                                                               validity_period='PT2H',
                                                               sas_definition_attributes=attributes)

        # use the sas definition to provision a sas token and use it to  create a BlockBlobClient
        # which can interact with blobs in the container

        # get the secret_id of the container sas definition and get the token from the vault as a secret
        sas_secret_id = SecretId(uri=blob_sas_def.secret_id)
        blob_sas_token = self.keyvault_client.get_secret(vault_base_url=sas_secret_id.vault,
                                                         secret_name=sas_secret_id.name,
                                                         secret_version=sas_secret_id.version).value
        service = BlockBlobService(account_name=self.config.storage_account_name,
                                   sas_token=blob_sas_token)
        service.create_blob_from_text(container_name='blobcontainer',
                                      blob_name='blob2',
                                      text=u'test blob2 data')
        blobs = list(service.list_blobs(container_name='blobcontainer'))

        for blob in blobs:
            service.delete_blob(container_name='blobcontainer',
                                blob_name=blob.name)

        Creates a service SAS definition with access to a blob container.
        
Creates a service SAS definition with access to a blob container.
Creates a service SAS definition with access to a blob container .
def create_blob_sas_defintion(self):
        from azure.storage.blob import BlockBlobService, ContainerPermissions
        from azure.keyvault.models import SasTokenType, SasDefinitionAttributes
        from azure.keyvault import SecretId
        service = BlockBlobService(account_name=self.config.storage_account_name,
                                   account_key='00000000')
        permissions = ContainerPermissions(read=True, write=True, delete=True, list=True)
        temp_token = service.generate_container_shared_access_signature(container_name='blobcontainer',
                                                                        permission=permissions,
                                                                        expiry='2020-01-01')
        blob_sas_template_uri = service.make_container_url(container_name='blobcontainer',
                                                           protocol='https',
                                                           sas_token=temp_token)
        attributes = SasDefinitionAttributes(enabled=True)
        blob_sas_def = self.keyvault_client.set_sas_definition(vault_base_url=self.sample_vault_url,
                                                               storage_account_name=self.config.storage_account_name,
                                                               sas_definition_name='blobcontall',
                                                               template_uri=blob_sas_template_uri,
                                                               sas_type=SasTokenType.service,
                                                               validity_period='PT2H',
                                                               sas_definition_attributes=attributes)
        sas_secret_id = SecretId(uri=blob_sas_def.secret_id)
        blob_sas_token = self.keyvault_client.get_secret(vault_base_url=sas_secret_id.vault,
                                                         secret_name=sas_secret_id.name,
                                                         secret_version=sas_secret_id.version).value
        service = BlockBlobService(account_name=self.config.storage_account_name,
                                   sas_token=blob_sas_token)
        service.create_blob_from_text(container_name='blobcontainer',
                                      blob_name='blob2',
                                      text=u'test blob2 data')
        blobs = list(service.list_blobs(container_name='blobcontainer'))
        for blob in blobs:
            service.delete_blob(container_name='blobcontainer',
                                blob_name=blob.name)
def create_blob_sas_defintion ( self ) : from azure . storage . blob import BlockBlobService , ContainerPermissions from azure . keyvault . models import SasTokenType , SasDefinitionAttributes from azure . keyvault import SecretId service = BlockBlobService ( account_name = self . config . storage_account_name , account_key = '00000000' ) permissions = ContainerPermissions ( read = True , write = True , delete = True , list = True ) temp_token = service . generate_container_shared_access_signature ( container_name = 'blobcontainer' , permission = permissions , expiry = '2020-01-01' ) blob_sas_template_uri = service . make_container_url ( container_name = 'blobcontainer' , protocol = 'https' , sas_token = temp_token ) attributes = SasDefinitionAttributes ( enabled = True ) blob_sas_def = self . keyvault_client . set_sas_definition ( vault_base_url = self . sample_vault_url , storage_account_name = self . config . storage_account_name , sas_definition_name = 'blobcontall' , template_uri = blob_sas_template_uri , sas_type = SasTokenType . service , validity_period = 'PT2H' , sas_definition_attributes = attributes ) sas_secret_id = SecretId ( uri = blob_sas_def . secret_id ) blob_sas_token = self . keyvault_client . get_secret ( vault_base_url = sas_secret_id . vault , secret_name = sas_secret_id . name , secret_version = sas_secret_id . version ) . value service = BlockBlobService ( account_name = self . config . storage_account_name , sas_token = blob_sas_token ) service . create_blob_from_text ( container_name = 'blobcontainer' , blob_name = 'blob2' , text = u'test blob2 data' ) blobs = list ( service . list_blobs ( container_name = 'blobcontainer' ) ) for blob in blobs : service . delete_blob ( container_name = 'blobcontainer' , blob_name = blob . name )
Creates a service SAS definition with access to a blob container.
Creates a service SAS definition with access to a blob container .
"""
        Creates a service SAS definition with access to a blob container.
        """ # create the blob sas definition template # the sas template uri for service sas definitions contains the storage entity url with the template token # this sample demonstrates constructing the template uri for a blob container, but a similar approach can # be used for all other storage service, i.e. File, Queue, Table # create a template sas token for the container # don't sign the template with the storage account key use key 00000000 # use the BlockBlobService to construct the template uri for the container sas definition # create the sas definition in the vault # use the sas definition to provision a sas token and use it to  create a BlockBlobClient # which can interact with blobs in the container # get the secret_id of the container sas definition and get the token from the vault as a secret
self