コード例 #1
0
async def main():
    CONNECTION_STRING = get_connection_string()

    # Create app config client
    client = AzureAppConfigurationClient.from_connection_string(
        CONNECTION_STRING)

    print("Set new configuration setting")
    config_setting = ConfigurationSetting(key="MyKey",
                                          value="my value",
                                          content_type="my content type",
                                          tags={"my tag": "my tag value"})
    returned_config_setting = await client.set_configuration_setting(
        config_setting)
    print("New configuration setting:")
    print_configuration_setting(returned_config_setting)
    print("")

    print("Get configuration setting")
    fetched_config_setting = await client.get_configuration_setting(key="MyKey"
                                                                    )
    print("Fetched configuration setting:")
    print_configuration_setting(fetched_config_setting)
    print("")

    print("Delete configuration setting")
    await client.delete_configuration_setting(key="MyKey")
コード例 #2
0
async def main():
    CONNECTION_STRING = get_connection_string()

    # Create app config client
    client = AzureAppConfigurationClient.from_connection_string(CONNECTION_STRING)

    config_setting = ConfigurationSetting(
        key="MyKey",
        value="my value",
        content_type="my content type",
        tags={"my tag": "my tag value"}
    )
    returned_config_setting = await client.set_configuration_setting(config_setting)

    returned_config_setting.value = "new value"
    returned_config_setting.content_type = "new content type"
    await client.set_configuration_setting(config_setting)

    items = client.list_revisions(key_filter="MyKey")
    async for item in items:
        print_configuration_setting(item)
        print("")

    await client.delete_configuration_setting(
        key="MyKey",
    )
コード例 #3
0
 def from_connection_string(
         cls,
         connection_string,  # type: str
         **kwargs):
     return cls(
         AzureAppConfigurationClient.from_connection_string(
             connection_string, **kwargs))
コード例 #4
0
 def __init__(self, method_name):
     super(AppConfigurationClientTest, self).__init__(method_name)
     self.vcr.match_on = ["path", "method", "query"]
     if self.is_playback():
         connection_str = "Endpoint=https://fake_app_config.azconfig-test.io;Id=0-l4-s0:h5htBaY5Z1LwFz50bIQv;Secret=bgyvBgwsQIw0s8myrqJJI3nLrj81M/kzSgSuP4BBoVg="
     else:
         connection_str = os.getenv('APP_CONFIG_CONNECTION')
     app_config_client = AzureAppConfigurationClient.from_connection_string(connection_str)
     self.app_config_client = AzureAppConfigurationClientProxy(app_config_client)
コード例 #5
0
 def __init__(self, arguments):
     super().__init__(arguments)
     connection_string = self.get_from_env(
         "AZURE_APP_CONFIG_CONNECTION_STRING")
     self.key = "KEY"
     self.service_client = SyncAppConfigClient.from_connection_string(
         connection_string=connection_string)
     self.async_service_client = AsyncAppConfigClient.from_connection_string(
         connection_string=connection_string)
    async def test_mock_policies(self):
        from azure.core.pipeline.transport import HttpRequest, HttpResponse, AsyncHttpTransport
        from azure.core.pipeline.policies import RetryPolicy
        from azure.core.pipeline import AsyncPipeline

        class MockTransport(AsyncHttpTransport):
            def __init__(self):
                self._count = 0
                self.auth_headers = []

            async def __aexit__(self, exc_type, exc_val, exc_tb):
                pass

            async def close(self):
                pass

            async def open(self):
                pass

            async def send(
                    self, request, **kwargs
            ):  # type: (PipelineRequest, Any) -> PipelineResponse
                self._count += 1
                self.auth_headers.append(request.headers['Authorization'])
                response = HttpResponse(request, None)
                response.status_code = 429
                return response

        def new_method(self, request):
            request.http_request.headers["Authorization"] = uuid4()

        from azure.appconfiguration._azure_appconfiguration_requests import AppConfigRequestsCredentialsPolicy
        # Store the method to restore later
        temp = AppConfigRequestsCredentialsPolicy._signed_request
        AppConfigRequestsCredentialsPolicy._signed_request = new_method

        client = AzureAppConfigurationClient.from_connection_string(
            os.environ["APPCONFIGURATION_CONNECTION_STRING"],
            transport=MockTransport())
        client.list_configuration_settings()

        # http_request = HttpRequest('GET', 'http://aka.ms/')
        # transport = MockTransport()

        # policies = client._impl._client._pipeline._impl_policies
        # pipeline = AsyncPipeline(transport, policies)
        # await pipeline.run(http_request)

        # Reset the actual method
        AppConfigRequestsCredentialsPolicy._signed_request = temp
