适用于部署密钥的 REST API 终结点
使用 REST API 创建和管理部署密钥。
关于部署密钥
可以使用部署密钥(即授予对单个存储库的访问权限的 SSH 密钥)从你的 GitHub Enterprise Server 实例上的存储库启动项目到服务器。 GitHub 将密钥的公共部分直接附加到存储库而不是个人帐户,密钥的私有部分仍保留在服务器上。 有关详细信息,请参阅“执行部署”。
可以使用以下 API 终结点或使用 GitHub Web 界面设置部署密钥。 若要了解如何在 Web 界面中设置部署密钥,请参阅 管理部署密钥。
如果组织或企业所有者设置了限制密钥使用的策略,则你可能无法创建部署密钥。 此外,如果在组织或企业级别启用此策略,则现有部署密钥可能会被禁用。 有关详细信息,请参阅 在企业中实施仓库管理策略 和 限制在您的组织中使用部署密钥。
在某些情况下,其他活动将删除部署密钥:
- 如果使用 personal access token 创建了部署密钥,删除 personal access token 也会删除该部署密钥。 重新生成 personal access token 不会删除部署密钥。
- 如果通过 OAuth app 令牌创建部署密钥,则撤销该令牌也会删除部署密钥。
相反,以下活动不会删除部署密钥:
- 如果使用用户访问令牌创建 GitHub App 部署密钥,则撤销令牌不会删除部署密钥。
- 如果使用安装访问令牌创建 GitHub App 部署密钥,则卸载或删除应用不会删除部署密钥。
- 如果使用 a personal access token创建部署密钥,则 personal access token 重新生成部署密钥不会删除部署密钥。
List deploy keys
“List deploy keys”的细粒度访问令牌
此端点支持以下精细令牌类型:
细粒度令牌必须具有以下权限集:
- "Administration" repository permissions (read)
“”List deploy keys 的参数
| 名称, 类型, 说明 |
|---|
accept string Setting to |
| 名称, 类型, 说明 |
|---|
owner string 必须The account owner of the repository. The name is not case sensitive. |
repo string 必须The name of the repository without the |
| 名称, 类型, 说明 |
|---|
per_page integer The number of results per page (max 100). For more information, see "Using pagination in the REST API." 默认: |
page integer The page number of the results to fetch. For more information, see "Using pagination in the REST API." 默认: |
“List deploy keys”的 HTTP 响应状态代码
| 状态代码 | 说明 |
|---|---|
200 | OK |
“List deploy keys”的代码示例
请求示例
curl -L \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer <YOUR-TOKEN>" \
-H "X-GitHub-Api-Version: 2022-11-28" \
http(s)://HOSTNAME/api/v3/repos/OWNER/REPO/keysResponse
Status: 200[
{
"id": 1,
"key": "ssh-rsa AAA...",
"url": "https://HOSTNAME/repos/octocat/Hello-World/keys/1",
"title": "octocat@octomac",
"verified": true,
"created_at": "2014-12-10T15:53:42Z",
"read_only": true,
"added_by": "octocat",
"last_used": "2022-01-10T15:53:42Z",
"enabled": true
}
]Create a deploy key
You can create a read-only deploy key.
“Create a deploy key”的细粒度访问令牌
此端点支持以下精细令牌类型:
细粒度令牌必须具有以下权限集:
- "Administration" repository permissions (write)
“”Create a deploy key 的参数
| 名称, 类型, 说明 |
|---|
accept string Setting to |
| 名称, 类型, 说明 |
|---|
owner string 必须The account owner of the repository. The name is not case sensitive. |
repo string 必须The name of the repository without the |
| 名称, 类型, 说明 |
|---|
title string A name for the key. |
key string 必须The contents of the key. |
read_only boolean If Deploy keys with write access can perform the same actions as an organization member with admin access, or a collaborator on a personal repository. For more information, see "Repository permission levels for an organization" and "Permission levels for a user account repository." |
“Create a deploy key”的 HTTP 响应状态代码
| 状态代码 | 说明 |
|---|---|
201 | Created |
422 | Validation failed, or the endpoint has been spammed. |
“Create a deploy key”的代码示例
请求示例
curl -L \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer <YOUR-TOKEN>" \
-H "X-GitHub-Api-Version: 2022-11-28" \
http(s)://HOSTNAME/api/v3/repos/OWNER/REPO/keys \
-d '{"title":"octocat@octomac","key":"ssh-rsa AAA...","read_only":true}'Response
Status: 201{
"id": 1,
"key": "ssh-rsa AAA...",
"url": "https://HOSTNAME/repos/octocat/Hello-World/keys/1",
"title": "octocat@octomac",
"verified": true,
"created_at": "2014-12-10T15:53:42Z",
"read_only": true,
"added_by": "octocat",
"last_used": "2022-01-10T15:53:42Z",
"enabled": true
}Get a deploy key
“Get a deploy key”的细粒度访问令牌
此端点支持以下精细令牌类型:
细粒度令牌必须具有以下权限集:
- "Administration" repository permissions (read)
“”Get a deploy key 的参数
| 名称, 类型, 说明 |
|---|
accept string Setting to |
| 名称, 类型, 说明 |
|---|
owner string 必须The account owner of the repository. The name is not case sensitive. |
repo string 必须The name of the repository without the |
key_id integer 必须The unique identifier of the key. |
“Get a deploy key”的 HTTP 响应状态代码
| 状态代码 | 说明 |
|---|---|
200 | OK |
404 | Resource not found |
“Get a deploy key”的代码示例
请求示例
curl -L \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer <YOUR-TOKEN>" \
-H "X-GitHub-Api-Version: 2022-11-28" \
http(s)://HOSTNAME/api/v3/repos/OWNER/REPO/keys/KEY_IDResponse
Status: 200{
"id": 1,
"key": "ssh-rsa AAA...",
"url": "https://HOSTNAME/repos/octocat/Hello-World/keys/1",
"title": "octocat@octomac",
"verified": true,
"created_at": "2014-12-10T15:53:42Z",
"read_only": true,
"added_by": "octocat",
"last_used": "2022-01-10T15:53:42Z",
"enabled": true
}Delete a deploy key
Deploy keys are immutable. If you need to update a key, remove the key and create a new one instead.
“Delete a deploy key”的细粒度访问令牌
此端点支持以下精细令牌类型:
细粒度令牌必须具有以下权限集:
- "Administration" repository permissions (write)
“”Delete a deploy key 的参数
| 名称, 类型, 说明 |
|---|
accept string Setting to |
| 名称, 类型, 说明 |
|---|
owner string 必须The account owner of the repository. The name is not case sensitive. |
repo string 必须The name of the repository without the |
key_id integer 必须The unique identifier of the key. |
“Delete a deploy key”的 HTTP 响应状态代码
| 状态代码 | 说明 |
|---|---|
204 | No Content |
“Delete a deploy key”的代码示例
请求示例
curl -L \
-X DELETE \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer <YOUR-TOKEN>" \
-H "X-GitHub-Api-Version: 2022-11-28" \
http(s)://HOSTNAME/api/v3/repos/OWNER/REPO/keys/KEY_IDResponse
Status: 204