def test_set_cors(self):
        # Arrange
        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, exposed_headers,
                              allowed_headers)

        cors = [cors_rule1, cors_rule2]

        # Act
        self.bs.set_blob_service_properties(cors=cors)

        # Assert
        received_props = self.bs.get_blob_service_properties()
        self._assert_cors_equal(received_props.cors, cors)
    def test_too_many_cors_rules(self):
        # Arrange
        cors = []
        for i in range(0, 6):
            cors.append(CorsRule(['www.xyz.com'], ['GET']))

        # Assert
        self.assertRaises(AzureHttpError, self.bs.set_blob_service_properties,
                          None, None, None, cors)
Exemplo n.º 3
0
def _fix_cors(args):
    cs = CloudStorage()

    if cs.can_use_advanced_azure:
        from azure.storage import blob as azure_blob
        from azure.storage import CorsRule

        blob_service = azure_blob.BlockBlobService(cs.driver_options['key'],
                                                   cs.driver_options['secret'])

        blob_service.set_blob_service_properties(cors=[
            CorsRule(allowed_origins=args['<domains>'],
                     allowed_methods=['GET'])
        ])
        print('Done!')
    else:
        print('The driver {driver_name} being used does not currently'
              ' support updating CORS rules through'
              ' cloudstorage.'.format(driver_name=cs.driver_name))
    def service_properties(self):
        # Basic
        self.service.set_file_service_properties(
            hour_metrics=Metrics(enabled=True, include_apis=True),
            minute_metrics=Metrics(enabled=True, include_apis=False),
            cors=[CorsRule(allowed_origins=['*'], allowed_methods=['GET'])])

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

        props = self.service.get_file_service_properties(
        )  # props = ServiceProperties() w/ all properties specified above

        # Omitted properties will not overwrite what's already on the self.service
        # Empty properties will clear
        self.service.set_file_service_properties(cors=[])

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

        props = self.service.get_file_service_properties(
        )  # props = ServiceProperties() w/ CORS rules cleared