sas_definition_sample.py
def create_account_sas_definition(self):
        """
        Creates an account sas definition, to manage storage account and its entities.
        """
        from azure.storage.common import SharedAccessSignature, CloudStorageAccount
        from azure.keyvault.models import SasTokenType, SasDefinitionAttributes
        from azure.keyvault import SecretId

        # To create an account sas definition in the vault we must first create the template. The
        # template_uri for an account sas definition is the intended account sas token signed with an arbitrary key.
        # Use the SharedAccessSignature class from azure.storage.common to create a account sas token
        sas = SharedAccessSignature(account_name=self.config.storage_account_name,
                                    # don't sign the template with the storage account key use key 00000000
                                    account_key='00000000')
        account_sas_template = sas.generate_account(services='bfqt',  # all services blob, file, queue and table
                                                    resource_types='sco',  # all resources service, template, object
                                                    permission='acdlpruw',
                                                    # all permissions add, create, list, process, read, update, write
                                                    expiry='2020-01-01')  # expiry will be ignored and validity period will determine token expiry

        # use the created template to create a sas definition in the vault
        attributes = SasDefinitionAttributes(enabled=True)
        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='acctall',
                                                          template_uri=account_sas_template,
                                                          sas_type=SasTokenType.account,
                                                          validity_period='PT2H',
                                                          sas_definition_attributes=attributes)

        # When the sas definition is created a corresponding managed secret is also created in the vault, the. This
        # secret is used to provision sas tokens according to the sas definition.  Users retrieve the sas token
        # via the get_secret method.

        # get the secret id from the returned SasDefinitionBundle
        sas_secret_id = SecretId(uri=sas_def.secret_id)
        # call get_secret and the value of the returned SecretBundle will be a newly issued sas token
        acct_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

        # create the cloud storage account object
        cloud_storage_account = CloudStorageAccount(account_name=self.config.storage_account_name,
                                                    sas_token=acct_sas_token)

        # create a blob with the account sas token
        blob_service = cloud_storage_account.create_block_blob_service()
        blob_service.create_container('blobcontainer')
        blob_service.create_blob_from_text(container_name='blobcontainer',
                                           blob_name='blob1',
                                           text=u'test blob1 data')

        Creates an account sas definition, to manage storage account and its entities.
        
Creates an account sas definition, to manage storage account and its entities.
Creates an account sas definition to manage storage account and its entities .
def create_account_sas_definition(self):
        from azure.storage.common import SharedAccessSignature, CloudStorageAccount
        from azure.keyvault.models import SasTokenType, SasDefinitionAttributes
        from azure.keyvault import SecretId
        sas = SharedAccessSignature(account_name=self.config.storage_account_name,
                                    account_key='00000000')
        account_sas_template = sas.generate_account(services='bfqt',  
                                                    resource_types='sco',  
                                                    permission='acdlpruw',
                                                    expiry='2020-01-01')  
        attributes = SasDefinitionAttributes(enabled=True)
        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='acctall',
                                                          template_uri=account_sas_template,
                                                          sas_type=SasTokenType.account,
                                                          validity_period='PT2H',
                                                          sas_definition_attributes=attributes)
        sas_secret_id = SecretId(uri=sas_def.secret_id)
        acct_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
        cloud_storage_account = CloudStorageAccount(account_name=self.config.storage_account_name,
                                                    sas_token=acct_sas_token)
        blob_service = cloud_storage_account.create_block_blob_service()
        blob_service.create_container('blobcontainer')
        blob_service.create_blob_from_text(container_name='blobcontainer',
                                           blob_name='blob1',
                                           text=u'test blob1 data')
def create_account_sas_definition ( self ) : from azure . storage . common import SharedAccessSignature , CloudStorageAccount from azure . keyvault . models import SasTokenType , SasDefinitionAttributes from azure . keyvault import SecretId sas = SharedAccessSignature ( account_name = self . config . storage_account_name , account_key = '00000000' ) account_sas_template = sas . generate_account ( services = 'bfqt' , resource_types = 'sco' , permission = 'acdlpruw' , expiry = '2020-01-01' ) attributes = SasDefinitionAttributes ( enabled = True ) 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 = 'acctall' , template_uri = account_sas_template , sas_type = SasTokenType . account , validity_period = 'PT2H' , sas_definition_attributes = attributes ) sas_secret_id = SecretId ( uri = sas_def . secret_id ) acct_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 cloud_storage_account = CloudStorageAccount ( account_name = self . config . storage_account_name , sas_token = acct_sas_token ) blob_service = cloud_storage_account . create_block_blob_service ( ) blob_service . create_container ( 'blobcontainer' ) blob_service . create_blob_from_text ( container_name = 'blobcontainer' , blob_name = 'blob1' , text = u'test blob1 data' )
Creates an account sas definition, to manage storage account and its entities.
Creates an account sas definition to manage storage account and its entities .
"""
        Creates an account sas definition, to manage storage account and its entities.
        """ # To create an account sas definition in the vault we must first create the template. The # template_uri for an account sas definition is the intended account sas token signed with an arbitrary key. # Use the SharedAccessSignature class from azure.storage.common to create a account sas token # don't sign the template with the storage account key use key 00000000 # all services blob, file, queue and table # all resources service, template, object # all permissions add, create, list, process, read, update, write # expiry will be ignored and validity period will determine token expiry # use the created template to create a sas definition in the vault # When the sas definition is created a corresponding managed secret is also created in the vault, the. This # secret is used to provision sas tokens according to the sas definition.  Users retrieve the sas token # via the get_secret method. # get the secret id from the returned SasDefinitionBundle # call get_secret and the value of the returned SecretBundle will be a newly issued sas token # create the cloud storage account object # create a blob with the account sas token
self