prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  tools/c7n-org - azure subscription generation includes disabled subscriptions
  
  per report on gitter.
  
  ngibbondaimler - We used azuresubs.py from c7n-org to generate a list of our subscriptions, however it's picking up disabled subscriptions and c7n-org throws an exception when it tries to read from a disabled sub to apply policy. Is there a suggested workaround for this?
  
  
  Stefan Gordon -
  I believe the return from the subscription API list call includes a state attribute, something like "state": "Enabled" - So for your scenario perhaps you can just add a check on that value at https://github.com/cloud-custodian/cloud-custodian/blob/master/tools/c7n_org/scripts/azuresubs.py#L34
  Additionally if you can file an issue with the error you are getting in c7n-org I would say that we should update it to handle this error properly. Generating a list without those is an easy workaround but it shouldn't fail on them.
  
  
  --- 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_org/scripts/azuresubs.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 click
  16 from c7n_azure.session import Session
  17 from c7n.utils import yaml_dump
  18 from azure.mgmt.resource.subscriptions import SubscriptionClient
  19 
  20 
  21 @click.command()
  22 @click.option(
  23     '-f', '--output', type=click.File('w'),
  24     help="File to store the generated config (default stdout)")
  25 def main(output):
  26     """
  27     Generate a c7n-org subscriptions config file
  28     """
  29 
  30     client = SubscriptionClient(Session().get_credentials())
  31     subs = [sub.serialize(True) for sub in client.subscriptions.list()]
  32     results = []
  33     for sub in subs:
  34         sub_info = {
  35             'subscription_id': sub['subscriptionId'],
  36             'name': sub['displayName']
  37         }
  38         results.append(sub_info)
  39 
  40     print(yaml_dump({'subscriptions': results}), file=output)
  41 
  42 
  43 if __name__ == '__main__':
  44     main()
  45
  ```
  --- 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()
  
  ```
  
golden_diff: diff --git a/tools/c7n_org/scripts/azuresubs.py b/tools/c7n_org/scripts/azuresubs.py
  --- a/tools/c7n_org/scripts/azuresubs.py
  +++ b/tools/c7n_org/scripts/azuresubs.py
  @@ -22,7 +22,12 @@
   @click.option(
       '-f', '--output', type=click.File('w'),
       help="File to store the generated config (default stdout)")
  -def main(output):
  +@click.option(
  +    '-s', '--state', multiple=True, type=click.Choice(
  +        ['Enabled', 'Warned', 'PastDue', 'Disabled', 'Deleted']),
  +    default=('Enabled',),
  +    help="File to store the generated config (default stdout)")
  +def main(output, state):
       """
       Generate a c7n-org subscriptions config file
       """
  @@ -31,6 +36,8 @@
       subs = [sub.serialize(True) for sub in client.subscriptions.list()]
       results = []
       for sub in subs:
  +        if state and sub['state'] not in state:
  +            continue
           sub_info = {
               'subscription_id': sub['subscriptionId'],
               'name': sub['displayName']
  
verification_info: {"golden_diff": "diff --git a/tools/c7n_org/scripts/azuresubs.py b/tools/c7n_org/scripts/azuresubs.py\n--- a/tools/c7n_org/scripts/azuresubs.py\n+++ b/tools/c7n_org/scripts/azuresubs.py\n@@ -22,7 +22,12 @@\n @click.option(\n     '-f', '--output', type=click.File('w'),\n     help=\"File to store the generated config (default stdout)\")\n-def main(output):\n+@click.option(\n+    '-s', '--state', multiple=True, type=click.Choice(\n+        ['Enabled', 'Warned', 'PastDue', 'Disabled', 'Deleted']),\n+    default=('Enabled',),\n+    help=\"File to store the generated config (default stdout)\")\n+def main(output, state):\n     \"\"\"\n     Generate a c7n-org subscriptions config file\n     \"\"\"\n@@ -31,6 +36,8 @@\n     subs = [sub.serialize(True) for sub in client.subscriptions.list()]\n     results = []\n     for sub in subs:\n+        if state and sub['state'] not in state:\n+            continue\n         sub_info = {\n             'subscription_id': sub['subscriptionId'],\n             'name': sub['displayName']\n", "issue": "tools/c7n-org - azure subscription generation includes disabled subscriptions\n\r\nper report on gitter.\r\n\r\nngibbondaimler - We used azuresubs.py from c7n-org to generate a list of our subscriptions, however it's picking up disabled subscriptions and c7n-org throws an exception when it tries to read from a disabled sub to apply policy. Is there a suggested workaround for this?\r\n\r\n\r\nStefan Gordon -\r\nI believe the return from the subscription API list call includes a state attribute, something like \"state\": \"Enabled\" - So for your scenario perhaps you can just add a check on that value at https://github.com/cloud-custodian/cloud-custodian/blob/master/tools/c7n_org/scripts/azuresubs.py#L34\r\nAdditionally if you can file an issue with the error you are getting in c7n-org I would say that we should update it to handle this error properly. Generating a list without those is an easy workaround but it shouldn't fail on them.\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 click\nfrom c7n_azure.session import Session\nfrom c7n.utils import yaml_dump\nfrom azure.mgmt.resource.subscriptions import SubscriptionClient\n\n\n@click.command()\n@click.option(\n    '-f', '--output', type=click.File('w'),\n    help=\"File to store the generated config (default stdout)\")\ndef main(output):\n    \"\"\"\n    Generate a c7n-org subscriptions config file\n    \"\"\"\n\n    client = SubscriptionClient(Session().get_credentials())\n    subs = [sub.serialize(True) for sub in client.subscriptions.list()]\n    results = []\n    for sub in subs:\n        sub_info = {\n            'subscription_id': sub['subscriptionId'],\n            'name': sub['displayName']\n        }\n        results.append(sub_info)\n\n    print(yaml_dump({'subscriptions': results}), file=output)\n\n\nif __name__ == '__main__':\n    main()\n", "path": "tools/c7n_org/scripts/azuresubs.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 click\nfrom c7n_azure.session import Session\nfrom c7n.utils import yaml_dump\nfrom azure.mgmt.resource.subscriptions import SubscriptionClient\n\n\n@click.command()\n@click.option(\n    '-f', '--output', type=click.File('w'),\n    help=\"File to store the generated config (default stdout)\")\n@click.option(\n    '-s', '--state', multiple=True, type=click.Choice(\n        ['Enabled', 'Warned', 'PastDue', 'Disabled', 'Deleted']),\n    default=('Enabled',),\n    help=\"File to store the generated config (default stdout)\")\ndef main(output, state):\n    \"\"\"\n    Generate a c7n-org subscriptions config file\n    \"\"\"\n\n    client = SubscriptionClient(Session().get_credentials())\n    subs = [sub.serialize(True) for sub in client.subscriptions.list()]\n    results = []\n    for sub in subs:\n        if state and sub['state'] not in state:\n            continue\n        sub_info = {\n            'subscription_id': sub['subscriptionId'],\n            'name': sub['displayName']\n        }\n        results.append(sub_info)\n\n    print(yaml_dump({'subscriptions': results}), file=output)\n\n\nif __name__ == '__main__':\n    main()\n", "path": "tools/c7n_org/scripts/azuresubs.py"}]}