Skip to content

Commit d9d7389

Browse files
feat: Update check-file-contents.yml to check for non-mTLS hardcoded endpoints
feat: Update check-file-contents.yml to check for non-mTLS hardcoded endpoints
1 parent 55cbc8c commit d9d7389

1 file changed

Lines changed: 32 additions & 0 deletions

File tree

.github/workflows/check-file-contents.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,3 +100,35 @@ jobs:
100100
else
101101
echo "✅ No relevant Python files found."
102102
fi
103+
104+
- name: Check for hardcoded googleapis.com endpoints
105+
run: |
106+
git fetch origin ${GITHUB_BASE_REF}
107+
CHANGED_FILES=$(git diff --diff-filter=ACMR --name-only origin/${GITHUB_BASE_REF}...HEAD | grep -E '\.py$' || true)
108+
if [ -n "$CHANGED_FILES" ]; then
109+
echo "Checking for hardcoded endpoints in: $CHANGED_FILES"
110+
111+
set +e
112+
FILES_WITH_HARDCODED_ENDPOINTS=$(grep -lE 'https?://[a-zA-Z0-9.-]+\.googleapis\.com' $CHANGED_FILES | grep -v '.mtls.googleapis.com' || true)
113+
set -e
114+
115+
if [ -n "$FILES_WITH_HARDCODED_ENDPOINTS" ]; then
116+
echo "❌ Found forbidden hardcoded non-mTLS endpoints."
117+
echo ""
118+
echo "🛠️ RESOLUTION (based on cl/905035339):"
119+
echo "Do not hardcode 'googleapis.com' URLs. Instead, implement dynamic endpoint selection:"
120+
echo ""
121+
echo "1. Initialize an AuthorizedSession with your credentials."
122+
echo "2. Use 'mtls.has_default_client_cert_source() from google-auth' to check for available client certificates."
123+
echo "3. If certificates are present, use 'session.configure_mtls_channel()'."
124+
echo "4. Dynamically select the '.mtls.' variant of the endpoint when mTLS is active."
125+
echo ""
126+
echo "The following files require updates:"
127+
echo "$FILES_WITH_HARDCODED_ENDPOINTS"
128+
exit 1
129+
else
130+
echo "✅ All endpoints are compliant or dynamically managed."
131+
fi
132+
else
133+
echo "✅ No relevant Python files found."
134+
fi

0 commit comments

Comments
 (0)