def generate_sas_token(self):
        fake_key = 'a' * 30 + 'b' * 30

        return '?' + generate_account_sas(
            account_name='test',  # name of the storage account
            account_key=fake_key,  # key for the storage account
            resource_types=ResourceTypes(object=True),
            permission=AccountSasPermissions(read=True, list=True),
            start=datetime.now() - timedelta(hours=24),
            expiry=datetime.now() + timedelta(days=8))
예제 #2
0
    async def authentication_shared_access_signature_async(self):
        # Instantiate a ShareServiceClient using a connection string
        from azure.storage.fileshare.aio import ShareServiceClient
        share_service_client = ShareServiceClient.from_connection_string(
            self.connection_string)

        # Create a SAS token to use to authenticate a new client
        from azure.storage.fileshare import generate_account_sas

        sas_token = generate_account_sas(
            share_service_client.account_name,
            share_service_client.credential.account_key,
            resource_types="object",
            permission="read",
            expiry=datetime.utcnow() + timedelta(hours=1))
예제 #3
0
    def authentication_shared_access_signature(self):
        # Instantiate a ShareServiceClient using a connection string
        # [START generate_sas_token]
        from azure.storage.fileshare import ShareServiceClient
        share_service_client = ShareServiceClient.from_connection_string(
            self.connection_string)

        # Create a SAS token to use to authenticate a new client
        from azure.storage.fileshare import generate_account_sas, ResourceTypes, AccountSasPermissions

        sas_token = generate_account_sas(
            self.account_name,
            self.access_key,
            resource_types=ResourceTypes(service=True),
            permission=AccountSasPermissions(read=True),
            expiry=datetime.utcnow() + timedelta(hours=1))
예제 #4
0
def get_a_sas_token(put_env=False):
    """
    Input: 
        - env:ACCOUNT_NAME
        - env:AZURE_STORAGE_ACCESS_KEY
    Returns: Connection_object ShareServiceClient()
    """
    refresh_var_env()
    sas_token = generate_account_sas(
        account_name=ACCOUNT_NAME,
        account_key=AZURE_STORAGE_ACCESS_KEY,
        resource_types=ResourceTypes(service=True),
        permission=AccountSasPermissions(read=True),
        expiry=datetime.utcnow() + timedelta(hours=1)
    )
    if put_env != False:os.putenv(AZ_SAS_TOKEN, connection_string)
    
    share_service_client = ShareServiceClient(
        account_url=f"https://{ACCOUNT_NAME}.file.core.windows.net", 
        credential=sas_token
    )
    return share_service_client