デプロイ キー
REST API を使って、デプロイ キーの作成と管理を行います。
デプロイ キーについて
GitHub.com のリポジトリからプロジェクトをサーバーに起動するには、デプロイ キーを使用します。これは、単一のリポジトリへのアクセスを許可する SSH キーです。 GitHub Enterprise Cloud は個人アカウントの代わりに、リポジトリに直接キーのパブリックな部分をアタッチし、キーのプライベートな部分はサーバーに残ります。 詳細については、「デプロイを配信する」を参照してください。
デプロイキーは、以下の API エンドポイントを使用するか、GitHub を使用することでセットアップできます。 GitHub でデプロイ キーを設定する方法を確認するには、「デプロイ キーの管理」を参照してください。
List deploy keys
パラメーター
ヘッダー |
---|
名前, Type, 説明 |
accept stringSetting to |
パス パラメーター |
名前, Type, 説明 |
owner string必須The account owner of the repository. The name is not case sensitive. |
repo string必須The name of the repository. The name is not case sensitive. |
クエリ パラメーター |
名前, Type, 説明 |
per_page integerThe number of results per page (max 100). Default: |
page integerPage number of the results to fetch. Default: |
HTTP 応答状態コード
状態コード | 説明 |
---|---|
200 | OK |
コード サンプル
curl \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer <YOUR-TOKEN>"\
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/OWNER/REPO/keys
Response
Status: 200
[
{
"id": 1,
"key": "ssh-rsa AAA...",
"url": "https://api.github.com/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"
}
]
Create a deploy key
You can create a read-only deploy key.
パラメーター
ヘッダー |
---|
名前, Type, 説明 |
accept stringSetting to |
パス パラメーター |
名前, Type, 説明 |
owner string必須The account owner of the repository. The name is not case sensitive. |
repo string必須The name of the repository. The name is not case sensitive. |
本文のパラメーター |
名前, Type, 説明 |
title stringA name for the key. |
key string必須The contents of the key. |
read_only booleanIf 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." |
HTTP 応答状態コード
状態コード | 説明 |
---|---|
201 | Created |
422 | Validation failed, or the endpoint has been spammed. |
コード サンプル
curl \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer <YOUR-TOKEN>"\
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/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://api.github.com/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"
}
Get a deploy key
パラメーター
ヘッダー |
---|
名前, Type, 説明 |
accept stringSetting to |
パス パラメーター |
名前, Type, 説明 |
owner string必須The account owner of the repository. The name is not case sensitive. |
repo string必須The name of the repository. The name is not case sensitive. |
key_id integer必須The unique identifier of the key. |
HTTP 応答状態コード
状態コード | 説明 |
---|---|
200 | OK |
404 | Resource not found |
コード サンプル
curl \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer <YOUR-TOKEN>"\
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/OWNER/REPO/keys/KEY_ID
Response
Status: 200
{
"id": 1,
"key": "ssh-rsa AAA...",
"url": "https://api.github.com/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"
}
Delete a deploy key
Deploy keys are immutable. If you need to update a key, remove the key and create a new one instead.
パラメーター
ヘッダー |
---|
名前, Type, 説明 |
accept stringSetting to |
パス パラメーター |
名前, Type, 説明 |
owner string必須The account owner of the repository. The name is not case sensitive. |
repo string必須The name of the repository. The name is not case sensitive. |
key_id integer必須The unique identifier of the key. |
HTTP 応答状態コード
状態コード | 説明 |
---|---|
204 | No Content |
コード サンプル
curl \
-X DELETE \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer <YOUR-TOKEN>"\
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/OWNER/REPO/keys/KEY_ID
Response
Status: 204