Skip to content

Commit 47ab0ca

Browse files
authored
Move help message to the google auth code (#29888)
The "google-auth" 2.16.2 just released, removed the _HELP_MESSAGE that was imported by google provider auth util thus failing the imports in canary builds of ours attempting to upgrade to newver versions of released libraries. This PR inlines the original help message into our code to make it independent from google-auth package version used.
1 parent 76d8aaa commit 47ab0ca

File tree

4 files changed

+128
-8
lines changed

4 files changed

+128
-8
lines changed
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
From dd2f3d76c32ed12d56ae18b8ecb7086a8d9b1180 Mon Sep 17 00:00:00 2001
2+
From: Igor Kholopov <kholopovus@gmail.com>
3+
Date: Thu, 1 Dec 2022 18:34:30 +1100
4+
Subject: [PATCH 01/15] =?UTF-8?q?Refactor=20=E2=80=98=5Fget=5Fcandidate=5F?=
5+
=?UTF-8?q?file=5Fdescriptor=5Franges=E2=80=99=20to=20use=20=E2=80=98range?=
6+
=?UTF-8?q?=E2=80=99=20objects.?=
7+
MIME-Version: 1.0
8+
Content-Type: text/plain; charset=UTF-8
9+
Content-Transfer-Encoding: 8bit
10+
11+
This avoids the requirement for a concrete set of all the actual file
12+
descriptors. When the range is very large, this can greatly improve the memory
13+
requirements and execution time of this function.
14+
---
15+
daemon/daemon.py | 43 ++++++++++++++++++++++---------------------
16+
1 file changed, 22 insertions(+), 21 deletions(-)
17+
18+
diff --git a/daemon/daemon.py b/daemon/daemon.py
19+
index 08245a4..d1673be 100644
20+
--- a/daemon/daemon.py
21+
+++ b/daemon/daemon.py
22+
@@ -921,29 +921,30 @@ def _get_candidate_file_descriptor_ranges(exclude):
23+
in this process, excluding those integers in the `exclude`
24+
collection.
25+
"""
26+
- candidates_list = sorted(_get_candidate_file_descriptors(exclude))
27+
+ _validate_fd_values(exclude)
28+
ranges = []
29+
30+
- def append_range_if_needed(candidate_range):
31+
- (low, high) = candidate_range
32+
- if (low < high):
33+
- # The range is not empty.
34+
- ranges.append(candidate_range)
35+
-
36+
- this_range = (
37+
- (min(candidates_list), (min(candidates_list) + 1))
38+
- if candidates_list else (0, 0))
39+
- for fd in candidates_list[1:]:
40+
- high = fd + 1
41+
- if this_range[1] == fd:
42+
- # This file descriptor extends the current range.
43+
- this_range = (this_range[0], high)
44+
- else:
45+
- # The previous range has ended at a gap.
46+
- append_range_if_needed(this_range)
47+
- # This file descriptor begins a new range.
48+
- this_range = (fd, high)
49+
- append_range_if_needed(this_range)
50+
+ remaining_range = _total_file_descriptor_range
51+
+ for exclude_fd in sorted(exclude):
52+
+ if (exclude_fd > remaining_range.stop):
53+
+ # This and all later exclusions are higher than the remaining
54+
+ # range.
55+
+ break
56+
+ if (exclude_fd < remaining_range.start):
57+
+ # The remaining range does not include the current exclusion.
58+
+ continue
59+
+ if (exclude_fd != remaining_range.start):
60+
+ # There is a candidate range below the current exclusion.
61+
+ ranges.append((remaining_range.start, exclude_fd))
62+
+ # Narrow the remaining range to those above the current exclusion.
63+
+ remaining_range = range(exclude_fd + 1, remaining_range.stop)
64+
+
65+
+ if (remaining_range.start < remaining_range.stop):
66+
+ # After excluding all the specified file descriptors, there is a
67+
+ # remaining range; append it as a candidate for closing file
68+
+ # descriptors.
69+
+ ranges.append((remaining_range.start, remaining_range.stop))
70+
+
71+
return ranges
72+
73+
74+
--
75+
2.34.1
76+

airflow/_vendor/daemon/module.mk

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# daemon/module.mk
2+
# Part of ‘python-daemon’, an implementation of PEP 3143.
3+
#
4+
# This is free software, and you are welcome to redistribute it under
5+
# certain conditions; see the end of this file for copyright
6+
# information, grant of license, and disclaimer of warranty.
7+
8+
# Makefile module for ‘daemon’ Python package.
9+
10+
MODULE_DIR := $(CURDIR)/daemon
11+
12+
CODE_MODULES += $(shell find ${MODULE_DIR}/ -name '*.py')
13+
14+
15+
# Copyright © 2006–2023 Ben Finney <ben+python@benfinney.id.au>
16+
#
17+
# This is free software: you may copy, modify, and/or distribute this work
18+
# under the terms of the GNU General Public License as published by the
19+
# Free Software Foundation; version 3 of that license or any later version.
20+
# No warranty expressed or implied. See the file ‘LICENSE.GPL-3’ for details.
21+
22+
23+
# Local Variables:
24+
# mode: makefile
25+
# coding: utf-8
26+
# End:
27+
# vim: fileencoding=utf-8 filetype=make :

airflow/providers/google/common/utils/id_token_credentials.py

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,26 @@
3636
import google.auth.transport
3737
import google.oauth2
3838
from google.auth import credentials as google_auth_credentials, environment_vars, exceptions
39-
from google.auth._default import _AUTHORIZED_USER_TYPE, _HELP_MESSAGE, _SERVICE_ACCOUNT_TYPE, _VALID_TYPES
4039
from google.oauth2 import credentials as oauth2_credentials, service_account
4140

41+
# Valid types accepted for file-based credentials.
42+
# They are taken from "google.auth._default" and since they are all "protected" and the imports might
43+
# change any time and fail the whole Google provider functionality - we should inline them
44+
_AUTHORIZED_USER_TYPE = "authorized_user"
45+
_SERVICE_ACCOUNT_TYPE = "service_account"
46+
_EXTERNAL_ACCOUNT_TYPE = "external_account"
47+
_EXTERNAL_ACCOUNT_AUTHORIZED_USER_TYPE = "external_account_authorized_user"
48+
_IMPERSONATED_SERVICE_ACCOUNT_TYPE = "impersonated_service_account"
49+
_GDCH_SERVICE_ACCOUNT_TYPE = "gdch_service_account"
50+
_VALID_TYPES = (
51+
_AUTHORIZED_USER_TYPE,
52+
_SERVICE_ACCOUNT_TYPE,
53+
_EXTERNAL_ACCOUNT_TYPE,
54+
_EXTERNAL_ACCOUNT_AUTHORIZED_USER_TYPE,
55+
_IMPERSONATED_SERVICE_ACCOUNT_TYPE,
56+
_GDCH_SERVICE_ACCOUNT_TYPE,
57+
)
58+
4259

4360
class IDTokenCredentialsAdapter(google_auth_credentials.Credentials):
4461
"""Convert Credentials with ``openid`` scope to IDTokenCredentials."""
@@ -198,7 +215,12 @@ def get_default_id_token_credentials(
198215
if current_credentials is not None:
199216
return current_credentials
200217

201-
raise exceptions.DefaultCredentialsError(_HELP_MESSAGE)
218+
raise exceptions.DefaultCredentialsError(
219+
f"""Could not automatically determine credentials. Please set {environment_vars.CREDENTIALS} or
220+
explicitly create credentials and re-run the application. For more information, please see
221+
https://cloud.google.com/docs/authentication/getting-started
222+
""".strip()
223+
)
202224

203225

204226
if __name__ == "__main__":

tests/providers/google/common/utils/test_id_token_credentials.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
import json
2020
import os
21-
import re
2221
from unittest import mock
2322

2423
import pytest
@@ -60,11 +59,7 @@ def test_should_raise_exception(self, mock_metadata_ping, mock_gcloud_sdk_path):
6059
del os.environ[CREDENTIALS]
6160
with pytest.raises(
6261
exceptions.DefaultCredentialsError,
63-
match=re.escape(
64-
"Could not automatically determine credentials. Please set GOOGLE_APPLICATION_CREDENTIALS "
65-
"or explicitly create credentials and re-run the application. For more information, please "
66-
"see https://cloud.google.com/docs/authentication/getting-started"
67-
),
62+
match="Please set GOOGLE_APPLICATION_CREDENTIALS",
6863
):
6964
get_default_id_token_credentials(target_audience="example.org")
7065

0 commit comments

Comments
 (0)