Help us learn about your current experience with the documentation. Take the survey.

许可证 API

  • 版本:Free, Premium, Ultimate
  • 产品:GitLab 私有化部署, GitLab 专属版

使用此 API 与许可证端点进行交互。更多信息,请参阅使用许可证文件或密钥激活 GitLab EE

前提条件:

  • 您必须拥有该实例的管理员访问权限。

获取当前许可证信息

GET /license
{
  "id": 2,
  "plan": "ultimate",
  "created_at": "2018-02-27T23:21:58.674Z",
  "starts_at": "2018-01-27",
  "expires_at": "2022-01-27",
  "historical_max": 300,
  "maximum_user_count": 300,
  "expired": false,
  "overage": 200,
  "user_limit": 100,
  "active_users": 300,
  "licensee": {
    "Name": "John Doe1",
    "Email": "[email protected]",
    "Company": "GitLab"
  },
  "add_ons": {
    "GitLab_FileLocks": 1,
    "GitLab_Auditor_User": 1
  }
}

获取所有许可证信息

GET /licenses
[
  {
    "id": 1,
    "plan": "premium",
    "created_at": "2018-02-27T23:21:58.674Z",
    "starts_at": "2018-01-27",
    "expires_at": "2022-01-27",
    "historical_max": 300,
    "maximum_user_count": 300,
    "expired": false,
    "overage": 200,
    "user_limit": 100,
    "licensee": {
      "Name": "John Doe1",
      "Email": "[email protected]",
      "Company": "GitLab"
    },
    "add_ons": {
      "GitLab_FileLocks": 1,
      "GitLab_Auditor_User": 1
    }
  },
  {
    "id": 2,
    "plan": "ultimate",
    "created_at": "2018-02-27T23:21:58.674Z",
    "starts_at": "2018-01-27",
    "expires_at": "2022-01-27",
    "historical_max": 300,
    "maximum_user_count": 300,
    "expired": false,
    "overage": 200,
    "user_limit": 100,
    "licensee": {
      "Name": "Doe John",
      "Email": "[email protected]",
      "Company": "GitLab"
    },
    "add_ons": {
      "GitLab_FileLocks": 1
    }
  }
]

超额用户数(Overage)是指可计费用户数与许可证授权用户数之间的差额。 其计算方式取决于许可证是否已过期。

  • 如果许可证已过期,则使用历史最高可计费用户数(historical_max)。
  • 如果许可证未过期,则使用当前可计费用户数。

返回:

  • 200 OK:响应包含 JSON 格式的许可证信息。如果没有许可证,则返回一个空的 JSON 数组。
  • 403 Forbidden:如果当前用户无权读取许可证。

获取单个许可证信息

GET /license/:id

支持的属性:

属性 类型 必需 描述
id integer GitLab 许可证的 ID。

返回以下状态码:

  • 200 OK:响应包含 JSON 格式的许可证信息。
  • 404 Not Found:请求的许可证不存在。
  • 403 Forbidden:当前用户无权读取许可证。

示例请求:

curl --header "PRIVATE-TOKEN: <your_access_token>" \
--url "https://gitlab.example.com/api/v4/license/:id"

示例响应:

{
  "id": 1,
  "plan": "premium",
  "created_at": "2018-02-27T23:21:58.674Z",
  "starts_at": "2018-01-27",
  "expires_at": "2022-01-27",
  "historical_max": 300,
  "maximum_user_count": 300,
  "expired": false,
  "overage": 200,
  "user_limit": 100,
  "active_users": 50,
  "licensee": {
    "Name": "John Doe1",
    "Email": "[email protected]",
    "Company": "GitLab"
  },
  "add_ons": {
    "GitLab_FileLocks": 1,
    "GitLab_Auditor_User": 1
  }
}

添加新许可证

POST /license
属性 类型 必需 描述
license string 许可证字符串
curl --request POST \
--header "PRIVATE-TOKEN: <your_access_token>" \
--url "https://gitlab.example.com/api/v4/license?license=eyJkYXRhIjoiMHM5Q...S01Udz09XG4ifQ=="

示例响应:

{
  "id": 1,
  "plan": "ultimate",
  "created_at": "2018-02-27T23:21:58.674Z",
  "starts_at": "2018-01-27",
  "expires_at": "2022-01-27",
  "historical_max": 300,
  "maximum_user_count": 300,
  "expired": false,
  "overage": 200,
  "user_limit": 100,
  "active_users": 300,
  "licensee": {
    "Name": "John Doe1",
    "Email": "[email protected]",
    "Company": "GitLab"
  },
  "add_ons": {
    "GitLab_FileLocks": 1,
    "GitLab_Auditor_User": 1
  }
}

返回:

  • 201 Created:如果许可证成功添加。
  • 400 Bad Request:如果无法添加许可证,并附带解释原因的错误消息。

删除许可证

DELETE /license/:id
属性 类型 必需 描述
id integer GitLab 许可证的 ID。
curl --request DELETE \
--header "PRIVATE-TOKEN: <your_access_token>" \
--url "https://gitlab.example.com/api/v4/license/:id"

返回:

  • 204 No Content:如果许可证成功删除。
  • 403 Forbidden:如果当前用户无权删除许可证。
  • 404 Not Found:如果找不到要删除的许可证。

触发可计费用户重新计算

PUT /license/:id/refresh_billable_users
属性 类型 必需 描述
id integer GitLab 许可证的 ID。
curl --request PUT \
--header "PRIVATE-TOKEN: <your_access_token>" \
--url "https://gitlab.example.com/api/v4/license/:id/refresh_billable_users"

示例响应:

{
  "success": true
}

返回:

  • 202 Accepted:如果刷新可计费用户的请求已成功启动。
  • 403 Forbidden:如果当前用户无权为该许可证刷新可计费用户。
  • 404 Not Found:如果找不到该许可证。
属性 类型 描述
success boolean 请求是否成功。

获取当前许可证的使用信息

获取当前许可证的使用信息,并以 CSV 格式导出。

GET /license/usage_export.csv
curl --request GET \
--header "PRIVATE-TOKEN: <your_access_token>" \
--url "https://gitlab.example.com/api/v4/license/usage_export.csv"

示例响应:

License Key,"eyJkYXRhIjoib1EwRWZXU3RobDY2Yl=
"
Email,[email protected]
License Start Date,2023-02-22
License End Date,2024-02-22
Company,Example Corp.
Generated At,2023-09-05 06:56:23
"",""
Date,Billable User Count
2023-07-11 12:00:05,21
2023-07-13 12:00:06,21
2023-08-16 12:00:02,21
2023-09-04 12:00:12,21

返回:

  • 200 OK:响应包含 CSV 格式的许可证使用信息。
  • 403 Forbidden:如果当前用户无权查看许可证使用情况。