We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
azure - lower az log verbosity when running custodian commands without -v
currently, c7n_azure will log info about the session it's using with normal c7n commands and is much more verbose than what it used to be, moved the log level from info to debug so it's still accessible with the -v flag

```
$ custodian schema network-addr.filters.shield-enabled -v
2018-06-19 09:42:36,028: cli.azure.cli.core:DEBUG Current cloud config:
AzureCloud
2018-06-19 09:42:36,029: custodian.azure.session:DEBUG Creating session with Azure CLI Authentication
2018-06-19 09:42:36,029: custodian.azure.session:DEBUG Session using Subscription ID: xxxxxxxxxxxxxxxxxxxxxxxxxxx

Help
----

The most base type

Schema
------

{
    "additionalProperties": false,
    "required": [
        "type"
    ],
    "type": "object",
    "properties": {
        "state": {
            "type": "boolean"
        },
        "type": {
            "enum": [
                "shield-enabled"
            ]
        }
    }
}
```

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `tools/c7n_azure/c7n_azure/session.py`
Content:
```
1 # Copyright 2018 Capital One Services, LLC
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14 
15 import importlib
16 import os
17 import logging
18 from azure.cli.core.cloud import AZURE_PUBLIC_CLOUD
19 from azure.cli.core._profile import Profile
20 from azure.common.credentials import ServicePrincipalCredentials, BasicTokenAuthentication
21 from c7n_azure.utils import ResourceIdParser
22 
23 
24 class Session(object):
25 
26     def __init__(self, subscription_id=None):
27         """
28         Creates a session using available authentication type.
29 
30         Auth priority:
31         1. Token Auth
32         2. Tenant Auth
33         3. Azure CLI Auth
34 
35         :param subscription_id: If provided, overrides environment variables.
36         """
37 
38         self.log = logging.getLogger('custodian.azure.session')
39         self._provider_cache = {}
40 
41         tenant_auth_variables = [
42             'AZURE_TENANT_ID', 'AZURE_SUBSCRIPTION_ID',
43             'AZURE_CLIENT_ID', 'AZURE_CLIENT_SECRET'
44         ]
45         token_auth_variables = ['AZURE_ACCESS_TOKEN', 'AZURE_SUBSCRIPTION_ID']
46 
47         if all(k in os.environ for k in token_auth_variables):
48             # Token authentication
49             self.credentials = BasicTokenAuthentication(
50                 token={
51                     'access_token': os.environ['AZURE_ACCESS_TOKEN']
52                 })
53             self.subscription_id = os.environ['AZURE_SUBSCRIPTION_ID']
54             self.log.info("Creating session with Token Authentication")
55 
56         elif all(k in os.environ for k in tenant_auth_variables):
57             # Tenant (service principal) authentication
58             self.credentials = ServicePrincipalCredentials(
59                 client_id=os.environ['AZURE_CLIENT_ID'],
60                 secret=os.environ['AZURE_CLIENT_SECRET'],
61                 tenant=os.environ['AZURE_TENANT_ID']
62             )
63             self.subscription_id = os.environ['AZURE_SUBSCRIPTION_ID']
64             self.tenant_id = os.environ['AZURE_TENANT_ID']
65             self.log.info("Creating session with Service Principal Authentication")
66 
67         else:
68             # Azure CLI authentication
69             (self.credentials,
70              self.subscription_id,
71              self.tenant_id) = Profile().get_login_credentials(
72                 resource=AZURE_PUBLIC_CLOUD.endpoints.active_directory_resource_id)
73             self.log.info("Creating session with Azure CLI Authentication")
74 
75         # Let provided id parameter override everything else
76         if subscription_id is not None:
77             self.subscription_id = subscription_id
78 
79         self.log.info("Session using Subscription ID: %s" % self.subscription_id)
80 
81         if self.credentials is None:
82             self.log.error('Unable to locate credentials for Azure session.')
83 
84     def client(self, client):
85         service_name, client_name = client.rsplit('.', 1)
86         svc_module = importlib.import_module(service_name)
87         klass = getattr(svc_module, client_name)
88         return klass(self.credentials, self.subscription_id)
89 
90     def resource_api_version(self, resource_id):
91         """ latest non-preview api version for resource """
92 
93         namespace = ResourceIdParser.get_namespace(resource_id)
94         resource_type = ResourceIdParser.get_resource_type(resource_id)
95 
96         if resource_type in self._provider_cache:
97             return self._provider_cache[resource_type]
98 
99         resource_client = self.client('azure.mgmt.resource.ResourceManagementClient')
100         provider = resource_client.providers.get(namespace)
101 
102         rt = next((t for t in provider.resource_types
103             if t.resource_type == str(resource_type).split('/')[-1]), None)
104         if rt and rt.api_versions:
105             versions = [v for v in rt.api_versions if 'preview' not in v.lower()]
106             api_version = versions[0] if versions else rt.api_versions[0]
107             self._provider_cache[resource_type] = api_version
108             return api_version
109
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/tools/c7n_azure/c7n_azure/session.py b/tools/c7n_azure/c7n_azure/session.py
--- a/tools/c7n_azure/c7n_azure/session.py
+++ b/tools/c7n_azure/c7n_azure/session.py
@@ -24,6 +24,19 @@
 class Session(object):
 
     def __init__(self, subscription_id=None):
+        """
+        :param subscription_id: If provided overrides environment variables.
+
+        """
+
+        self.log = logging.getLogger('custodian.azure.session')
+        self._provider_cache = {}
+        self.subscription_id_override = subscription_id
+        self.credentials = None
+        self.subscription_id = None
+        self.tenant_id = None
+
+    def _initialize_session(self):
         """
         Creates a session using available authentication type.
 
@@ -32,11 +45,11 @@
         2. Tenant Auth
         3. Azure CLI Auth
 
-        :param subscription_id: If provided, overrides environment variables.
         """
 
-        self.log = logging.getLogger('custodian.azure.session')
-        self._provider_cache = {}
+        # Only run once
+        if self.credentials is not None:
+            return
 
         tenant_auth_variables = [
             'AZURE_TENANT_ID', 'AZURE_SUBSCRIPTION_ID',
@@ -73,8 +86,8 @@
             self.log.info("Creating session with Azure CLI Authentication")
 
         # Let provided id parameter override everything else
-        if subscription_id is not None:
-            self.subscription_id = subscription_id
+        if self.subscription_id_override is not None:
+            self.subscription_id = self.subscription_id_override
 
         self.log.info("Session using Subscription ID: %s" % self.subscription_id)
 
@@ -82,6 +95,7 @@
             self.log.error('Unable to locate credentials for Azure session.')
 
     def client(self, client):
+        self._initialize_session()
         service_name, client_name = client.rsplit('.', 1)
         svc_module = importlib.import_module(service_name)
         klass = getattr(svc_module, client_name)

{"golden_diff": "diff --git a/tools/c7n_azure/c7n_azure/session.py b/tools/c7n_azure/c7n_azure/session.py\n--- a/tools/c7n_azure/c7n_azure/session.py\n+++ b/tools/c7n_azure/c7n_azure/session.py\n@@ -24,6 +24,19 @@\n class Session(object):\n \n     def __init__(self, subscription_id=None):\n+        \"\"\"\n+        :param subscription_id: If provided overrides environment variables.\n+\n+        \"\"\"\n+\n+        self.log = logging.getLogger('custodian.azure.session')\n+        self._provider_cache = {}\n+        self.subscription_id_override = subscription_id\n+        self.credentials = None\n+        self.subscription_id = None\n+        self.tenant_id = None\n+\n+    def _initialize_session(self):\n         \"\"\"\n         Creates a session using available authentication type.\n \n@@ -32,11 +45,11 @@\n         2. Tenant Auth\n         3. Azure CLI Auth\n \n-        :param subscription_id: If provided, overrides environment variables.\n         \"\"\"\n \n-        self.log = logging.getLogger('custodian.azure.session')\n-        self._provider_cache = {}\n+        # Only run once\n+        if self.credentials is not None:\n+            return\n \n         tenant_auth_variables = [\n             'AZURE_TENANT_ID', 'AZURE_SUBSCRIPTION_ID',\n@@ -73,8 +86,8 @@\n             self.log.info(\"Creating session with Azure CLI Authentication\")\n \n         # Let provided id parameter override everything else\n-        if subscription_id is not None:\n-            self.subscription_id = subscription_id\n+        if self.subscription_id_override is not None:\n+            self.subscription_id = self.subscription_id_override\n \n         self.log.info(\"Session using Subscription ID: %s\" % self.subscription_id)\n \n@@ -82,6 +95,7 @@\n             self.log.error('Unable to locate credentials for Azure session.')\n \n     def client(self, client):\n+        self._initialize_session()\n         service_name, client_name = client.rsplit('.', 1)\n         svc_module = importlib.import_module(service_name)\n         klass = getattr(svc_module, client_name)\n", "issue": "azure - lower az log verbosity when running custodian commands without -v\ncurrently, c7n_azure will log info about the session it's using with normal c7n commands and is much more verbose than what it used to be, moved the log level from info to debug so it's still accessible with the -v flag\r\n\r\n```\r\n$ custodian schema network-addr.filters.shield-enabled -v\r\n2018-06-19 09:42:36,028: cli.azure.cli.core:DEBUG Current cloud config:\r\nAzureCloud\r\n2018-06-19 09:42:36,029: custodian.azure.session:DEBUG Creating session with Azure CLI Authentication\r\n2018-06-19 09:42:36,029: custodian.azure.session:DEBUG Session using Subscription ID: xxxxxxxxxxxxxxxxxxxxxxxxxxx\r\n\r\nHelp\r\n----\r\n\r\nThe most base type\r\n\r\nSchema\r\n------\r\n\r\n{\r\n    \"additionalProperties\": false,\r\n    \"required\": [\r\n        \"type\"\r\n    ],\r\n    \"type\": \"object\",\r\n    \"properties\": {\r\n        \"state\": {\r\n            \"type\": \"boolean\"\r\n        },\r\n        \"type\": {\r\n            \"enum\": [\r\n                \"shield-enabled\"\r\n            ]\r\n        }\r\n    }\r\n}\r\n```\n", "before_files": [{"content": "# Copyright 2018 Capital One Services, LLC\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport importlib\nimport os\nimport logging\nfrom azure.cli.core.cloud import AZURE_PUBLIC_CLOUD\nfrom azure.cli.core._profile import Profile\nfrom azure.common.credentials import ServicePrincipalCredentials, BasicTokenAuthentication\nfrom c7n_azure.utils import ResourceIdParser\n\n\nclass Session(object):\n\n    def __init__(self, subscription_id=None):\n        \"\"\"\n        Creates a session using available authentication type.\n\n        Auth priority:\n        1. Token Auth\n        2. Tenant Auth\n        3. Azure CLI Auth\n\n        :param subscription_id: If provided, overrides environment variables.\n        \"\"\"\n\n        self.log = logging.getLogger('custodian.azure.session')\n        self._provider_cache = {}\n\n        tenant_auth_variables = [\n            'AZURE_TENANT_ID', 'AZURE_SUBSCRIPTION_ID',\n            'AZURE_CLIENT_ID', 'AZURE_CLIENT_SECRET'\n        ]\n        token_auth_variables = ['AZURE_ACCESS_TOKEN', 'AZURE_SUBSCRIPTION_ID']\n\n        if all(k in os.environ for k in token_auth_variables):\n            # Token authentication\n            self.credentials = BasicTokenAuthentication(\n                token={\n                    'access_token': os.environ['AZURE_ACCESS_TOKEN']\n                })\n            self.subscription_id = os.environ['AZURE_SUBSCRIPTION_ID']\n            self.log.info(\"Creating session with Token Authentication\")\n\n        elif all(k in os.environ for k in tenant_auth_variables):\n            # Tenant (service principal) authentication\n            self.credentials = ServicePrincipalCredentials(\n                client_id=os.environ['AZURE_CLIENT_ID'],\n                secret=os.environ['AZURE_CLIENT_SECRET'],\n                tenant=os.environ['AZURE_TENANT_ID']\n            )\n            self.subscription_id = os.environ['AZURE_SUBSCRIPTION_ID']\n            self.tenant_id = os.environ['AZURE_TENANT_ID']\n            self.log.info(\"Creating session with Service Principal Authentication\")\n\n        else:\n            # Azure CLI authentication\n            (self.credentials,\n             self.subscription_id,\n             self.tenant_id) = Profile().get_login_credentials(\n                resource=AZURE_PUBLIC_CLOUD.endpoints.active_directory_resource_id)\n            self.log.info(\"Creating session with Azure CLI Authentication\")\n\n        # Let provided id parameter override everything else\n        if subscription_id is not None:\n            self.subscription_id = subscription_id\n\n        self.log.info(\"Session using Subscription ID: %s\" % self.subscription_id)\n\n        if self.credentials is None:\n            self.log.error('Unable to locate credentials for Azure session.')\n\n    def client(self, client):\n        service_name, client_name = client.rsplit('.', 1)\n        svc_module = importlib.import_module(service_name)\n        klass = getattr(svc_module, client_name)\n        return klass(self.credentials, self.subscription_id)\n\n    def resource_api_version(self, resource_id):\n        \"\"\" latest non-preview api version for resource \"\"\"\n\n        namespace = ResourceIdParser.get_namespace(resource_id)\n        resource_type = ResourceIdParser.get_resource_type(resource_id)\n\n        if resource_type in self._provider_cache:\n            return self._provider_cache[resource_type]\n\n        resource_client = self.client('azure.mgmt.resource.ResourceManagementClient')\n        provider = resource_client.providers.get(namespace)\n\n        rt = next((t for t in provider.resource_types\n            if t.resource_type == str(resource_type).split('/')[-1]), None)\n        if rt and rt.api_versions:\n            versions = [v for v in rt.api_versions if 'preview' not in v.lower()]\n            api_version = versions[0] if versions else rt.api_versions[0]\n            self._provider_cache[resource_type] = api_version\n            return api_version\n", "path": "tools/c7n_azure/c7n_azure/session.py"}], "after_files": [{"content": "# Copyright 2018 Capital One Services, LLC\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport importlib\nimport os\nimport logging\nfrom azure.cli.core.cloud import AZURE_PUBLIC_CLOUD\nfrom azure.cli.core._profile import Profile\nfrom azure.common.credentials import ServicePrincipalCredentials, BasicTokenAuthentication\nfrom c7n_azure.utils import ResourceIdParser\n\n\nclass Session(object):\n\n    def __init__(self, subscription_id=None):\n        \"\"\"\n        :param subscription_id: If provided overrides environment variables.\n\n        \"\"\"\n\n        self.log = logging.getLogger('custodian.azure.session')\n        self._provider_cache = {}\n        self.subscription_id_override = subscription_id\n        self.credentials = None\n        self.subscription_id = None\n        self.tenant_id = None\n\n    def _initialize_session(self):\n        \"\"\"\n        Creates a session using available authentication type.\n\n        Auth priority:\n        1. Token Auth\n        2. Tenant Auth\n        3. Azure CLI Auth\n\n        \"\"\"\n\n        # Only run once\n        if self.credentials is not None:\n            return\n\n        tenant_auth_variables = [\n            'AZURE_TENANT_ID', 'AZURE_SUBSCRIPTION_ID',\n            'AZURE_CLIENT_ID', 'AZURE_CLIENT_SECRET'\n        ]\n        token_auth_variables = ['AZURE_ACCESS_TOKEN', 'AZURE_SUBSCRIPTION_ID']\n\n        if all(k in os.environ for k in token_auth_variables):\n            # Token authentication\n            self.credentials = BasicTokenAuthentication(\n                token={\n                    'access_token': os.environ['AZURE_ACCESS_TOKEN']\n                })\n            self.subscription_id = os.environ['AZURE_SUBSCRIPTION_ID']\n            self.log.info(\"Creating session with Token Authentication\")\n\n        elif all(k in os.environ for k in tenant_auth_variables):\n            # Tenant (service principal) authentication\n            self.credentials = ServicePrincipalCredentials(\n                client_id=os.environ['AZURE_CLIENT_ID'],\n                secret=os.environ['AZURE_CLIENT_SECRET'],\n                tenant=os.environ['AZURE_TENANT_ID']\n            )\n            self.subscription_id = os.environ['AZURE_SUBSCRIPTION_ID']\n            self.tenant_id = os.environ['AZURE_TENANT_ID']\n            self.log.info(\"Creating session with Service Principal Authentication\")\n\n        else:\n            # Azure CLI authentication\n            (self.credentials,\n             self.subscription_id,\n             self.tenant_id) = Profile().get_login_credentials(\n                resource=AZURE_PUBLIC_CLOUD.endpoints.active_directory_resource_id)\n            self.log.info(\"Creating session with Azure CLI Authentication\")\n\n        # Let provided id parameter override everything else\n        if self.subscription_id_override is not None:\n            self.subscription_id = self.subscription_id_override\n\n        self.log.info(\"Session using Subscription ID: %s\" % self.subscription_id)\n\n        if self.credentials is None:\n            self.log.error('Unable to locate credentials for Azure session.')\n\n    def client(self, client):\n        self._initialize_session()\n        service_name, client_name = client.rsplit('.', 1)\n        svc_module = importlib.import_module(service_name)\n        klass = getattr(svc_module, client_name)\n        return klass(self.credentials, self.subscription_id)\n\n    def resource_api_version(self, resource_id):\n        \"\"\" latest non-preview api version for resource \"\"\"\n\n        namespace = ResourceIdParser.get_namespace(resource_id)\n        resource_type = ResourceIdParser.get_resource_type(resource_id)\n\n        if resource_type in self._provider_cache:\n            return self._provider_cache[resource_type]\n\n        resource_client = self.client('azure.mgmt.resource.ResourceManagementClient')\n        provider = resource_client.providers.get(namespace)\n\n        rt = next((t for t in provider.resource_types\n            if t.resource_type == str(resource_type).split('/')[-1]), None)\n        if rt and rt.api_versions:\n            versions = [v for v in rt.api_versions if 'preview' not in v.lower()]\n            api_version = versions[0] if versions else rt.api_versions[0]\n            self._provider_cache[resource_type] = api_version\n            return api_version\n", "path": "tools/c7n_azure/c7n_azure/session.py"}]}