Пример #1
0
    async def list_shares_in_service_async(self):
        # Instantiate the ShareServiceClient from a connection string
        from azure.storage.fileshare.aio import ShareServiceClient
        file_service = ShareServiceClient.from_connection_string(
            self.connection_string)

        async with file_service:
            # [START fsc_create_shares]
            await file_service.create_share(share_name="fileshare1")
            # [END fsc_create_shares]
            try:
                # [START fsc_list_shares]
                # List the shares in the file service
                my_shares = []
                async for s in file_service.list_shares():
                    my_shares.append(s)

                # Print the shares
                for share in my_shares:
                    print(share)
                # [END fsc_list_shares]

            finally:
                # [START fsc_delete_shares]
                await file_service.delete_share(share_name="fileshare1")
Пример #2
0
    async def get_share_client_async(self):
        # [START get_share_client]
        from azure.storage.fileshare.aio import ShareServiceClient
        file_service = ShareServiceClient.from_connection_string(
            self.connection_string)

        # Get a share client to interact with a specific share
        share = file_service.get_share_client("fileshare2")
Пример #3
0
 def __init__(self, arguments):
     super().__init__(arguments)
     connection_string = self.get_from_env(
         "AZURE_STORAGE_CONNECTION_STRING")
     kwargs = {}
     if self.args.max_range_size:
         kwargs['max_range_size'] = self.args.max_range_size
     if not _ServiceTest.service_client or self.args.no_client_share:
         _ServiceTest.service_client = SyncShareServiceClient.from_connection_string(
             conn_str=connection_string, **kwargs)
         _ServiceTest.async_service_client = AsyncShareServiceClient.from_connection_string(
             conn_str=connection_string, **kwargs)
     self.service_client = _ServiceTest.service_client
     self.async_service_client = _ServiceTest.async_service_client
Пример #4
0
    async def file_service_properties_async(self):
        # Instantiate the ShareServiceClient from a connection string
        from azure.storage.fileshare.aio import ShareServiceClient
        file_service = ShareServiceClient.from_connection_string(
            self.connection_string)

        # [START set_service_properties]
        # Create service properties
        from azure.storage.fileshare import Metrics, CorsRule, RetentionPolicy

        # Create metrics for requests statistics
        hour_metrics = Metrics(enabled=True,
                               include_apis=True,
                               retention_policy=RetentionPolicy(enabled=True,
                                                                days=5))
        minute_metrics = Metrics(enabled=True,
                                 include_apis=True,
                                 retention_policy=RetentionPolicy(enabled=True,
                                                                  days=5))

        # Create CORS rules
        cors_rule1 = CorsRule(['www.xyz.com'], ['GET'])
        allowed_origins = ['www.xyz.com', "www.ab.com", "www.bc.com"]
        allowed_methods = ['GET', 'PUT']
        max_age_in_seconds = 500
        exposed_headers = [
            "x-ms-meta-data*", "x-ms-meta-source*", "x-ms-meta-abc",
            "x-ms-meta-bcd"
        ]
        allowed_headers = [
            "x-ms-meta-data*", "x-ms-meta-target*", "x-ms-meta-xyz",
            "x-ms-meta-foo"
        ]
        cors_rule2 = CorsRule(allowed_origins,
                              allowed_methods,
                              max_age_in_seconds=max_age_in_seconds,
                              exposed_headers=exposed_headers,
                              allowed_headers=allowed_headers)

        cors = [cors_rule1, cors_rule2]

        async with file_service:
            # Set the service properties
            await file_service.set_service_properties(hour_metrics,
                                                      minute_metrics, cors)
            # [END set_service_properties]

            # [START get_service_properties]
            properties = await file_service.get_service_properties()
Пример #5
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))
Пример #6
0
 async def create_client_with_connection_string_async(self):
     # Instantiate the ShareServiceClient from a connection string
     from azure.storage.fileshare.aio import ShareServiceClient
     file_service = ShareServiceClient.from_connection_string(
         self.connection_string)
Пример #7
0
 async def authentication_connection_string_async(self):
     # Instantiate the ShareServiceClient from a connection string
     # [START create_share_service_client_from_conn_string]
     from azure.storage.fileshare.aio import ShareServiceClient
     file_service = ShareServiceClient.from_connection_string(
         self.connection_string)