Skip to content

Commit fc72e93

Browse files
authored
chore(migration): Migrate code from googleapis/google-auth-library-python into packages/google-auth (googleapis#16011)
See googleapis#14908. This PR should be merged with a merge-commit, not a squash-commit, in order to preserve the git history.
2 parents 258de5d + 23ad4c8 commit fc72e93

File tree

287 files changed

+62673
-45
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

287 files changed

+62673
-45
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ coverage.xml
5757
*sponge_log.xml
5858

5959
# System test environment variables.
60-
system_tests/local_test_setup
60+
**/system_tests/local_test_setup
61+
**/system_tests/data
6162

6263
# Make sure a generated file isn't accidentally committed.
6364
pylintrc

.kokoro/system-single.sh

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,14 @@ pwd
2222

2323
# If NOX_SESSION is set, it only runs the specified session,
2424
# otherwise run all the sessions.
25-
SESSION_ARG=""
25+
NOX_SESSION_ARG=""
2626

27-
[[ -z "${NOX_SESSION}" ]] || SESSION_ARG="-s ${NOX_SESSION}"
28-
python3 -m nox ${SESSION_ARG}
27+
# IF NOX_FILE is set, it runs the specific nox file,
28+
# otherwise it runs noxfile.py in the package directory.
29+
NOX_FILE_ARG=""
30+
31+
[[ -z "${NOX_SESSION}" ]] || NOX_SESSION_ARG="-s ${NOX_SESSION}"
32+
33+
[[ -z "${NOX_FILE}" ]] || NOX_FILE_ARG="-f ${NOX_FILE}"
34+
35+
python3 -m nox ${NOX_SESSION_ARG} $NOX_FILE_ARG

.kokoro/system.sh

Lines changed: 77 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -24,26 +24,69 @@ export PYTHONUNBUFFERED=1
2424
# Setup firestore account credentials
2525
export FIRESTORE_APPLICATION_CREDENTIALS=${KOKORO_GFILE_DIR}/firebase-credentials.json
2626

27-
# Setup service account credentials.
28-
export GOOGLE_APPLICATION_CREDENTIALS=${KOKORO_GFILE_DIR}/service-account.json
29-
30-
# Setup project id.
31-
export PROJECT_ID=$(cat "${KOKORO_GFILE_DIR}/project-id.json")
32-
33-
RETVAL=0
34-
3527
export PROJECT_ROOT=$(realpath $(dirname "${BASH_SOURCE[0]}")/..)
3628

3729
cd "$PROJECT_ROOT"
3830

39-
pwd
40-
41-
# A file for running system tests
42-
system_test_script="${PROJECT_ROOT}/.kokoro/system-single.sh"
43-
4431
# This is needed in order for `git diff` to succeed
4532
git config --global --add safe.directory $(realpath .)
4633

34+
RETVAL=0
35+
36+
pwd
37+
38+
run_package_test() {
39+
local package_name=$1
40+
local package_path="packages/${package_name}"
41+
42+
# Declare local overrides to prevent bleeding into the next loop iteration
43+
local PROJECT_ID
44+
local GOOGLE_APPLICATION_CREDENTIALS
45+
local NOX_FILE
46+
local NOX_SESSION
47+
48+
echo "------------------------------------------------------------"
49+
echo "Configuring environment for: ${package_name}"
50+
echo "------------------------------------------------------------"
51+
52+
case "${package_name}" in
53+
"google-auth")
54+
# Copy files needed for google-auth system tests
55+
mkdir -p "${package_path}/system_tests/data"
56+
cp "${KOKORO_GFILE_DIR}/google-auth-service-account.json" "${package_path}/system_tests/data/service_account.json"
57+
cp "${KOKORO_GFILE_DIR}/google-auth-authorized-user.json" "${package_path}/system_tests/data/authorized_user.json"
58+
cp "${KOKORO_GFILE_DIR}/google-auth-impersonated-service-account.json" "${package_path}/system_tests/data/impersonated_service_account.json"
59+
60+
PROJECT_ID=$(cat "${KOKORO_GFILE_DIR}/google-auth-project-id.json")
61+
GOOGLE_APPLICATION_CREDENTIALS="${KOKORO_GFILE_DIR}/google-auth-service-account.json"
62+
NOX_FILE="system_tests/noxfile.py"
63+
NOX_SESSION=""
64+
;;
65+
*)
66+
PROJECT_ID=$(cat "${KOKORO_GFILE_DIR}/project-id.json")
67+
GOOGLE_APPLICATION_CREDENTIALS="${KOKORO_GFILE_DIR}/service-account.json"
68+
NOX_FILE="noxfile.py"
69+
NOX_SESSION="system-3.12"
70+
;;
71+
esac
72+
73+
# Export variables for the duration of this function's sub-processes
74+
export PROJECT_ID GOOGLE_APPLICATION_CREDENTIALS NOX_FILE NOX_SESSION
75+
76+
gcloud auth activate-service-account --key-file="$GOOGLE_APPLICATION_CREDENTIALS"
77+
gcloud config set project "$PROJECT_ID"
78+
79+
# Run the actual test
80+
pushd "${package_path}" > /dev/null
81+
set +e
82+
"${system_test_script}"
83+
local res=$?
84+
set -e
85+
popd > /dev/null
86+
87+
return $res
88+
}
89+
4790
packages_with_system_tests=(
4891
"google-auth"
4992
"google-cloud-bigquery-storage"
@@ -56,42 +99,38 @@ packages_with_system_tests=(
5699
"google-cloud-testutils"
57100
)
58101

102+
# A file for running system tests
103+
system_test_script="${PROJECT_ROOT}/.kokoro/system-single.sh"
104+
59105
# Join array elements with | for the pattern match
60106
packages_with_system_tests_pattern=$(printf "|*%s*" "${packages_with_system_tests[@]}")
61107
packages_with_system_tests_pattern="${packages_with_system_tests_pattern:1}" # Remove the leading pipe
62108

63-
64-
# Run system tests for each package with directory packages/*/tests/system
65-
for dir in `find 'packages' -type d -wholename 'packages/*/tests/system'`; do
66-
# Get the path to the package by removing the suffix /tests/system
67-
package=$(echo $dir | cut -f -2 -d '/')
68-
69-
# Run system tests on every change to these libraries
70-
if [[ $package == @($packages_with_system_tests_pattern) ]]; then
71-
files_to_check=${package}
72-
else
73-
files_to_check=${package}/CHANGELOG.md
109+
# Run system tests for each package with directory `packages/*/tests/system` or directory `packages/*/system_tests`
110+
for dir in `find 'packages' -type d -wholename 'packages/*/tests/system' -o -wholename 'packages/*/system_tests'`; do
111+
# Extract the package name and define the relative package path
112+
# 1. Remove the 'packages/' prefix from the start
113+
# 2. Remove everything after the first '/' remaining
114+
package_name=${dir#packages/}
115+
package_name=${package_name%%/*}
116+
package_path="packages/${package_name}"
117+
118+
# Determine if we should skip based on git diff
119+
files_to_check="${package_path}/CHANGELOG.md"
120+
if [[ $package_name == @($packages_with_system_tests_pattern) ]]; then
121+
files_to_check="${package_path}"
74122
fi
75123

76124
echo "checking changes with 'git diff "${KOKORO_GITHUB_PULL_REQUEST_TARGET_BRANCH}...${KOKORO_GITHUB_PULL_REQUEST_COMMIT}" -- ${files_to_check}'"
77125
set +e
78126
package_modified=$(git diff "${KOKORO_GITHUB_PULL_REQUEST_TARGET_BRANCH}...${KOKORO_GITHUB_PULL_REQUEST_COMMIT}" -- ${files_to_check} | wc -l)
79127
set -e
80-
if [[ "${package_modified}" -eq 0 ]]; then
81-
echo "no change detected in ${files_to_check}, skipping"
128+
129+
if [[ "${package_modified}" -gt 0 ]]; then
130+
# Call the function - its internal exports won't affect the next loop
131+
run_package_test "$package_name" || RETVAL=$?
82132
else
83-
echo "change detected in ${files_to_check}"
84-
echo "Running system tests for ${package}"
85-
pushd ${package}
86-
# Temporarily allow failure.
87-
set +e
88-
${system_test_script}
89-
ret=$?
90-
set -e
91-
if [ ${ret} -ne 0 ]; then
92-
RETVAL=${ret}
93-
fi
94-
popd
133+
echo "No changes in ${package_name}, skipping."
95134
fi
96135
done
97136
exit ${RETVAL}

.librarian/state.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,15 @@ libraries:
213213
remove_regex:
214214
- packages/google-area120-tables/
215215
tag_format: '{id}-v{version}'
216+
- id: google-auth
217+
version: 2.48.0
218+
last_generated_commit: ""
219+
apis: []
220+
source_roots:
221+
- packages/google-auth
222+
preserve_regex: []
223+
remove_regex: []
224+
tag_format: '{id}-v{version}'
216225
- id: google-auth-httplib2
217226
version: 0.3.0
218227
last_generated_commit: ""

packages/google-auth/.coveragerc

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
[run]
2+
branch = True
3+
4+
[report]
5+
omit =
6+
*/samples/*
7+
*/conftest.py
8+
*/google-cloud-sdk/lib/*
9+
# NOTE: Temporarily disabling coverage for `_requests_base.py`.
10+
*/_requests_base.py
11+
exclude_lines =
12+
# Re-enable the standard pragma
13+
pragma: NO COVER
14+
# Ignore debug-only repr
15+
def __repr__
16+
# Don't complain if tests don't hit defensive assertion code:
17+
raise NotImplementedError

packages/google-auth/.flake8

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[flake8]
2+
ignore = E203, E266, E501, W503
3+
exclude =
4+
# Standard linting exemptions.
5+
__pycache__,
6+
.git,
7+
*.pyc,
8+
conf.py
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Read the Docs configuration file
2+
# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details
3+
4+
# Required
5+
version: 2
6+
7+
# Set the OS, Python version, and other tools you might need
8+
build:
9+
os: ubuntu-24.04
10+
tools:
11+
python: "3.10"
12+
13+
# Build documentation in the "docs/" directory with Sphinx
14+
sphinx:
15+
configuration: docs/conf.py
16+
17+
python:
18+
install:
19+
- requirements: docs/requirements-docs.txt
20+
# Install our python package before building the docs
21+
- method: pip
22+
path: .
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"name": "google-auth",
3+
"name_pretty": "Google Auth Python Library",
4+
"client_documentation": "https://googleapis.dev/python/google-auth/latest",
5+
"issue_tracker": "https://github.com/googleapis/google-auth-library-python/issues",
6+
"release_level": "stable",
7+
"language": "python",
8+
"library_type": "AUTH",
9+
"repo": "googleapis/google-auth-library-python",
10+
"distribution_name": "google-auth"
11+
}

0 commit comments

Comments
 (0)