We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Cloud SDK credentials should use the 'active' config not the 'default' config
Context: https://github.com/GoogleCloudPlatform/google-cloud-python/issues/2588


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `google/auth/_cloud_sdk.py`
Content:
```
1 # Copyright 2015 Google Inc.
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 """Helpers for reading the Google Cloud SDK's configuration."""
16 
17 import os
18 
19 import six
20 from six.moves import configparser
21 
22 from google.auth import environment_vars
23 import google.oauth2.credentials
24 
25 # The Google OAuth 2.0 token endpoint. Used for authorized user credentials.
26 _GOOGLE_OAUTH2_TOKEN_ENDPOINT = 'https://accounts.google.com/o/oauth2/token'
27 
28 # The ~/.config subdirectory containing gcloud credentials.
29 _CONFIG_DIRECTORY = 'gcloud'
30 # Windows systems store config at %APPDATA%\gcloud
31 _WINDOWS_CONFIG_ROOT_ENV_VAR = 'APPDATA'
32 # The name of the file in the Cloud SDK config that contains default
33 # credentials.
34 _CREDENTIALS_FILENAME = 'application_default_credentials.json'
35 # The name of the file in the Cloud SDK config that contains the
36 # active configuration.
37 _ACTIVE_CONFIG_FILENAME = os.path.join(
38     'configurations', 'config_default')
39 # The config section and key for the project ID in the cloud SDK config.
40 _PROJECT_CONFIG_SECTION = 'core'
41 _PROJECT_CONFIG_KEY = 'project'
42 
43 
44 def get_config_path():
45     """Returns the absolute path the the Cloud SDK's configuration directory.
46 
47     Returns:
48         str: The Cloud SDK config path.
49     """
50     # If the path is explicitly set, return that.
51     try:
52         return os.environ[environment_vars.CLOUD_SDK_CONFIG_DIR]
53     except KeyError:
54         pass
55 
56     # Non-windows systems store this at ~/.config/gcloud
57     if os.name != 'nt':
58         return os.path.join(
59             os.path.expanduser('~'), '.config', _CONFIG_DIRECTORY)
60     # Windows systems store config at %APPDATA%\gcloud
61     else:
62         try:
63             return os.path.join(
64                 os.environ[_WINDOWS_CONFIG_ROOT_ENV_VAR],
65                 _CONFIG_DIRECTORY)
66         except KeyError:
67             # This should never happen unless someone is really
68             # messing with things, but we'll cover the case anyway.
69             drive = os.environ.get('SystemDrive', 'C:')
70             return os.path.join(
71                 drive, '\\', _CONFIG_DIRECTORY)
72 
73 
74 def get_application_default_credentials_path():
75     """Gets the path to the application default credentials file.
76 
77     The path may or may not exist.
78 
79     Returns:
80         str: The full path to application default credentials.
81     """
82     config_path = get_config_path()
83     return os.path.join(config_path, _CREDENTIALS_FILENAME)
84 
85 
86 def get_project_id():
87     """Gets the project ID from the Cloud SDK's configuration.
88 
89     Returns:
90         Optional[str]: The project ID.
91     """
92     config_path = get_config_path()
93     config_file = os.path.join(config_path, _ACTIVE_CONFIG_FILENAME)
94 
95     if not os.path.isfile(config_file):
96         return None
97 
98     config = configparser.RawConfigParser()
99 
100     try:
101         config.read(config_file)
102     except configparser.Error:
103         return None
104 
105     if config.has_section(_PROJECT_CONFIG_SECTION):
106         return config.get(
107             _PROJECT_CONFIG_SECTION, _PROJECT_CONFIG_KEY)
108 
109 
110 def load_authorized_user_credentials(info):
111     """Loads an authorized user credential.
112 
113     Args:
114         info (Mapping[str, str]): The loaded file's data.
115 
116     Returns:
117         google.oauth2.credentials.Credentials: The constructed credentials.
118 
119     Raises:
120         ValueError: if the info is in the wrong format or missing data.
121     """
122     keys_needed = set(('refresh_token', 'client_id', 'client_secret'))
123     missing = keys_needed.difference(six.iterkeys(info))
124 
125     if missing:
126         raise ValueError(
127             'Authorized user info was not in the expected format, missing '
128             'fields {}.'.format(', '.join(missing)))
129 
130     return google.oauth2.credentials.Credentials(
131         None,  # No access token, must be refreshed.
132         refresh_token=info['refresh_token'],
133         token_uri=_GOOGLE_OAUTH2_TOKEN_ENDPOINT,
134         client_id=info['client_id'],
135         client_secret=info['client_secret'])
136
```
--- 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/google/auth/_cloud_sdk.py b/google/auth/_cloud_sdk.py
--- a/google/auth/_cloud_sdk.py
+++ b/google/auth/_cloud_sdk.py
@@ -14,6 +14,7 @@
 
 """Helpers for reading the Google Cloud SDK's configuration."""
 
