Skip to main content
The REST API is now versioned. For more information, see "About API versioning."

Codespaces 存储库机密

使用 REST API 管理用户有权在 codespace 中访问的存储库的机密。

谁可以使用此功能

Users with write access to a repository can manage Codespaces repository secrets.

关于 Codespaces 存储库机密

可以为用户有权访问的存储库创建、列出和删除机密(如云服务的访问令牌)。 这些机密在运行时可供 codespace 使用。 有关详细信息,请参阅“管理 codespace 的机密”。

List repository secrets

Works with GitHub Apps

Lists all secrets available in a repository without revealing their encrypted values. You must authenticate using an access token with the repo scope to use this endpoint. GitHub Apps must have write access to the codespaces_secrets repository permission to use this endpoint.

Parameters for "List repository secrets"

标头
名称, 类型, 说明
accept string

Setting to application/vnd.github+json is recommended.

路径参数
名称, 类型, 说明
owner string 必须

The account owner of the repository. The name is not case sensitive.

repo string 必须

The name of the repository without the .git extension. The name is not case sensitive.

查询参数
名称, 类型, 说明
per_page integer

The number of results per page (max 100).

默认: 30

page integer

Page number of the results to fetch.

默认: 1

HTTP response status codes for "List repository secrets"

Status codeDescription
200

OK

Code samples for "List repository secrets"

get/repos/{owner}/{repo}/codespaces/secrets
curl -L \ -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/codespaces/secrets

Response

Status: 200
{ "total_count": 2, "secrets": [ { "name": "GH_TOKEN", "created_at": "2019-08-10T14:59:22Z", "updated_at": "2020-01-10T14:59:22Z", "visibility": "all" }, { "name": "GIST_ID", "created_at": "2020-01-10T10:59:22Z", "updated_at": "2020-01-11T11:59:22Z", "visibility": "all" } ] }

Get a repository public key

Gets your public key, which you need to encrypt secrets. You need to encrypt a secret before you can create or update secrets. Anyone with read access to the repository can use this endpoint. If the repository is private you must use an access token with the repo scope. GitHub Apps must have write access to the codespaces_secrets repository permission to use this endpoint.

Parameters for "Get a repository public key"

标头
名称, 类型, 说明
accept string

Setting to application/vnd.github+json is recommended.

路径参数
名称, 类型, 说明
owner string 必须

The account owner of the repository. The name is not case sensitive.

repo string 必须

The name of the repository without the .git extension. The name is not case sensitive.

HTTP response status codes for "Get a repository public key"

Status codeDescription
200

OK

Code samples for "Get a repository public key"

get/repos/{owner}/{repo}/codespaces/secrets/public-key
curl -L \ -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/codespaces/secrets/public-key

Response

Status: 200
{ "key_id": "012345678912345678", "key": "2Sg8iYjAxxmI2LvUXpJjkYrMxURPc8r+dB7TJyvv1234" }

Get a repository secret

Works with GitHub Apps

Gets a single repository secret without revealing its encrypted value. You must authenticate using an access token with the repo scope to use this endpoint. GitHub Apps must have write access to the codespaces_secrets repository permission to use this endpoint.

Parameters for "Get a repository secret"

标头
名称, 类型, 说明
accept string

Setting to application/vnd.github+json is recommended.

路径参数
名称, 类型, 说明
owner string 必须

The account owner of the repository. The name is not case sensitive.

repo string 必须

The name of the repository without the .git extension. The name is not case sensitive.

secret_name string 必须

The name of the secret.

HTTP response status codes for "Get a repository secret"

Status codeDescription
200

OK

Code samples for "Get a repository secret"

get/repos/{owner}/{repo}/codespaces/secrets/{secret_name}
curl -L \ -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/codespaces/secrets/SECRET_NAME

Response

Status: 200
{ "name": "GH_TOKEN", "created_at": "2019-08-10T14:59:22Z", "updated_at": "2020-01-10T14:59:22Z", "visibility": "all" }

Create or update a repository secret

Works with GitHub Apps

Creates or updates a repository secret with an encrypted value. Encrypt your secret using LibSodium. For more information, see "Encrypting secrets for the REST API."

You must authenticate using an access token with the repo scope to use this endpoint. GitHub Apps must have write access to the codespaces_secrets repository permission to use this endpoint.

Parameters for "Create or update a repository secret"

标头
名称, 类型, 说明
accept string

Setting to application/vnd.github+json is recommended.

路径参数
名称, 类型, 说明
owner string 必须

The account owner of the repository. The name is not case sensitive.

repo string 必须

The name of the repository without the .git extension. The name is not case sensitive.

secret_name string 必须

The name of the secret.

正文参数
名称, 类型, 说明
encrypted_value string

Value for your secret, encrypted with LibSodium using the public key retrieved from the Get a repository public key endpoint.

key_id string

ID of the key you used to encrypt the secret.

HTTP response status codes for "Create or update a repository secret"

Status codeDescription
201

Response when creating a secret

204

Response when updating a secret

Code samples for "Create or update a repository secret"

put/repos/{owner}/{repo}/codespaces/secrets/{secret_name}
curl -L \ -X PUT \ -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/codespaces/secrets/SECRET_NAME \ -d '{"encrypted_value":"c2VjcmV0","key_id":"012345678912345678"}'

Response when creating a secret

Delete a repository secret

Works with GitHub Apps

Deletes a secret in a repository using the secret name. You must authenticate using an access token with the repo scope to use this endpoint. GitHub Apps must have write access to the codespaces_secrets repository permission to use this endpoint.

Parameters for "Delete a repository secret"

标头
名称, 类型, 说明
accept string

Setting to application/vnd.github+json is recommended.

路径参数
名称, 类型, 说明
owner string 必须

The account owner of the repository. The name is not case sensitive.

repo string 必须

The name of the repository without the .git extension. The name is not case sensitive.

secret_name string 必须

The name of the secret.

HTTP response status codes for "Delete a repository secret"

Status codeDescription
204

No Content

Code samples for "Delete a repository secret"

delete/repos/{owner}/{repo}/codespaces/secrets/{secret_name}
curl -L \ -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/codespaces/secrets/SECRET_NAME

Response

Status: 204