コード例 #7
0
    def wrapper(*args, **kwargs):
        appconfiguration_connection_string = kwargs.pop(
            "appconfiguration_connection_string")
        client = AzureAppConfigurationClient.from_connection_string(
            appconfiguration_connection_string)
        client = AzureAppConfigurationClientProxy(client)

        kwargs['client'] = client
        kwargs[
            'appconfiguration_connection_string'] = appconfiguration_connection_string

        # Do setUp on client
        test_config_setting = _add_for_test(
            client,
            ConfigurationSetting(
                key=KEY,
                label=LABEL,
                value=TEST_VALUE,
                content_type=TEST_CONTENT_TYPE,
                tags={
                    "tag1": "tag1",
                    "tag2": "tag2"
                },
            ))
        test_config_setting_no_label = _add_for_test(
            client,
            ConfigurationSetting(
                key=KEY,
                label=None,
                value=TEST_VALUE,
                content_type=TEST_CONTENT_TYPE,
                tags={
                    "tag1": "tag1",
                    "tag2": "tag2"
                },
            ))
        to_delete = [test_config_setting, test_config_setting_no_label]

        kwargs['test_config_setting'] = test_config_setting
        kwargs['test_config_setting_no_label'] = test_config_setting_no_label

        trimmed_kwargs = {k: v for k, v in kwargs.items()}
        trim_kwargs_from_test_function(func, trimmed_kwargs)

        func(*args, **trimmed_kwargs)

        # do tearDown on client
        for item in to_delete:
            client.delete_configuration_setting(key=item.key, label=item.label)
コード例 #8
0
async def handle_event_grid_notifications(event_grid_events):
    # type: (List[dict[str, Any]]) -> None
    CONNECTION_STRING = get_connection_string()

    all_keys = []

    async with AzureAppConfigurationClient.from_connection_string(
            CONNECTION_STRING) as client:
        for event_grid_event in event_grid_events:
            if event_grid_event["eventType"] == 'Microsoft.KeyValueModified':
                sync_token = event_grid_event['data']['syncToken']
                client.update_sync_token(sync_token)

                new_key = await client.get_configuration_setting(
                    key=event_grid_event['data']['key'],
                    label=event_grid_event['data']['label'])

                all_keys.append(new_key)
async def main():
    CONNECTION_STRING = get_connection_string()

    # Create app config client
    client = AzureAppConfigurationClient.from_connection_string(
        CONNECTION_STRING)

    # Unconditional set
    config_setting = ConfigurationSetting(key="MyKey",
                                          value="my value",
                                          content_type="my content type",
                                          tags={"my tag": "my tag value"})
    await client.set_configuration_setting(config_setting)

    # Unconditional get
    first_get = await client.get_configuration_setting(key="MyKey")
    print_configuration_setting(first_get)

    # Conditional get, expect to return None because it is not modified
    second_get = await client.get_configuration_setting(
        key="MyKey",
        etag=first_get.etag,
        match_condition=MatchConditions.IfModified)
    print_configuration_setting(second_get)

    # Conditional set
    first_get.value = "new value"
    await client.set_configuration_setting(
        configuration_setting=first_get,
        match_condition=MatchConditions.IfNotModified)

    # Conditional set, expect to see error because it is modified
    try:
        await client.set_configuration_setting(
            configuration_setting=first_get,
            match_condition=MatchConditions.IfNotModified)
    except ResourceModifiedError:
        pass

    await client.delete_configuration_setting(key="MyKey")
コード例 #10
0
async def main():
    CONNECTION_STRING = get_connection_string()

    # Create app config client
    client = AzureAppConfigurationClient.from_connection_string(
        CONNECTION_STRING)

    print("Add new configuration setting")
    config_setting = ConfigurationSetting(key="MyKey",
                                          label="MyLabel",
                                          value="my value",
                                          content_type="my content type",
                                          tags={"my tag": "my tag value"})
    added_config_setting = await client.add_configuration_setting(
        config_setting)
    print("New configuration setting:")
    print_configuration_setting(added_config_setting)
    print("")

    print("Set configuration setting")
    added_config_setting.value = "new value"
    added_config_setting.content_type = "new content type"
    updated_config_setting = await client.set_configuration_setting(
        config_setting)
    print_configuration_setting(updated_config_setting)
    print("")

    print("List configuration settings")
    config_settings = client.list_configuration_settings(
        label_filter="MyLabel")
    async for item in config_settings:
        print_configuration_setting(item)

    print("Delete configuration setting")
    await client.delete_configuration_setting(
        key="MyKey",
        label="MyLabel",
    )