+import io
 import os
 
 import six
@@ -32,10 +33,6 @@
 # The name of the file in the Cloud SDK config that contains default
 # credentials.
 _CREDENTIALS_FILENAME = 'application_default_credentials.json'
-# The name of the file in the Cloud SDK config that contains the
-# active configuration.
-_ACTIVE_CONFIG_FILENAME = os.path.join(
-    'configurations', 'config_default')
 # The config section and key for the project ID in the cloud SDK config.
 _PROJECT_CONFIG_SECTION = 'core'
 _PROJECT_CONFIG_KEY = 'project'
@@ -83,6 +80,40 @@
     return os.path.join(config_path, _CREDENTIALS_FILENAME)
 
 
+def _get_active_config(config_path):
+    """Gets the active config for the Cloud SDK.
+
+    Args:
+        config_path (str): The Cloud SDK's config path.
+
+    Returns:
+        str: The active configuration name.
+    """
+    active_config_filename = os.path.join(config_path, 'active_config')
+
+    if not os.path.isfile(active_config_filename):
+        return 'default'
+
+    with io.open(active_config_filename, 'r', encoding='utf-8') as file_obj:
+        active_config_name = file_obj.read().strip()
+
+    return active_config_name
+
+
+def _get_config_file(config_path, config_name):
+    """Returns the full path to a configuration's config file.
+
+    Args:
+        config_path (str): The Cloud SDK's config path.
+        config_name (str): The configuration name.
+
+    Returns:
+        str: The config file path.
+    """
+    return os.path.join(
+        config_path, 'configurations', 'config_{}'.format(config_name))
+
+
 def get_project_id():
     """Gets the project ID from the Cloud SDK's configuration.
 
@@ -90,7 +121,8 @@
         Optional[str]: The project ID.
     """
     config_path = get_config_path()
-    config_file = os.path.join(config_path, _ACTIVE_CONFIG_FILENAME)
+    active_config = _get_active_config(config_path)
+    config_file = _get_config_file(config_path, active_config)
 
     if not os.path.isfile(config_file):
         return None

