Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions .github/workflows/check-file-contents.yml
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,35 @@ jobs:
else
echo "✅ No relevant Python files found."
fi

- name: Check for hardcoded googleapis.com endpoints
run: |
git fetch origin ${GITHUB_BASE_REF}
CHANGED_FILES=$(git diff --diff-filter=ACMR --name-only origin/${GITHUB_BASE_REF}...HEAD | grep -E '\.py$' || true)
if [ -n "$CHANGED_FILES" ]; then
echo "Checking for hardcoded endpoints in: $CHANGED_FILES"

set +e
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The current logic grep -lE ... | grep -v '.mtls.googleapis.com' will not work as intended. grep -l returns a list of filenames, and the subsequent grep -v will only exclude the filename if it contains .mtls.googleapis.com, which is unlikely for a filename.

To catch any non-mTLS endpoint, you should probably do something like:
grep -rE 'https?://[a-zA-Z0-9.-]+\.googleapis\.com' $CHANGED_FILES | grep -v '.mtls.googleapis.com'
This will check the content of each line and only exclude lines that contain the .mtls. prefix.

FILES_WITH_HARDCODED_ENDPOINTS=$(grep -lE 'https?://[a-zA-Z0-9.-]+\.googleapis\.com' $CHANGED_FILES | grep -v '.mtls.googleapis.com' || true)
set -e

if [ -n "$FILES_WITH_HARDCODED_ENDPOINTS" ]; then
echo "❌ Found forbidden hardcoded non-mTLS endpoints."
echo ""
echo "🛠️ RESOLUTION (based on cl/905035339):"
echo "Do not hardcode 'googleapis.com' URLs. Instead, implement dynamic endpoint selection:"
echo ""
echo "1. Initialize an AuthorizedSession with your credentials."
echo "2. Use 'mtls.has_default_client_cert_source() from google-auth' to check for available client certificates."
echo "3. If certificates are present, use 'session.configure_mtls_channel()'."
echo "4. Dynamically select the '.mtls.' variant of the endpoint when mTLS is active."
echo ""
echo "The following files require updates:"
echo "$FILES_WITH_HARDCODED_ENDPOINTS"
exit 1
else
echo "✅ All endpoints are compliant or dynamically managed."
fi
else
echo "✅ No relevant Python files found."
fi
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ def stop_streaming(function_name: str):
"""
pass

# Temporary test for linter
API_ENDPOINT = "https://test.googleapis.com"

root_agent = Agent(
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This temporary test code should be removed before merging.

# Find supported models in Vertex here: https://docs.cloud.google.com/vertex-ai/generative-ai/docs/live-api
Expand Down
Loading