配置和使用 Developer Connect 代理

本页介绍了如何配置 Developer Connect 代理。

Developer Connect 代理可增强 Developer Connect 处理源代码管理系统 (SCM) 和任意 HTTP 端点(预览版)的身份验证和网络访问的方式。为连接启用代理后,Developer Connect 会使用代理服务器来代理 Git 请求(例如 git clone)或对 HTTP 端点(预览版)的 API 调用。使用Google Cloud 控制台创建连接时,代理默认处于启用状态。这样一来,您只需向用户或服务账号授予 IAM 权限,而无需在 Secret Manager 中管理访问令牌。

例如,在连接上启用 Developer Connect 代理后,您可以执行以下操作:

  • Gemini Code Assist 代码自定义功能与私有托管网络(包括本地网络)中的 SCM 搭配使用。
  • 使用 Google Cloud 身份验证和 Identity and Access Management 权限从外部 SCM 克隆源代码。
  • 在私有托管网络(包括本地网络)中使用 Gemini Code Review Agent 与 SCM 集成(预览版)。

Developer Connect 代理包含两个组件:

  • Git 代理

    对于与源代码管理系统 (SCM) 的连接

  • HTTP 代理(预览版

    对于与任意 HTTP 端点的连接

这两个组件均通过同一设置启用。Git 代理可让您更好地控制使用情况。

准备工作

确保您在 Developer Connect 中至少有一个与 SCM(例如 GitHub、GitLab 或 Bitbucket)的连接。

如需获得为连接配置 Developer Connect 代理所需的权限,请让管理员向您授予启用或停用 Developer Connect 代理的用户的 Developer Connect Admin (developerconnect.admin) IAM 角色。 如需详细了解如何授予角色,请参阅管理对项目、文件夹和组织的访问权限

您也可以通过自定义角色或其他预定义角色来获取所需的权限。

如需获得向连接代理发出请求所需的权限,请让管理员向发出 Git 请求的用户账号或服务账号授予以下 IAM 角色:

  • 发出 Git 读取请求,例如 git cloneGit Proxy Reader (roles/developerconnect.gitProxyReader)
  • 发出 Git 写入请求(例如 git push): Git Proxy User (roles/developerconnect.gitProxyUser)

查看和更新 Developer Connect 代理设置

Developer Connect 代理默认处于启用状态。启用后,Git 代理和 HTTP 代理都会启用。

如需查看和更新代理设置,请执行以下操作:

控制台

  1. 在 Google Cloud 控制台中,打开 Developer Connect

    前往 Developer Connect

  2. 点击连接标签页,然后点击要使用的连接的名称。

  3. 连接详情页面上,点击其他配置标签页。

  4. 点击 Developer Connect 代理切换开关,以停用或重新启用 Developer Connect 代理功能。

    Developer Connect 代理默认处于启用状态。

Google Cloud CLI

为连接启用 Developer Connect 代理设置

如需为连接启用 Developer Connect 代理,请运行 gcloud developer-connect connections update 命令来启用代理设置:

gcloud developer-connect connections update CONNECTION_NAME \
--location=REGION \
--git-proxy-config-enabled

为连接停用 Developer Connect 代理

如需为连接停用 Developer Connect 代理,请运行 gcloud developer-connect connections update 命令来停用代理设置:

gcloud developer-connect connections update CONNECTION_NAME \
--location=REGION \
--no-git-proxy-config-enabled

查看连接的代理设置

如需查看有关连接的 Developer Connect 代理设置的详细信息,请运行 gcloud developer-connect connections describe 命令:

gcloud developer-connect connections describe CONNECTION_NAME \
--location=REGION

替换以下内容:

  • CONNECTION_NAME 替换为连接的名称。
  • REGION 替换为连接的区域

本文档的其余部分仅包含 Git 代理的说明。

查找 Git 代理 URI

启用 Developer Connect 代理后,您可以按以下步骤查找连接的 Git 代理 URI:

控制台

  1. 在 Google Cloud 控制台中,打开 Developer Connect

    前往 Developer Connect

  2. 点击连接标签页,然后点击要使用的连接的名称。

  3. 连接详情页面中,点击代码库标签页。

  4. 找到相应连接的代码库,然后点击复制 Git 代理网址

Google Cloud CLI

如需获取 Git 代理 URI,请运行 gcloud developer-connect connections git-repository-links describe 命令:

gcloud developer-connect connections git-repository-links describe REPOSITORY_NAME \
--connection=CONNECTION_NAME \
--location=REGION

替换以下内容:

  • REPOSITORY_NAME 替换为代码库的名称。
  • CONNECTION_NAME 替换为连接的名称。
  • REGION 替换为连接的区域

Developer Connect API

Git 代理 URI 位于连接的 GitRepositoryLinkgit_proxy_url 字段中。

向 Git 代理发出问题请求

获得 Git 代理 URI 后,您可以通过执行以下操作向 Git 代理发出请求:

  1. 配置 Git CLI 以使用 Google Cloud CLI 凭据帮助程序:

    git config --global credential.'https://*.developerconnect.dev'.helper gcloud.sh

  2. 向 Git 代理发出请求(例如 git clone):

    git clone https://REGION.developerconnect.dev/PROJECT_NAME/CONNECTION_NAME/REPOSITORY NAME
    

    如果您不想使用凭据帮助程序,则可以将云访问令牌嵌入到请求中:

    git clone https://unused:$(gcloud auth print-access-token)@REGION-git.developerconnect.dev/PROJECT_NAME/CONNECTION_NAME/REPOSITORY NAME
    

    替换以下内容:

    • REPOSITORY_NAME 替换为代码库的名称。
    • CONNECTION_NAME 替换为连接的名称。
    • REGION 替换为连接的区域