{"golden_diff": "diff --git a/google/auth/_cloud_sdk.py b/google/auth/_cloud_sdk.py\n--- a/google/auth/_cloud_sdk.py\n+++ b/google/auth/_cloud_sdk.py\n@@ -14,6 +14,7 @@\n \n \"\"\"Helpers for reading the Google Cloud SDK's configuration.\"\"\"\n \n+import io\n import os\n \n import six\n@@ -32,10 +33,6 @@\n # The name of the file in the Cloud SDK config that contains default\n # credentials.\n _CREDENTIALS_FILENAME = 'application_default_credentials.json'\n-# The name of the file in the Cloud SDK config that contains the\n-# active configuration.\n-_ACTIVE_CONFIG_FILENAME = os.path.join(\n-    'configurations', 'config_default')\n # The config section and key for the project ID in the cloud SDK config.\n _PROJECT_CONFIG_SECTION = 'core'\n _PROJECT_CONFIG_KEY = 'project'\n@@ -83,6 +80,40 @@\n     return os.path.join(config_path, _CREDENTIALS_FILENAME)\n \n \n+def _get_active_config(config_path):\n+    \"\"\"Gets the active config for the Cloud SDK.\n+\n+    Args:\n+        config_path (str): The Cloud SDK's config path.\n+\n+    Returns:\n+        str: The active configuration name.\n+    \"\"\"\n+    active_config_filename = os.path.join(config_path, 'active_config')\n+\n+    if not os.path.isfile(active_config_filename):\n+        return 'default'\n+\n+    with io.open(active_config_filename, 'r', encoding='utf-8') as file_obj:\n+        active_config_name = file_obj.read().strip()\n+\n+    return active_config_name\n+\n+\n+def _get_config_file(config_path, config_name):\n+    \"\"\"Returns the full path to a configuration's config file.\n+\n+    Args:\n+        config_path (str): The Cloud SDK's config path.\n+        config_name (str): The configuration name.\n+\n+    Returns:\n+        str: The config file path.\n+    \"\"\"\n+    return os.path.join(\n+        config_path, 'configurations', 'config_{}'.format(config_name))\n+\n+\n def get_project_id():\n     \"\"\"Gets the project ID from the Cloud SDK's configuration.\n \n@@ -90,7 +121,8 @@\n         Optional[str]: The project ID.\n     \"\"\"\n     config_path = get_config_path()\n-    config_file = os.path.join(config_path, _ACTIVE_CONFIG_FILENAME)\n+    active_config = _get_active_config(config_path)\n+    config_file = _get_config_file(config_path, active_config)\n \n     if not os.path.isfile(config_file):\n         return None\n", "issue": "Cloud SDK credentials should use the 'active' config not the 'default' config\nContext: https://github.com/GoogleCloudPlatform/google-cloud-python/issues/2588\n\n", "before_files": [{"content": "# Copyright 2015 Google Inc.\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\n\"\"\"Helpers for reading the Google Cloud SDK's configuration.\"\"\"\n\nimport os\n\nimport six\nfrom six.moves import configparser\n\nfrom google.auth import environment_vars\nimport google.oauth2.credentials\n\n# The Google OAuth 2.0 token endpoint. Used for authorized user credentials.\n_GOOGLE_OAUTH2_TOKEN_ENDPOINT = 'https://accounts.google.com/o/oauth2/token'\n\n# The ~/.config subdirectory containing gcloud credentials.\n_CONFIG_DIRECTORY = 'gcloud'\n# Windows systems store config at %APPDATA%\\gcloud\n_WINDOWS_CONFIG_ROOT_ENV_VAR = 'APPDATA'\n# The name of the file in the Cloud SDK config that contains default\n# credentials.\n_CREDENTIALS_FILENAME = 'application_default_credentials.json'\n# The name of the file in the Cloud SDK config that contains the\n# active configuration.\n_ACTIVE_CONFIG_FILENAME = os.path.join(\n    'configurations', 'config_default')\n# The config section and key for the project ID in the cloud SDK config.\n_PROJECT_CONFIG_SECTION = 'core'\n_PROJECT_CONFIG_KEY = 'project'\n\n\ndef get_config_path():\n    \"\"\"Returns the absolute path the the Cloud SDK's configuration directory.\n\n    Returns:\n        str: The Cloud SDK config path.\n    \"\"\"\n    # If the path is explicitly set, return that.\n    try:\n        return os.environ[environment_vars.CLOUD_SDK_CONFIG_DIR]\n    except KeyError:\n        pass\n\n    # Non-windows systems store this at ~/.config/gcloud\n    if os.name != 'nt':\n        return os.path.join(\n            os.path.expanduser('~'), '.config', _CONFIG_DIRECTORY)\n    # Windows systems store config at %APPDATA%\\gcloud\n    else:\n        try:\n            return os.path.join(\n                os.environ[_WINDOWS_CONFIG_ROOT_ENV_VAR],\n                _CONFIG_DIRECTORY)\n        except KeyError:\n            # This should never happen unless someone is really\n            # messing with things, but we'll cover the case anyway.\n            drive = os.environ.get('SystemDrive', 'C:')\n            return os.path.join(\n                drive, '\\\\', _CONFIG_DIRECTORY)\n\n\ndef get_application_default_credentials_path():\n    \"\"\"Gets the path to the application default credentials file.\n\n    The path may or may not exist.\n\n    Returns:\n        str: The full path to application default credentials.\n    \"\"\"\n    config_path = get_config_path()\n    return os.path.join(config_path, _CREDENTIALS_FILENAME)\n\n\ndef get_project_id():\n    \"\"\"Gets the project ID from the Cloud SDK's configuration.\n\n    Returns:\n        Optional[str]: The project ID.\n    \"\"\"\n    config_path = get_config_path()\n    config_file = os.path.join(config_path, _ACTIVE_CONFIG_FILENAME)\n\n    if not os.path.isfile(config_file):\n        return None\n\n    config = configparser.RawConfigParser()\n\n    try:\n        config.read(config_file)\n    except configparser.Error:\n        return None\n\n    if config.has_section(_PROJECT_CONFIG_SECTION):\n        return config.get(\n            _PROJECT_CONFIG_SECTION, _PROJECT_CONFIG_KEY)\n\n\ndef load_authorized_user_credentials(info):\n    \"\"\"Loads an authorized user credential.\n\n    Args:\n        info (Mapping[str, str]): The loaded file's data.\n\n    Returns:\n        google.oauth2.credentials.Credentials: The constructed credentials.\n\n    Raises:\n        ValueError: if the info is in the wrong format or missing data.\n    \"\"\"\n    keys_needed = set(('refresh_token', 'client_id', 'client_secret'))\n    missing = keys_needed.difference(six.iterkeys(info))\n\n    if missing:\n        raise ValueError(\n            'Authorized user info was not in the expected format, missing '\n            'fields {}.'.format(', '.join(missing)))\n\n    return google.oauth2.credentials.Credentials(\n        None,  # No access token, must be refreshed.\n        refresh_token=info['refresh_token'],\n        token_uri=_GOOGLE_OAUTH2_TOKEN_ENDPOINT,\n        client_id=info['client_id'],\n        client_secret=info['client_secret'])\n", "path": "google/auth/_cloud_sdk.py"}], "after_files": [{"content": "# Copyright 2015 Google Inc.\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\n\"\"\"Helpers for reading the Google Cloud SDK's configuration.\"\"\"\n\nimport io\nimport os\n\nimport six\nfrom six.moves import configparser\n\nfrom google.auth import environment_vars\nimport google.oauth2.credentials\n\n# The Google OAuth 2.0 token endpoint. Used for authorized user credentials.\n_GOOGLE_OAUTH2_TOKEN_ENDPOINT = 'https://accounts.google.com/o/oauth2/token'\n\n# The ~/.config subdirectory containing gcloud credentials.\n_CONFIG_DIRECTORY = 'gcloud'\n# Windows systems store config at %APPDATA%\\gcloud\n_WINDOWS_CONFIG_ROOT_ENV_VAR = 'APPDATA'\n# The name of the file in the Cloud SDK config that contains default\n# credentials.\n_CREDENTIALS_FILENAME = 'application_default_credentials.json'\n# The config section and key for the project ID in the cloud SDK config.\n_PROJECT_CONFIG_SECTION = 'core'\n_PROJECT_CONFIG_KEY = 'project'\n\n\ndef get_config_path():\n    \"\"\"Returns the absolute path the the Cloud SDK's configuration directory.\n\n    Returns:\n        str: The Cloud SDK config path.\n    \"\"\"\n    # If the path is explicitly set, return that.\n    try:\n        return os.environ[environment_vars.CLOUD_SDK_CONFIG_DIR]\n    except KeyError:\n        pass\n\n    # Non-windows systems store this at ~/.config/gcloud\n    if os.name != 'nt':\n        return os.path.join(\n            os.path.expanduser('~'), '.config', _CONFIG_DIRECTORY)\n    # Windows systems store config at %APPDATA%\\gcloud\n    else:\n        try:\n            return os.path.join(\n                os.environ[_WINDOWS_CONFIG_ROOT_ENV_VAR],\n                _CONFIG_DIRECTORY)\n        except KeyError:\n            # This should never happen unless someone is really\n            # messing with things, but we'll cover the case anyway.\n            drive = os.environ.get('SystemDrive', 'C:')\n            return os.path.join(\n                drive, '\\\\', _CONFIG_DIRECTORY)\n\n\ndef get_application_default_credentials_path():\n    \"\"\"Gets the path to the application default credentials file.\n\n    The path may or may not exist.\n\n    Returns:\n        str: The full path to application default credentials.\n    \"\"\"\n    config_path = get_config_path()\n    return os.path.join(config_path, _CREDENTIALS_FILENAME)\n\n\ndef _get_active_config(config_path):\n    \"\"\"Gets the active config for the Cloud SDK.\n\n    Args:\n        config_path (str): The Cloud SDK's config path.\n\n    Returns:\n        str: The active configuration name.\n    \"\"\"\n    active_config_filename = os.path.join(config_path, 'active_config')\n\n    if not os.path.isfile(active_config_filename):\n        return 'default'\n\n    with io.open(active_config_filename, 'r', encoding='utf-8') as file_obj:\n        active_config_name = file_obj.read().strip()\n\n    return active_config_name\n\n\ndef _get_config_file(config_path, config_name):\n    \"\"\"Returns the full path to a configuration's config file.\n\n    Args:\n        config_path (str): The Cloud SDK's config path.\n        config_name (str): The configuration name.\n\n    Returns:\n        str: The config file path.\n    \"\"\"\n    return os.path.join(\n        config_path, 'configurations', 'config_{}'.format(config_name))\n\n\ndef get_project_id():\n    \"\"\"Gets the project ID from the Cloud SDK's configuration.\n\n    Returns:\n        Optional[str]: The project ID.\n    \"\"\"\n    config_path = get_config_path()\n    active_config = _get_active_config(config_path)\n    config_file = _get_config_file(config_path, active_config)\n\n    if not os.path.isfile(config_file):\n        return None\n\n    config = configparser.RawConfigParser()\n\n    try:\n        config.read(config_file)\n    except configparser.Error:\n        return None\n\n    if config.has_section(_PROJECT_CONFIG_SECTION):\n        return config.get(\n            _PROJECT_CONFIG_SECTION, _PROJECT_CONFIG_KEY)\n\n\ndef load_authorized_user_credentials(info):\n    \"\"\"Loads an authorized user credential.\n\n    Args:\n        info (Mapping[str, str]): The loaded file's data.\n\n    Returns:\n        google.oauth2.credentials.Credentials: The constructed credentials.\n\n    Raises:\n        ValueError: if the info is in the wrong format or missing data.\n    \"\"\"\n    keys_needed = set(('refresh_token', 'client_id', 'client_secret'))\n    missing = keys_needed.difference(six.iterkeys(info))\n\n    if missing:\n        raise ValueError(\n            'Authorized user info was not in the expected format, missing '\n            'fields {}.'.format(', '.join(missing)))\n\n    return google.oauth2.credentials.Credentials(\n        None,  # No access token, must be refreshed.\n        refresh_token=info['refresh_token'],\n        token_uri=_GOOGLE_OAUTH2_TOKEN_ENDPOINT,\n        client_id=info['client_id'],\n        client_secret=info['client_secret'])\n", "path": "google/auth/_cloud_sdk.py"}]}